Java Web容器之Tomcat6.0 源码学习笔记
好记性不如烂笔头,把学习过的知识记下来以后参考,文笔不好,只作笔记之用,后面继续补充。
Tomcat 根据server.xml文件中的配置将Web服务器划分为以下几个组件:
StandardServer
StandardServer对象,实现Server接口,服务器启用后内存中只有一个StandardServer对象,可包含多个Service组件,由StandardServer负责启用其包含的Service组件
// 属性域private Service services[] = new Service[0];// Start 部分代码摘要// Start our defined Servicessynchronized (services) { for (int i = 0; i < services.length; i++) { if (services[i] instanceof Lifecycle) ((Lifecycle) services[i]).start(); }}
protected Container container = null;protected Connector connectors[] = new Connector[0];// Start our defined Container firstif (container != null) { synchronized (container) { if (container instanceof Lifecycle) { ((Lifecycle) container).start(); } }}// Start our defined Connectors secondsynchronized (connectors) { for (int i = 0; i < connectors.length; i++) { if (connectors[i] instanceof Lifecycle) ((Lifecycle) connectors[i]).start(); }}
/** * Deploy applications for any directories or WAR files that are found * in our "application root" directory. */ protected void deployApps() { 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()); }
context.setPath(contextPath);context.setDocBase(file);host.addChild(context);
// Configure and call application event listenersif (ok) { if (!listenerStart()) { log.error( "Error listenerStart"); ok = false; }}
// Configure and call application filtersif (ok) { if (!filterStart()) { log.error( "Error filterStart"); ok = false; }}
// Load and initialize all "load on startup" servletsif (ok) { loadOnStartup(findChildren());}
public void addChild(Container child) { throw new IllegalStateException (sm.getString("standardWrapper.notChild"));}