一。server.xml

在每个容器对象里面都有一个pipeline,Pipeline就像是每个容器的逻辑总线。

    <Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false"> <!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
--> <!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
--> </Host>

二。源码追踪

1.Engine

    /**
* Create a new StandardEngine component with the default basic Valve.
*/
public StandardEngine() { super();
pipeline.setBasic(new StandardEngineValve());
/* Set the jmvRoute using the system property jvmRoute */
try {
setJvmRoute(System.getProperty("jvmRoute"));
} catch(Exception ex) {
}
// By default, the engine will hold the reloading thread
backgroundProcessorDelay = 10; }

2.Host

    /**
* Create a new StandardHost component with the default basic Valve.
*/
public StandardHost() { super();
pipeline.setBasic(new StandardHostValve()); }

3.Context

    /**
* Create a new StandardContext component with the default basic Valve.
*/
public StandardContext() { super();
pipeline.setBasic(new StandardContextValve());
broadcaster = new NotificationBroadcasterSupport(); }

4.Wrapper

    /**
* Create a new StandardWrapper component with the default basic Valve.
*/
public StandardWrapper() { super();
swValve=new StandardWrapperValve();
pipeline.setBasic(swValve);
broadcaster = new NotificationBroadcasterSupport(); if (restrictedServlets == null) {
restrictedServlets = new Properties();
try {
InputStream is =
this.getClass().getClassLoader().getResourceAsStream
("org/apache/catalina/core/RestrictedServlets.properties");
if (is != null) {
restrictedServlets.load(is);
} else {
log.error(sm.getString("standardWrapper.restrictedServletsResource"));
}
} catch (IOException e) {
log.error(sm.getString("standardWrapper.restrictedServletsResource"), e);
}
} }

三。ContainerBase

把Pipeline接口的实现委托给成员变量pipeline

public abstract class ContainerBase
implements Container, Lifecycle, Pipeline, MBeanRegistration, Serializable {

1.setBasic

    public void setBasic(Valve valve) {

        pipeline.setBasic(valve);

    }

2.invoke

    public void invoke(Request request, Response response)
throws IOException, ServletException { pipeline.getFirst().invoke(request, response); }

3.继承

四。StandardPipeline

1.setBasic

    public void setBasic(Valve valve) {

        // Change components if necessary
Valve oldBasic = this.basic;
if (oldBasic == valve)
return; // Stop the old component if necessary
if (oldBasic != null) {
if (started && (oldBasic instanceof Lifecycle)) {
try {
((Lifecycle) oldBasic).stop();
} catch (LifecycleException e) {
log.error("StandardPipeline.setBasic: stop", e);
}
}
if (oldBasic instanceof Contained) {
try {
((Contained) oldBasic).setContainer(null);
} catch (Throwable t) {
;
}
}
} // Start the new component if necessary
if (valve == null)
return;
if (valve instanceof Contained) {
((Contained) valve).setContainer(this.container);
}
if (valve instanceof Lifecycle) {
try {
((Lifecycle) valve).start();
} catch (LifecycleException e) {
log.error("StandardPipeline.setBasic: start", e);
return;
}
} // Update the pipeline
Valve current = first;
while (current != null) {
if (current.getNext() == oldBasic) {
current.setNext(valve);
break;
}
current = current.getNext();
} this.basic = valve; }

1.addValve

    public void addValve(Valve valve) {

        // Validate that we can add this Valve
if (valve instanceof Contained)
((Contained) valve).setContainer(this.container); // Start the new component if necessary
if (started) {
if (valve instanceof Lifecycle) {
try {
((Lifecycle) valve).start();
} catch (LifecycleException e) {
log.error("StandardPipeline.addValve: start: ", e);
}
}
// Register the newly added valve
registerValve(valve);
} // Add this Valve to the set associated with this Pipeline
if (first == null) {
first = valve;
valve.setNext(basic);
} else {
Valve current = first;
while (current != null) {
if (current.getNext() == basic) {
current.setNext(valve);
valve.setNext(basic);
break;
}
current = current.getNext();
}
} }

六。public interface Pipeline

Interface describing a collection of Valves that should be executed in sequence when the invoke() method is invoked. It is required that

a Valve somewhere in the pipeline (usually the last one) must process the request and create the corresponding response, rather than

trying to pass the request on.

There is generally a single Pipeline instance associated with each Container. The container's normal request processing functionality is

generally encapsulated in a container-specific Valve, which should always be executed at the end of a pipeline. To facilitate this, the

setBasic() method is provided to set the Valve instance that will always be executed last. Other Valves will be executed in the order

that they were added, before the basic Valve is executed.

tomcat 的 Pipeline 机制的更多相关文章

  1. Tomcat类加载器机制

    Tomcat为什么需要定制自己的ClassLoader: 1.定制特定的规则:隔离webapp,安全考虑,reload热插拔 2.缓存类 3.事先加载 要说Tomcat的Classloader机制,我 ...

  2. tomcat的classloader机制

    本系列博客打算分析一下tomcat7.x的源码,其中可能会穿插一些java基础知识的介绍  读tomcat的源码的时候,我建议和官方的User Guide一起阅读,明白tomcat做某件事情的目的之后 ...

  3. 函数式编程:面向可复用的map和pipeline机制的编程语言

    函数式编程:面向可复用的map和pipeline机制的编程语言

  4. 设计模式——责任链(结合Tomcat中Filter机制)

    设计模式:责任链模式 说责任链之前,先引入一个场景,假如规定学生请假小于或等于 2 天,班主任可以批准:小于或等于 7 天,系主任可以批准:小于或等于 10 天,院长可以批准:其他情况不予批准:以此为 ...

  5. Tomcat中Pipeline

    Pipeline 节选部分源码.源码版本 Tomcat8.5 处理模式 Pipeline--Valve是一种责任链模式,它和普通责任链模式有两点区别: 每个Pipeline都是有特定的Valve,而且 ...

  6. tomcat集群机制剖析及其生产部署选型

    为什么要使用集群? 为什么要使用集群?主要有两方面原因:一是对于一些核心系统要求长期不能中断服务,为了提供高可用性我们需要由多台机器组成的集群:另外一方面,随着访问量越来越大且业务逻辑越来越复杂,单台 ...

  7. Tomcat架构解析(五)-----Tomcat的类加载机制

    类加载器就是根据类的全限定名(例如com.ty.xxx.xxx)来获取此类的二进制字节流的代码模块,从而程序可以自己去获取到相关的类. 一.java中的类加载器   1.类加载器类别 java中的类加 ...

  8. sklearn 中的 Pipeline 机制

    转载自:https://blog.csdn.net/lanchunhui/article/details/50521648 from sklearn.pipeline import Pipeline ...

  9. 深入剖析tomcat的类加载机制

    1JVM类加载机制 JVM的ClassLoader通过Parent属性定义父子关系,可以形成树状结构.其中引导类.扩展类.系统类三个加载器是JVM内置的. 它们的作用分别是: 1)引导类加载器:使用n ...

