How Tomcat Work——容器

容器是一个处理用户servlet请求并返回对象给web用户的模块。
org.apache.catalina.Container接口定义了容器的形式,有四种容器:Engine
(引擎), Host(主机), Context(上下文), 和 Wrapper(包装器)。这一
章将会介绍context和wrapper,而Engine和 Host会留到第十三章介绍。这一
章首先介绍容器接口,然后介绍容器的工作流程。然后介绍的内容是 Wrapper
和Context接口。然后用两个例子来总结wrapper和context容器。
容器接口
一个容器必须实现org.apache.catalina.Container接口。就如在第四章中看到
的,传递一个Container实例给Connector对象的setContainer方法,然后
Connector对象就可以使用container 的invoke方法,重新看第四章中
Bootstrap类的代码如下:
   HttpConnector connector = new HttpConnector();
   SimpleContainer container = new SimpleContainer();
   connector.setContainer(container);

一个Catalina功能部署不一定需要所有的四种类型的容器。例如本章的第一个
应用程序仅仅包括一个wrapper,而第二个应用程序是一个包含Context和
wrapper的容器模块。
一个容器可以有一个或多个低层次上的子容器。例如,一个Context有一个或多
个wrapper,而wrapper作为容器层次中的最底层,不能包含子容器。讲一个容
器添加到另一容器中可以使用在Container接口中定义的addChild()方法,如
下定义:
   public void addChild(Container child);
删除一个容器可以使用Container接口中定义的removeChild()方法,删除方法
如下表示:
public void removeChild(Container child);
另外容器接口支持子接口查找和获得所有子接口集合的方法findChild和
findChildren方法。如下表示:
public Container findChild(String name);
public Container[] findChildren();
一个容器还包含一系列的部分如Lodder、 Loggee、 Manager、 Realm和Resources。
这些组成部分将会在后边章节中进行讨论。需要注意的一点是 Container接口对
于这些组件都定义了set和get方法包括: getLoader and setLoader, getLogger
and setLogger, getManager and setManager, getRealm and setRealm, and
getResources and setResources.
更有意思的是Container接口被设计成Tomcat管理员可以通过server.xml文件
配置来决定其工作方式的模式。它通过一个pipeline(流水线)和一系列的阀
门来实现,这些内容将会在下一节Pipelining Task中讨论。
更有意思的是Container接口被设计成Tomcat管理员可以通过server.xml文件
配置来决定其工作方式的模式。它通过一个pipeline(流水线)和一系列的阀
门来实现。

猜你喜欢

转载自bioubiou.iteye.com/blog/1666229