`
wu_quanyin
  • 浏览: 204409 次
  • 性别: Icon_minigender_1
  • 来自: 福建省
社区版块
存档分类
最新评论

Tomcat源码---容器启动六(2)

阅读更多

  super.start()--->org.apache.catalina.core.ContainerBase#start()

 

/**
     * Prepare for active use of the public methods of this Component.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents it from being started
     */
    public synchronized void start() throws LifecycleException {

        // Validate and update our current component state
        if (started) {
            if(log.isInfoEnabled())
                log.info(sm.getString("containerBase.alreadyStarted", logName()));
            return;
        }
        
        // Notify our interested LifecycleListeners
        lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);

        started = true;
	
   	//这些为server.xml中配置应用组件的启动,如果要了解的话
	//可根据自己的配置进行查看
        // Start our subordinate components, if any
        if ((loader != null) && (loader instanceof Lifecycle))
            ((Lifecycle) loader).start();
        logger = null;
        getLogger();
        if ((logger != null) && (logger instanceof Lifecycle))
            ((Lifecycle) logger).start();
        if ((manager != null) && (manager instanceof Lifecycle))
            ((Lifecycle) manager).start();
        if ((cluster != null) && (cluster instanceof Lifecycle))
            ((Lifecycle) cluster).start();
        if ((realm != null) && (realm instanceof Lifecycle))
            ((Lifecycle) realm).start();
        if ((resources != null) && (resources instanceof Lifecycle))
            ((Lifecycle) resources).start();

        // Start our child containers, if any
 	//StandardHost容器的启动,
        Container children[] = findChildren();
        for (int i = 0; i < children.length; i++) {
            if (children[i] instanceof Lifecycle)
                ((Lifecycle) children[i]).start();
        }

        // Start the Valves in our pipeline (including the basic), if any
 	//StandardPipeline的启动(容器与容器间的管道)
        if (pipeline instanceof Lifecycle)
            ((Lifecycle) pipeline).start();

        // Notify our interested LifecycleListeners(里面将会对HostConfig进行启动,并且部暑webapps)
        lifecycle.fireLifecycleEvent(START_EVENT, null);

        // Start our thread
        threadStart();

        // Notify our interested LifecycleListeners
        lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);

    }

  StandardHost#start

  /**

     * Start this host.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents it from being started
     */
    public synchronized void start() throws LifecycleException {
        if( started ) {
            return;
        }
        if( ! initialized )
            init();

        // Look for a realm - that may have been configured earlier. 
        // If the realm is added after context - it'll set itself.
        if( realm == null ) {
            ObjectName realmName=null;
            try {
                realmName=new ObjectName( domain + ":type=Realm,host=" + getName());
                if( mserver.isRegistered(realmName ) ) {
                    mserver.invoke(realmName, "init", 
                            new Object[] {},
                            new String[] {}
                    );            
                }
            } catch( Throwable t ) {
                log.debug("No realm for this host " + realmName);
            }
        }
            
        // Set error report valve
        if ((errorReportValveClass != null)
            && (!errorReportValveClass.equals(""))) {
            try {
                boolean found = false;
                if(errorReportValveObjectName != null) {
                    ObjectName[] names = 
                        ((StandardPipeline)pipeline).getValveObjectNames();
                    for (int i=0; !found && i<names.length; i++)
                        if(errorReportValveObjectName.equals(names[i]))
                            found = true ;
                    }
                    if(!found) { 
			//添加阀门,在接收消息时,进行过滤消息         	
                        Valve valve = (Valve) Class.forName(errorReportValveClass)
                        .newInstance();
                        addValve(valve);
                        errorReportValveObjectName = ((ValveBase)valve).getObjectName() ;
                    }
            } catch (Throwable t) {
                log.error(sm.getString
                    ("standardHost.invalidErrorReportValveClass", 
                     errorReportValveClass), t);
            }
        }
        if(log.isDebugEnabled()) {
            if (xmlValidation)
                log.debug(sm.getString("standardHost.validationEnabled"));
            else
                log.debug(sm.getString("standardHost.validationDisabled"));
        }
 	//返回到以上的containerBase#start执行pipeline
	//pipeline是容器与容器间的桥梁(管道),在每一个容器中执行这一步,都为自己的容器添加相应的valve
        super.start();

    }

 StandardPipeline#start

 

 /**
     * Prepare for active use of the public methods of this Component.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents it from being started
     */
    public synchronized void start() throws LifecycleException {

        // Validate and update our current component state
        if (started)
            throw new LifecycleException
                (sm.getString("standardPipeline.alreadyStarted"));

        // Notify our interested LifecycleListeners
        lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);

        started = true;

        // Start the Valves in our pipeline (including the basic), if any
        Valve current = first;
        if (current == null) {
        	current = basic;
        }
        while (current != null) {
            //ErrorReportValve StandardHostValve两个阀门
            if (current instanceof Lifecycle)
                ((Lifecycle) current).start();
	    //注册阀门,
            registerValve(current);
        	current = current.getNext();
        }

        // Notify our interested LifecycleListeners
        lifecycle.fireLifecycleEvent(START_EVENT, null);

        // Notify our interested LifecycleListeners
        lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);

    }

   HostConfig#lifecycleEvent方法下的start方法

 

  /**
     * Process a "start" event for this Host.
     */
    public void start() {

        if (log.isDebugEnabled())
            log.debug(sm.getString("hostConfig.start"));

        try {
            ObjectName hostON = new ObjectName(host.getObjectName());
            oname = new ObjectName
                (hostON.getDomain() + ":type=Deployer,host=" + host.getName());
            Registry.getRegistry(null, null).registerComponent
                (this, oname, this.getClass().getName());
        } catch (Exception e) {
            log.error(sm.getString("hostConfig.jmx.register", oname), e);
        }
        //StandardHost判断
        if (host.getDeployOnStartup())
            //部暑webapps
            deployApps();
        
    }

 HostConfig#deployApps

 

 /**
     * Deploy applications for any directories or WAR files that are found
     * in our "application root" directory.
     */
    protected void deployApps() {
	//webapps,以下方法见名知义
        File appBase = appBase();
        File configBase = configBase();
        // Deploy XML descriptors from configBase
        deployDescriptors(configBase, configBase.list());
        // Deploy WARs, and loop if additional descriptors are found
        deployWARs(appBase, appBase.list());
        // Deploy expanded folders
        deployDirectories(appBase, appBase.list());
        
    }
0
1
分享到:
评论

相关推荐

    tomcat 源码分析系列文档

    tomcat 源码分析系列文档 http深入分析,tomcat中类的加载,tomcat的启动,tomcat的容器思想,

    apache-tomcat-8.5.50-src.zip

    Tomcat启动流程分析 组件的生命周期管理 用Lifecycle管理启动、停止、关闭 Lifecycle接口预览 几个核心方法 Server中的init方法示例 为啥StandardServer没有init方法 LifecycleBase中的init与...

    3-8Tomcat请求容器中的处理与启动过程源码实现(1).mp4

    3-8Tomcat请求容器中的处理与启动过程源码实现(1).mp4

    Tomcat源码研究.pdf

    Tomcat源码研究.pdf。Catalina脚本解析,Tomcat启动遇到的常见问题,架构探讨,JMX在tomcat中的应用,容器初探,生命周期

    3-8Tomcat请求容器中的处理与启动过程源码实现(2).mp4

    3-8Tomcat请求容器中的处理与启动过程源码实现(2).mp4

    基于内嵌apache-tomcat-8.0.24的应用开发

    开发人员无需搭建Tomcat的环境就可以使用内嵌式Tomcat进行开发,减少搭建J2EE容器环境的时间和开发时容器频繁启动所花时间,提高开发的效率. 基于内嵌apache-tomcat-8.0.24的应用开发解决了网上提供省了el-ri相关...

    tomcat源码分析图谱

    tomcat的基础脚本分析 tomcat的源码启动分析 tomcat的web应用启动分析 tomcat的socket分析 tomcat的cocket与容器对接时序分析

    java8源码-docker-tomcat8:在jre-8上运行Tomcat服务器8的简单docker镜像

    容器启动后会自动创建一个具有所有权限的admin用户,并自动生成随机密码。你可以通过查看容器log获得密码,比如 =&gt; Creating and admin user with a random password in Tomcat =&gt; Done! ==========================...

    tomcat-sr:Tomcat启动脚本,配置文件,源码剖析

    TomcatTomcat启动脚本,配置文件,源码剖析============ Tomcat 7.0.56 RUNNING.txt-安装并运行Tomcat 7.0 Servlet / JSP容器(2014.10.28-) serverStartup.txt-Tomcat 5启动顺序,serverStartup.pdf-启动过程的UML...

    Tomcat源码分析

    总体架构:1、面向组件架构2、基于JMX3、事件侦听tomcat代码看似很庞大,但从结构上看却很清晰和简单,它主要由一堆组件组成,如Server、Service、...2、Server:是整个Tomcat组件的容器,包含一个或多个Service。3、

    Idea中tomcat启动源码调试进入到tomcat内部进行调试的方法

    使用idea开发工具调试代码的时候,如果是java的web项目,使用的是tomcat作为web容器,打断点debug调试跟踪,当跟踪到org.apache.catalina包下的时候,则无法进入,这是因为idea运行的tomcat是通过插件的方式集成的,...

    java版ss源码-couchdb-lucene:使用Lucene启用CouchDB文档的全文搜索

    java版s源码couchdb-lucene 版本兼容性 CouchDB-Lucene 适用于 0.10 以上的所有版本的 CouchDB。 问题跟踪 问题跟踪在 . 最低系统要求 需要 Java 1.8; 推荐使用 Oracle Java 8 或 OpenJDK 8。 构建并运行 couchdb-...

    java开发斗地主源码-LandManager:房东的小型网站以简化会计(2013)

    java开发斗地主源码#About LandManager 是一个让房东轻松记账的小网站(2013 年)。 客户允许共享源代码(无保密协议)。 从项目中删除了有关客户和环境(数据库帐户)的所有数据。 #技术: maven、spring、spring-...

    单点登录源码

    Spring Framework | 容器 | [http://projects.spring.io/spring-framework/](http://projects.spring.io/spring-framework/) SpringMVC | MVC框架 | ...

    Java ssm校园在线点餐系统源码(含数据库).zip

    4.将项目放入tomcat容器中,并启动项目 5.浏览器访问地址 前台访问路径:http://localhost:8081/fore/foreIndex 登录账号:byh 登录密码:12345 后台访问地址:http://localhost:8081/login 登录账号:小白 登录密码...

    JAVA上百实例源码以及开源项目源代码

    Java 源码包 Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这款实例会对你有所帮助。 Calendar万年历 1个目标文件 EJB 模拟银行ATM流程及操作源代码 6个目标文件,EJB来...

    JAVA上百实例源码以及开源项目

     在对象创建的过程中将被容器调用,onMessage函数方法接收消息参数,将其强制转型为合适的消息类型,同时打印出消息的内容。同时一个mail note将被发送给消息发送者,发送一个e-mail通知给由recipient参数确定的e-...

    深入浅出Hibernate源码

    它会自动进行数据库初始化、编译、启动tomcat容器.(此命令将会启动tomcat,因此之前tomcat必须处于停止状态) 然后,打开您的浏览器,输入http://localhost:8080/forum 您应该看到我们的示例正常运行. 9, 在您的...

    Java的过滤器与拦截器的区别.docx

    createWebServer()这个方法的源码我就不贴上了,大家可以自己看一下源码,最后就会看到new tomcat();并进行启动tomcat。启动容器后当然是开始进行初始化。 1 private void selfInitialize(ServletContext ...

Global site tag (gtag.js) - Google Analytics