Catalina-Container接口

来源:互联网 发布:剑灵男刺客捏脸数据图 编辑:程序博客网 时间:2024/06/15 19:48

对于Catalina中的servlet容器,首先需要注意的是

4中类型的容器,分别对应不用概念层次

Engine:表示整个Catalina servlet引擎

Host:表示包含一个或多个Context容器的虚拟主机

Context:表示一个Web应用程序。一个Context可以有多个Wrapper

Wrapper:表示一个独立的Servlet

管道任务

管道包含该Servlet容器将要调用的任务。

一个阀表示一个具体的执行任务

在servlet容器的管道中,有一个基础阀,可以添加任意数量的阀。

阀的数量是指额外添加的阀数量,即不包括基础阀

管道会调用其中的第一个阀开始处理,之后会调用后续的阀。

当所有阀被调用完之后,将调用基础阀。

但是Tomcat使用了另一种调用方式

引入接口org.apache.catalina.ValueContext

通过调用容器的invoke()方法,在调用其管道的invoke()方法

public void invoke(Request request, Response response)    throws IOException, ServletException {    // Invoke the first Valve in this pipeline for this request    (new SimplePipelineValveContext()).invokeNext(request, response);  }
  public void invokeNext(Request request, Response response)      throws IOException, ServletException {      int subscript = stage;      stage = stage + 1;      // Invoke the requested Valve for the current request thread      if (subscript < valves.length) {        valves[subscript].invoke(request, response, this);      }      else if ((subscript == valves.length) && (basic != null)) {        basic.invoke(request, response, this);      }      else {        throw new ServletException("No valve");      }    }
Pipeline()接口

invoke()来开始调用管道中的阀和基础阀。

addValue()向管道中添加新的阀

removeValue()从管道中删除某个阀

setBasic()方法将基础阀设置到管道中

getBasic()获取基础阀

Value()接口(阀)

invoke()

getInfo()返回阀的实现信息

ValueContext()接口

getInfo()返回ValueContext的实现信息

invokeNext()首先调用管道中的第一个阀,第一个阀执行完成后,会调用后面阀继续执行,会将自身传递给下个阀

Wrapper接口

load()载入并初始化servlet类

allocate()会分配一个已经初始化的Servlet实例








0 0