随机推荐

  1. 【应用篇】Activiti外置表单实例demo(四)

    在这里我想说的外置表单.是说我们将我们自己的jsp(.form,.html)等页面上传到工作流的数据库中,当任务运行到当前结点时.给我们像前台发送绑定好的表单. 此处是给表单绑定表单的过程 water ...

  2. MySQL(8)--Cluster 7.4 rpm centos7

    还没来得及写.我就知道一个月完毕不了,暂时添加的工作总是拖后腿. .. MySQL集群 docker下安装MySQL Cluster报错了.是我image的包少了perl.老实装吧.image又小不了 ...

  3. putty英文乱码---DM8168_ETV_V1.1(路视明)

    配置參照http://jingyan.baidu.com/article/c74d600048ed620f6a595d12.html 注意事项: 假设出现 英文也乱码.那么就是波特率设置的问题,应该这 ...

  4. Atitit.跨语言  文件夹与文件的io操作集合  草案

    Atitit.跨语言  文件夹与文件的io操作集合  草案 1. Jdk原生的太难用了..1 2. PS: apache commons-io包,FileUtils有相关的方法,IOUtils一般是拷 ...

  5. php 结合md5的加密,解密方法

    php 结合md5的加密,解密方法 张映 发表于 2012-06-28 分类目录: php 标签:md5, php 最近在整理代码发现了一个不错的东西,结合md5的加解密算法.网上关于php结合md5 ...

  6. Mysql 5.7 liunx 忘记密码的补救方法

    linux下mysql的root密码忘记解决方 1.修改MySQL的登录设置 # vim /etc/my.cnf 在[mysqld]的段中加上一句: skip-grant-tables 例如: [my ...

  7. diamond源码阅读-diamond-server

    diamond-server 1 增加一条数据 /diamond-server/admin.do?method=postConfig 1.1 调用 this.configService.addConf ...

  8. 【JavaEE】Springmvc+Spring+Hibernate整合及example

    前面两篇文章,分别介绍了Springmvc和Spring的搭建方法,本文再搭建hibernate,并建立SSH最基本的代码结构. Hibernate和前面两个比就比较复杂了,Hibernate是一个o ...

  9. 微信小程序 view 布局

    刚看到这个效果的时候还真是和ReactNative的效果一致,属性也基本的一样. view这个组件就是一个视图组件使用起来非常简单. 主要属性: flex-direction: 主要两个特性”row” ...

  10. unity3d面试题与参考答案

    1.C#程序题 1 2 3 4 5 6 7 8 9 10 11 private static void aaa(int x) { x = 10; }   private static void bbb ...