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

Tomcat源码---载入相应的资源及解析四(2)

阅读更多

一,根据以上文章所讲的对server.xml的解析作下简单的分析

org.apache.catalina.startup.Catalina#load

Digester是用sax来解析server.xml的类,这一步是初始化

 

  1. //创建该对象,主要是对conf/server.xml进行解析  
  2.        Digester digester = createStartDigester(); 

 

tomcat文档的解析如下:

--------------------------------------------------------------------------------------------

 

b3) createStartDigester() 

Configures a digester for the main server.xml elements like

org.apache.catalina.core.StandardServer (can change of course :)

org.apache.catalina.deploy.NamingResources

Stores naming resources in the J2EE JNDI tree

org.apache.catalina.LifecycleListener

implements events for start/stop of major components

org.apache.catalina.core.StandardService

The single entry for a set of connectors,

so that a container can listen to multiple connectors

ie, single entry

org.apache.coyote.tomcat5.CoyoteConnector

Connectors to listen for incoming requests only

It also adds the following rulesets to the digester

NamingRuleSet

EngineRuleSet

HostRuleSet

ContextRuleSet

b4) Load the server.xml and parse it using the digester

   Parsing the server.xml using the digester is an automatic

   XML-object mapping tool, that will create the objects defined in server.xml

   Startup of the actual container has not started yet.

b5) Assigns System.out and System.err to the SystemLogHandler class

b6) Calls intialize on all components, this makes each object register itself with the 

   JMX agent.

   During the process call the Connectors also initialize the adapters.

   The adapters are the components that do the request pre-processing.

   Typical adapters are HTTP1.1 (default if no protocol is specified,

   org.apache.coyote.http11.Http11Protocol)

   AJP1.3 for mod_jk etc.


 

--------------------------------------------------------------------------------------------

org.apache.catalina.startup.Catalina#createStartDigester

 

