`

PipeLine and Value

 
阅读更多

参考博文 : http://gearever.iteye.com/blog/1540028

 

pipleLine 是管道,而value可以理解成是阀门 , 容器与容器间通过管道连接

所以容器中有管道这个组件(定义在ContainerBase中),管道中又存在阀门,来控制信息的流动。

一个管道中可以有多个阀门,以链表的形式表示!!Tomcat 启动时候,这些组件就会相应的启动!

如果把Tomcat比作一台大的机器的话,那么Container ,pipeline ,value就是他内部的一些小零件,当机器启动的时候,

那么相应着的,必须使小零件转动。

 

    StanardPipeline

    Value (interface) ---- ValueBase  --- (StanardEngineValue , StandardHostValue ..........) ;

    Value 的各种子类,不同之处在于invoke()定义的业务逻辑的不同!也就是说,你这个阀门究竟要做什么事,由他来定义!

 

 // coyoteAdapter service 方法: 这里是接着Tomcat接收请求那篇过来 ;

 public void service(org.apache.coyote.Request req,
    	                org.apache.coyote.Response res)
        throws Exception {
// 因为Connector中有一个成员变量container 并不是他所在的容器,而是请求传递的地方,然后调用管道中第一个value(StandardEngineValue) ;
	connector.getContainer().getPipeline().getFirst().invoke(request, response);
	//省略若干代码
    }

 // StandardEngineValue

public final void invoke(Request request, Response response)
        throws IOException, ServletException {

        // Select the Host to be used for this Request
        Host host = request.getHost();
        if (host == null) {
            response.sendError
                (HttpServletResponse.SC_BAD_REQUEST,
                 sm.getString("standardEngine.noHost", 
                              request.getServerName()));
            return;
        }

        // Ask this Host to process this request
        host.getPipeline().getFirst().invoke(request, response); 
    }

 StandardHost中ErrorReportValue :

  

public void invoke(Request request, Response response)
        throws IOException, ServletException {
        // Perform the request 调用StandardHost的pipeLine 中下一个value
        getNext().invoke(request, response);
        //省略若干代码        
    }
context.getPipeline().getFirst().invoke(request, response);
  
wrapper.getPipeline().getFirst().invoke(request, response);

 

可以定制化Value , 通常在server.xml中配置,只要继承了org.apache.catalina.valves.ValveBase 

<Engine name="Catalina" defaultHost="localhost">  
  <Valve className="MyValve0"/>  
  <Valve className="MyValve1"/>  
  <Valve className="MyValve2"/>  
   ……  
  <Host name="localhost"  appBase="webapps">  
  </Host>  
</Engine>  

 当定制了Value时,就会调用pipeLine 中add方法,把Value添加到相应的管道中!

  就像我们在上面看到的一样,每个容器都要一个缺省的(就是不要在server.xml)中配置的Value;

  他们总是位于value链的末端!最后才被调用!就像上面看到的一样,我们调用的都是第一个,并没有看到它调用了整个value链啊。

  原因就在这,因为这些每个容器默认的value 永远都是在最后一个,所以不存在会调用下一个的情况(getNext()),但是,像自己定义的

  的Value , 那么你在实现invoke()的时候,内部就必须getNext(),即调用下一个Value的操作,就像上面的ErrorReportValue一样!

 

  看下面的addvalue() :

 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); // basic 就是缺省的 添加到最后 
        } else {
            Valve current = first;
            while (current != null) { //这里在一个链表中找到basic , 然后在它前面插入
				if (current.getNext() == basic) { 
					current.setNext(valve);
					valve.setNext(basic);
					break;
				}
				current = current.getNext();
			}
        }

    }

 四大容器的标准valve的调用逻辑图:

  

 

 

 

 

分享到:
评论

相关推荐

    Alpaca-LoRA-RLHF-PyTorch

    a full pipeline to finetune Alpaca LLM with LoRA and RLHF on consumer hardware。 第一步SFT之前,切记有个注意事项,需要检查下 安装的peft代码, src/peft/utils/save_and_load.py , 如果 line 52 有这行代码 ...

    OpenGL ES 2.0 Programming Guide

    variables, types, constructors, structures, arrays, attributes, uniforms, varyings, precision qualifiers, and invariance * Inputting geometry into the graphics pipeline, and assembling geometry into ...

    Managed Directx 9 Kick Start - Graphics And Game Programming

    Using Value Types as Objects Understanding the Performance Implications of the Event Model Understanding the Cost of Methods In Brief Part VII. Appendices Appendix A. Using the ...

    Big Data Architect's Handbook

    The big data architects are the “masters” of data, and hold high value in today’s market. Handling big data, be it of good or bad quality, is not an easy task. The prime job for any big data ...

    Sams.Teach.Yourself.Big.Data.Analytics.with.Microsoft.HDInsight

    Introduction of Big Data, NoSQL systems, its Business Value Proposition and use cases examples Introduction to Hadoop, Architecture, Ecosystem and Microsoft HDInsight Getting to know Hadoop 2.0 and ...

    Scala.Functional.Programming.Patterns.178398

    Get to know about functional programming and the value Scala's FP idioms bring to the table Solve day-to-day programming problems using functional programming idioms Cut down the boiler-plate and ...

    Big Data Architect’s Handbook 2018pdf

    The big data architects are the “masters” of data, and hold high value in today’s market. Handling big data, be it of good or bad quality, is not an easy task. The prime job for any big data ...

    Continuous Delivery & Continuous Integration

    organization move from idea to release faster than ever—so you can deliver value to your business rapidly and reliably. -------------------------------------------- For any software developer who ...

    Principles.of.Data.Science

    Create actionable insights and transform raw data into tangible value Book Description Need to turn your skills at programming into effective data science skills? Principles of Data Science is created...

    Mastering Data Mining with Python(PACKT,2016)

    Since data is vital to just about every modern organization, it is worth taking the next step to unlock even greater value and more meaningful understanding. If you already know the fundamentals of ...

    The.DevOps.Adoption.Playbook.1119308747.pdf )

    Deliver high-value applications and systems with velocity and agility by adopting the necessary practices, automation tools, and organizational and cultural changes that lead to innovation through ...

    X-Frame FPS Accelerator v3.5

    Unity 2019.3 Universal Rendering Pipeline support! X-Frame FPS Accelerator reduces lag and contributes to higher FPS (Frames Per Second) providing a smooth gameplay to your users. X-Frame is ...

    OpenGL ES.2.0 Programming Guide

    Using detailed C-based code examples, they demonstrate how to set up and program every aspect of the graphics pipeline. You’ll move from introductory techniques all the way to advanced per-pixel ...

    Mastering.Data.Mining.with.Python.1785889958

    Since data is vital to just about every modern organization, it is worth taking the next step to unlock even greater value and more meaningful understanding. If you already know the fundamentals of ...

    Amplify Shader Editor1.5.4 最新版

    • Improved editor rendering pipeline leading to huge performance boost. • Reduced editor memory allocations resulting on a low Garbage Collector impact. • Editor more snappy and responsive when ...

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...

    Amplify Shader Editor 1.4.3

    * Added support for Lightweight Scriptable Rendering Pipeline * New Sample * SRP Lightweight GlintSparkle * SRP Lightweight Coverage * New Template: * LightweightSRP * New Shader Function * Create ...

    Principles of Computer Architeture

    10.3.3 Keeping the pipeline Filled 411 10.4 OVERLAPPING REGISTER WINDOWS 415 ULTIPLE INSTRUCTION ISSUE (SUPERSCALAR) MACHINES – THE POWERPC 601 10.5 M TABLE OF CONTENTS xix 423 ASE STUDY: THE POWER...

    jedis使用指南

    官方的说明是:starts a pipeline,which is a very efficient way to send lots of command and read all the responses when you finish sending them。简单点说pipeline适用于批处理。当有大量的操作需要一次性...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Tabs Function Declarations and Definitions Function Calls Conditionals Loops and Switch Statements Pointer and Reference Expressions Boolean Expressions Return Values Variable and Array ...

Global site tag (gtag.js) - Google Analytics