tomcat6源码学习1.0.0_Catalina类

本文详细解析了Tomcat启动过程中的关键步骤,包括初始化Embedded类、设置安全保护配置、使用Digester解析server.xml配置文件等内容。

1  Catalina extends Embedded
  
2  public class Embedded  extends StandardService implements Lifecycle
   2.1 public class Embedded  extends StandardService implements Lifecycle
   2.1.1 public class StandardService   implements Lifecycle, Service, MBeanRegistration
   2.1.1.1 = 3
   2.1.1.2 public interface Service
   2.1.1.3 MBeanRegistration
3  public interface Lifecycle

   3.1 Lifecycle 包括以下内容
    public static final String INIT_EVENT = "init";
    public static final String BEFORE_START_EVENT = "before_start";
    public static final String AFTER_START_EVENT = "after_start";
    public static final String STOP_EVENT = "stop";
    public static final String BEFORE_STOP_EVENT = "before_stop";
    public static final String AFTER_STOP_EVENT = "after_stop";
    public static final String DESTROY_EVENT = "destroy";
    public static final String PERIODIC_EVENT = "periodic";
   
    public void addLifecycleListener(LifecycleListener listener);
    public LifecycleListener[] findLifecycleListeners();
    public void removeLifecycleListener(LifecycleListener listener);
    public void start() throws LifecycleException;
    public void stop() throws LifecycleException;
   
    //Lifecycle 描述了程序运行的生命周期

4  手工调试
    public static void main(String args[]) {
     String argsNew[] = {"start"}; //手工增加此参数
        (new Catalina()).process(argsNew);
    }

    4.1 初始化 Catalina // goto
   4.1.1    public Embedded() {
        this(null); // goto 1.2
    }

   4.1.2  public Embedded(Realm realm) {

        super();
        setRealm(realm);
        setSecurityProtection();  // goto 1.3
       
    }
   4.1.3  protected void setSecurityProtection(){
        SecurityConfig securityConfig = SecurityConfig.newInstance(); //读取资源文件 catalina.properties
        securityConfig.setPackageDefinition();
        securityConfig.setPackageAccess();
    }
  //初始化完成
   4.2 process(args)执行

   Digester digester = createStartDigester(); // 需要的系统属性,内容为 server.xml中的元素
   //此物很伟大,见 《用Digester简化XML文档处理》一文所述
   Digester for server.xml created // 由此可知,tomcat 先将 server.xml 的结果设置在了digester,然后去解析

   按以下步骤解析
            inputSource.setByteStream(inputStream);// 读取文件
            digester.push(this); // 4.2.1 压入堆栈
            digester.parse(inputSource); //4.2.2 解析 server.xml
            inputStream.close();

    4.2.2.1
public Object parse(InputSource input) throws IOException, SAXException {
        configure();   //取解析器 4.2.2.1.1
        getXMLReader().parse(input);
        return (root);

    }
  4.2.2.1.1
 //下面两个东西貌似tomcat自己专用的XML解析器
        log = LogFactory.getLog("org.apache.commons.digester.Digester");
        saxLog = LogFactory.getLog("org.apache.commons.digester.Digester.sax");
//事实是这个解析器 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值