//Create and configure the Digester we will be using for startup. 
    protected Digester createStartDigester() {
        long t1=System.currentTimeMillis();
        // Initialize the digester
        Digester digester = new Digester();
        digester.setValidating(false);
        digester.setRulesValidation(true);
        HashMap<Class, List<String>> fakeAttributes = new HashMap<Class, List<String>>();
        ArrayList<String> attrs = new ArrayList<String>();
        attrs.add("className");
        fakeAttributes.put(Object.class, attrs);
        digester.setFakeAttributes(fakeAttributes);
        digester.setClassLoader(StandardServer.class.getClassLoader());

        // Configure the actions we will be using
	//1,server标签.2,默认初始化的类,若在xml上有自定义,覆盖此类,3,属性名
        digester.addObjectCreate("Server",
                                 "org.apache.catalina.core.StandardServer",
                                 "className");
        // 设定一个SetPropertiesRule,这个规则是用于堆栈顶端元素的属性设置  
        digester.addSetProperties("Server");
       //设置下一个server的标签,总是先外再到内,,按这三种模式可推出以下的设置
        digester.addSetNext("Server",
                            "setServer",
                            "org.apache.catalina.Server");

        digester.addObjectCreate("Server/GlobalNamingResources",
                                 "org.apache.catalina.deploy.NamingResources");
        digester.addSetProperties("Server/GlobalNamingResources");
        digester.addSetNext("Server/GlobalNamingResources",
                            "setGlobalNamingResources",
                            "org.apache.catalina.deploy.NamingResources");

        digester.addObjectCreate("Server/Listener",
                                 null, // MUST be specified in the element
                                 "className");
        digester.addSetProperties("Server/Listener");
        digester.addSetNext("Server/Listener",
                            "addLifecycleListener",
                            "org.apache.catalina.LifecycleListener");

        digester.addObjectCreate("Server/Service",
                                 "org.apache.catalina.core.StandardService",
                                 "className");
        digester.addSetProperties("Server/Service");
        digester.addSetNext("Server/Service",
                            "addService",
                            "org.apache.catalina.Service");

        digester.addObjectCreate("Server/Service/Listener",
                                 null, // MUST be specified in the element
                                 "className");
        digester.addSetProperties("Server/Service/Listener");
        digester.addSetNext("Server/Service/Listener",
                            "addLifecycleListener",
                            "org.apache.catalina.LifecycleListener");

        //Executor
        digester.addObjectCreate("Server/Service/Executor",
                         "org.apache.catalina.core.StandardThreadExecutor",
                         "className");
        digester.addSetProperties("Server/Service/Executor");

        digester.addSetNext("Server/Service/Executor",
                            "addExecutor",
                            "org.apache.catalina.Executor");

        
        digester.addRule("Server/Service/Connector",
                         new ConnectorCreateRule());
        digester.addRule("Server/Service/Connector", 
                         new SetAllPropertiesRule(new String[]{"executor"}));
        digester.addSetNext("Server/Service/Connector",
                            "addConnector",
                            "org.apache.catalina.connector.Connector");
        
        


        digester.addObjectCreate("Server/Service/Connector/Listener",
                                 null, // MUST be specified in the element
                                 "className");
        digester.addSetProperties("Server/Service/Connector/Listener");
        digester.addSetNext("Server/Service/Connector/Listener",
                            "addLifecycleListener",
                            "org.apache.catalina.LifecycleListener");

        // Add RuleSets for nested elements
        digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/"));
        digester.addRuleSet(new EngineRuleSet("Server/Service/"));
        digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));
        digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/"));
        digester.addRuleSet(ClusterRuleSetFactory.getClusterRuleSet("Server/Service/Engine/Host/Cluster/"));
        digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/"));

        // When the 'engine' is found, set the parentClassLoader.
        digester.addRule("Server/Service/Engine",
                         new SetParentClassLoaderRule(parentClassLoader));
        digester.addRuleSet(ClusterRuleSetFactory.getClusterRuleSet("Server/Service/Engine/Cluster/"));

        long t2=System.currentTimeMillis();
        if (log.isDebugEnabled())
            log.debug("Digester for server.xml created " + ( t2-t1 ));
        return (digester);

    }
 

 

  //要查看digester的解析可查看how tomcat work 这本书的第十五章,有详细介绍

 

  1. inputSource.setByteStream(inputStream);  
  2.            //把Catalina这个类压入栈顶部  
  3.            digester.push(this);  
  4.     //压入顶部之后,在digester中就可以此类与server.xml进行相应的解析,比如该类的server实例化  
  5.            digester.parse(inputSource);  
  6.            inputStream.close();  

 

digester.push(this);把该对象压入到栈中,以便为这个类中的属性进行初始化,如Server

digester.parse(inputSource);为对里面所设置的对象进行初始化等一系列操作.

0
0
分享到:
评论

