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

6411

被折叠的 条评论
为什么被折叠?



