标签:tomcat servlet hashmap standardcontext standardcontextvalve
在tomcat4中,StandardContext.java是最大的一个类,有117k。废话不说,开始分析吧。public class SimpleContextConfig implements LifecycleListener { public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.START_EVENT.equals(event.getType())) { Context context = (Context) event.getLifecycle(); context.setConfigured(true); } } }在StandardContext配置完成后调用
setAvailable(false); setConfigured(false);3 配置资源 (这部分我也不是太懂)
((Lifecycle) loader).start(); ((Lifecycle) logger).start(); ((Lifecycle) mappers[i]).start();8 启动子容器
Container children[] = findChildren(); for (int i = 0; i < children.length; i++) { if (children[i] instanceof Lifecycle) ((Lifecycle) children[i]).start(); }9 启动管道
if (pipeline instanceof Lifecycle) ((Lifecycle) pipeline).start();10 触发START_EVENT,注意呀 观察者模式,SimpleContextConfig, configured会被设置为true
// Notify our interested LifecycleListeners // 会调用SimpleContextConfig的lifecycleEvent lifecycle.fireLifecycleEvent(START_EVENT, null);11 启动session
//session部分 if ((manager != null) && (manager instanceof Lifecycle)) ((Lifecycle) manager).start();12 (书上说)检查confired的值,postWelcomeFiles会载入需要提前载入的子容器,StandardContext的子容器能有什么?StandardWrapper呗。
if (!getConfigured()) ok = false; if (ok) { postWelcomeFiles(); }问题是加载需要提前载入的子容器是
if (ok) { setAvailable(true); } else { try { stop(); } catch (Throwable t) { log(sm.getString("standardContext.startCleanup"), t); } setAvailable(false); }stop里面具体的代码就不说了。
while (getPaused()) { //getPaused如果返回true 就说明正在重载 try { Thread.sleep(1000); } catch (InterruptedException e) { ; } }然后调用父类,也就是ContainerBase的invoke
Context context = (Context) getContainer(); wrapper = (Wrapper) context.map(request, true);接着在ContainerBase的map中先获得相应协议(http还是https)的映射器,再用映射器的map方法根据request的uri获得Wrapper。
addDefaultMapper(this.mapperClass); //private String mapperClass = "org.apache.catalina.core.StandardContextMapper";StandardContext会调用父类的addDefaultMapper。这里面,默认的协议是http
Class<?> clazz = Class.forName(mapperClass); Mapper mapper = (Mapper) clazz.newInstance(); mapper.setProtocol("http"); addMapper(mapper);在addMapper中
How tomcat works 读书笔记十二 StandardContext 上
标签:tomcat servlet hashmap standardcontext standardcontextvalve
原文地址:http://blog.csdn.net/dlf123321/article/details/41380081