一个context代表一个web网站,一个context包含多个wrappers。这个章节介绍了catalina的standardContext。
一、StandardContext Configuration
standardContext Configuration是配置standardContext的。它会读取web.xml以便让standardcontext配置好。StandardContext Configuration会在lifecycle listener上实现,以便在standardContext启动时完成配置,如果失败则不会处理请求
二、StandardContext Class's Constructor
public StandardContext() {
super();
pipeline.setBasic(new StandardContextValve());
namingResources.setContainer(this);
}
构造函数最重要的就是对pipeline设置standardContextValve了。
三、Starting StandardContext
start()方法主要是:
- 启动BEFOTE_START event
- 设置availability 属性为false
- 设置configured 属性为false
- 设置resources
- 设置loader
- 设置manager
- 设置mapper
- start及将其他组件和StandardContext联系起来
- start子containers(wrappers)
- start pipeline
- start manager
- 启动START event.这里会设置configuration
- 在配置成功后,检查configured的属性,如果是true则,调用postWelcomePages函数,加载那些需要提前加载的子wrappers
- 启动AFTER_START event.
四、Invoke Method
invoked(Request request, Response response)调用时会想检查是否这web application是否被重新加载。
五、Support for Reloading
在tomcat4中,web的重新加载是依靠standardContext中的WebappLoader实例,WebappLoader一个线程检查是否需要重新加载,只需要启动这个线程就可以了。
因为每一个像这样的方法都会开启一个线程,这样会导致资源的消耗,所以在tomcat5中则用backgroundProcess 方法,而处理都只用一个线程。
tomcat5会在基类,baseContainer中创建一个ContainerBackgroundProcessor实例,并开启这个实例,并将一个Container调用他的backgroundProcess 方法和调用他子Container的backgroundProcess 方法。