相关推荐

    tomcat-redis-session-manager-1.2-tomcat-7-java-7

    tomcat-redis-session-manager-1.2-tomcat-7-java-7tomcat-redis-session-manager-1.2-tomcat-7-java-7tomcat-redis-session-manager-1.2-tomcat-7-java-7tomcat-redis-session-manager-1.2-tomcat-7-java-7tomcat-...

    Maven使用tomcat8-maven-plugin插件.docx

    Maven 使用 tomcat8-maven-plugin 插件 Maven 是一个流行的构建自动化工具,它可以帮助开发者自动完成项目的编译、测试、打包、部署等任务。 Tomcat 是一个流行的 Web 服务器,Maven 提供了一个插件 tomcat8-maven-...

    tomcat7-maven-plugin-2.2.jar

    《深入解析修改版tomcat7-maven-plugin-2.2.jar》 在Java开发领域,Maven作为项目管理和构建工具,极大地简化了依赖管理和构建流程。而Tomcat,作为广泛使用的开源Servlet容器,是Java Web应用部署的首选平台。当...

    tomcat-redis-session-manager源码

    《深入解析Tomcat-Redis-Session-Manager源码》 在现代Web应用中,服务器端会话管理是一个至关重要的部分,特别是在高并发、分布式环境中。Tomcat作为最流行的Java Servlet容器,提供了丰富的功能来支持这一需求。...

    开发工具 apache-tomcat-8.0.41-windows-x86

    开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-...

    tomcat8-maven-plugin-3.0-r1655215.jar

    解决tomcat8-maven-plugin-3.0-r1655215.jar阿里云同有的问题。放到路径org\apache\tomcat\maven\tomcat8-maven-plugin\3.0-r1655215\就可以了

    apache-tomcat-9.0.8-src源码资源

    通过对`apache-tomcat-9.0.8-src`源码的深入研究,我们可以了解到Tomcat如何处理网络请求,怎样管理Web应用,以及如何实现各种高级特性。这对于开发者来说是一份宝贵的学习资料,可以帮助他们更好地优化应用程序,...

    tomcat8.5.20-redis-session共享-JAR包大全

    apache-tomcat-8.5.20.tar.gz源码包和context.xml文件,这套配置是我自己亲测可用的。。另外我用的redis4这个版本。注意:如果你使用的TOMCAT其他版本。例如tomcat6或者7这套JAR包可能不可用,tomcat8.0没有测试。...

    apache-tomcat-7.0.81-src 源码免费下载

    在"apache-tomcat-7.0.81-src"这个压缩包中,你将获得Tomcat 7.0.81版本的完整源代码,这包括了服务器的所有核心组件和模块。通过分析这些源码,我们可以学习到以下关键知识点: 1. **Servlet容器**:Tomcat作为...

    tomcat-redis-session-manager的jar包-包含Tomcat7和Tomcat8

    《深入理解Tomcat-Redis-Session-Manager:在Tomcat7和Tomcat8中的应用》 在现代Web应用程序开发中,session管理是一个至关重要的环节,它涉及到用户会话的持久化和跨请求的数据共享。传统的session管理方式在高...

    apache-tomcat-6.0.53-src

    apache-tomcat-6.0.53-src,apache tomcat 6.0.53的源码。 压缩包文件清单: apache-tomcat-6.0.53-src.tar.gz apache-tomcat-6.0.53-src.tar.gz.asc apache-tomcat-6.0.53-src.tar.gz.md5 apache-tomcat-6.0.53-...

    tomcat6-dta-ssl-1.0.0.jar

    tomcat6-dta-ssl-1.0.0.jar 此类文件将有助于tomcat支持ssl协议

    tomcat-redis-session-manager for tomcat8.5

    压缩文件包括tomcat-redis-session-manager-master-2.0.0.jar、jedis-2.7.3.jar、commons-pool2-2.3.jar三个jar包使用方法请参照https://github.com/jcoleman/tomcat-redis-session-manager。apache-tomcat-8.5.33....

    tomcat源码+文档pdf+源码解析

    这个资源包包含了Tomcat的源码、文档以及源码解析,对于深入理解Tomcat的工作原理、优化应用性能以及进行二次开发具有极大的帮助。 首先,让我们深入探讨Tomcat的源码。源码是软件的基石,通过阅读源码,我们可以...

    tomcat-redis-session-manager包集合下载(tomcat8)

    **知识点四:配置tomcat-redis-session-manager** 1. **添加依赖**:将下载的jar包添加到Tomcat的lib目录,或者在Maven或Gradle项目中添加对应的依赖。 2. **修改Tomcat配置**:在`$CATALINA_HOME/conf/context.xml`...

    apache-tomcat-8.5.78-windows-x64安装包-kaic.rar

    apache-tomcat-8.5.78-windows-x64安装包 apache-tomcat-8.5.78-windows-x64安装包 apache-tomcat-8.5.78-windows-x64安装包 apache-tomcat-8.5.78-windows-x64安装包 apache-tomcat-8.5.78-windows-x64安装包 ...

    tomcat-redis-session-manager-1.2-tomcat-6.jar

    用于配置 tomcat-redis-session-manager

    apache-tomcat-9.0.45-windows-x64

    apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-...

    tomcat-redis-session-manager-1.2-tomcat-6&7

    标题 "tomcat-redis-session-manager-1.2-tomcat-6&7" 指的是一个用于在Tomcat服务器中集成Redis作为session管理器的组件。这个组件使得Web应用程序可以利用Redis分布式缓存系统来存储和管理用户的会话数据,从而...

Global site tag (gtag.js) - Google Analytics