浅析Tomcat之Pipeline和Value
public abstract class ValveBase extends LifecycleMBeanBase implements Contained, Valve{ /** * The next Valve in the pipeline this Valve is a component of. */ protected Valve next = null; @Override public Container getContainer() { return (container); } @Override public void setContainer(Container container) { this.container = container; } @Override public Valve getNext(){ return (next); } @Override public void setNext(Valve valve){ this.next = valve; } @Override public abstract void invoke(Request request, Response response) throws IOException, ServletException; @Override public void event(Request request, Response response, CometEvent event) throws IOException, ServletException { // Perform the request getNext().event(request, response, event); }}
?上述精简过的代码是实现了Value接口的基础类ValueBase,它有一个Value类型的内部属性next,即同一个Pipeline中的后续Value的引用.如果玩过Java数据结构或作STL的基本上不难理解这是一个单向链表的节点.继承这个ValueBase针对不同的容器实现了不同版本的阀如StandardEngineValue,StandardHostValue,StandardContextValue,StandardWrapperValve等.他们之间不同的实现就是invoke和event的方法不同.而实际上也就是请求的路由选择,Filter应用和Servlet的处理(此部分内容后续博文解释).
Pipeline的标准实现是StandardPipeline.它的类注释是Standard implementation of a processing Pipeline that will invoke a series of Valves that have been configured to be called in order.This implementation can be used for any type of Container.意思是它用于依次执行已经配置好的阀.
?
?
首发于泛泛之辈 -?http://www.lihongkun.com/archives/146