首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Coder 爱通译 How Tomcat Works 第五章 第一部分

2012-08-22 
Coder 爱翻译 How Tomcat Works 第五章 第一部分Chapter 5: Container一个容器是一个为servlet处理请求和

Coder 爱翻译 How Tomcat Works 第五章 第一部分
Chapter 5: Container

一个容器是一个为servlet处理请求和给客户端填充response对象的模块。一个容器可以用
org.apache.catalina.Container接口表示。这里有四种类型的容器:Engine, Host, Context 和Wrapper。这章包含了Context和Wrapper。把其它两个容器放在后面第十三章讲解。

The Container Interface

一个容器必须实现了org.apache.catalina.Container。你看到了在第四章中,你传递一个Container实例给连接器的toContainer方法,这样连接器可以调用容器的invoke方法。回顾下面的Bootstrap类的代码:

Listing 5.2: The StandardValveContext class in Tomcat 5    package org.apache.catalina.core; import java.io.IOException; import javax.servlet.ServletException; import org.apache.catalina.Request; import org.apache.catalina.Response; import org.apache.catalina.Valve; import org.apache.catalina.ValveContext; import org.apache.catalina.util.StringManager;  public final class StandardValveContext implements ValveContext {   protected static StringManager sm =  StringManager.getManager(Constants.Package);    protected String info =  "org.apache.catalina.core.StandardValveContext/1.0";    protected int stage = 0;    protected Valve basic = null;    protected Valve valves[] = null;    public String getInfo() {      return info;     }  public final 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          (sm.getString("standardPipeline.noValve"));      }    }     void set(Valve basic, Valve valves[]) {      stage = 0;      this.basic = basic;      this.valves = valves;    } }

你可以看见Tomcat 4中的StandardPipelineValveContext类和Tomcat 5 中的StandardValveContext类相似。

下面们将要详细讨论Pipeline, Valve和 ValveContext接口:
1 楼 amwiacel 2010-12-10   一个容器可以用
org.apache.catalina.Container接口表示。这里有四种类型的容器:Engine, Host, Context 和Wrapper。 这种直译不是很好,其实这种分法是一种抽象模型,得从设计模式上去理解其意思。 2 楼 dicmo 2010-12-10   amwiacel 写道一个容器可以用
org.apache.catalina.Container接口表示。这里有四种类型的容器:Engine, Host, Context 和Wrapper。 这种直译不是很好,其实这种分法是一种抽象模型,得从设计模式上去理解其意思。
谢谢指正。这个措词是不恰当。抽象层面的东西。

热点排行