起首,挪用init()要领逐级初始化,接着挪用start()要领举办启动,同时,每次挪用陪伴着生命周期状态改观变乱的触发。
- org.apache.catalina.startup.Bootstrap的措施进口main要领,详细实现如下:
- public static void main(String args[]) {
-
- if (daemon == null) {
- // Don't set daemon until init() has completed
- Bootstrap bootstrap = new Bootstrap();
- try {
- bootstrap.init();
- } catch (Throwable t) {
- handleThrowable(t);
- t.printStackTrace();
- return;
- }
- daemon = bootstrap;
- } else {
- // When running as a service the call to stop will be on a new
- // thread so make sure the correct class loader is used to prevent
- // a range of class not found exceptions.
- Thread.currentThread().setContextClassLoader(daemon.catalinaLoader);
- }
-
- try {
- String command = "start";
- if (args.length > 0) {
- command = args[args.length - 1];
- }
-
- if (command.equals("startd")) {
- args[args.length - 1] = "start";
- daemon.load(args);
- daemon.start();
- } else if (command.equals("stopd")) {
- args[args.length - 1] = "stop";
- daemon.stop();
- } else if (command.equals("start")) {
- daemon.setAwait(true);
- daemon.load(args);
- daemon.start();
- } else if (command.equals("stop")) {
- daemon.stopServer(args);
- } else if (command.equals("configtest")) {
- daemon.load(args);
- if (null==daemon.getServer()) {
- System.exit(1);
- }
- System.exit(0);
- } else {
- log.warn("Bootstrap: command "" + command + "" does not exist.");
- }
- } catch (Throwable t) {
- // Unwrap the Exception for clearer error reporting
- if (t instanceof InvocationTargetException &&
- t.getCause() != null) {
- t = t.getCause();
- }
- handleThrowable(t);
- t.printStackTrace();
- System.exit(1);
- }
-
- }
- org.apache.catalina.startup.Bootstrap的初始化要领,详细实现如下:
- public void init() throws Exception {
- // 1、配置catalina.home的设置:将catalina.home体系属性配置为当前事变目次(假如尚未配置)。
- setCatalinaHome();
- // 2、配置catalina.base的设置:假如没有配置的话,将当前的事变目次为了catalina.base的配置
- setCatalinaBase();
- // 3、初始化类加载器:commonLoader、catalinaLoader、sharedLoader
- initClassLoaders();
-
- Thread.currentThread().setContextClassLoader(catalinaLoader);
-
- SecurityClassLoad.securityClassLoad(catalinaLoader);
-
- // 加载我们的启动类并挪用其process()要领
- if (log.isDebugEnabled())
- log.debug("Loading startup class");
- //4、加载启动类
- Class<?> startupClass = catalinaLoader.loadClass("org.apache.catalina.startup.Catalina");
- //5、实例化启动类
- Object startupInstance = startupClass.newInstance();
-
- if (log.isDebugEnabled())
- log.debug("Setting startup class properties");
-
- //6、配置要领参数
- String methodName = "setParentClassLoader";
- Class<?> paramTypes[] = new Class[1];
- paramTypes[0] = Class.forName("java.lang.ClassLoader");
- Object paramValues[] = new Object[1];
- paramValues[0] = sharedLoader;
- Method method = startupInstance.getClass().getMethod(methodName, paramTypes);
- // 7、挪用启动类的setParentClassLoader要领配置共享扩展类加载器
- method.invoke(startupInstance, paramValues);
-
- catalinaDaemon = startupInstance;
-
- }
- org.apache.catalina.startup.Bootstrap的start()要领,详细实现如下:
- /**
- * Start the Catalina daemon.
- */
- public void start() throws Exception {
- // 假如启动类为实例化,则挪用init()要领
- if( catalinaDaemon==null ) init();
-
- //获取启动类的start要领
- Method method = catalinaDaemon.getClass().getMethod("start", (Class [] )null);
- //挪用启动类的start要领,即挪用org.apache.catalina.startup.Catalina的start()要领
- method.invoke(catalinaDaemon, (Object [])null);
-
- }
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|