zoukankan      html  css  js  c++  java
  • tomcat启动(Ⅷ)--请求最终目的地 getContainer().getPipeline().getFirst().invoke(request, response)

    当tomcat的Conector保存着StandardService实例,而StandardService保存着Container的实例

    当Http11NioProcessor.process()方法内调用getAdapter.service(request,response)时会调用CoyoteAdapter.service() 

    上面会调用请求对应的container的方法。

    在这之前有必要说下Container的初始化。

    在StandardService的initInternal()中会执行Container.init方法。这个开始的container表示StandardEngine,从Catalina.createDigester方法详细理解可以知道

    先调用构造方法

    /**
         * 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) {
                log.warn(sm.getString("standardEngine.jvmRouteFail"));
            }
            // By default, the engine will hold the reloading thread
            backgroundProcessorDelay = 10;
    
        }

     

    创建一个StandardEngine组件,为管道StandardPipeLine对象设置Basic,Basic即Vlave阀门对象,用于处理请求的对象。设置为StandardEngineValve()

    同样的,StandardEngine的Valve对象为StandardEngineValve

    在源码中也可以看到StandardHost的为:StandardHostValve,StandardContext的为:StandardContextValve,StandardWrapper的为:StandardWrapperValve

    connector.getService().getContainer().getPipeline().getFirst().invoke(request, response)

    Pipeline管道,getFirst()获得的是Pipeline存放的第一个Valve对象。Valve阀门。---------这些类的名字取得很形象

    管道连通着所有阀门,当水从供水局(有这个部门吗?)到我们的房子时候,首先要从水源处被抽水机抽到水处理厂,然后水处理厂收到请求信息(要将水放到城市里的哪个位置,这里即Host),水处理厂就会通过放水进入管道,而接受方就是城市的某个区,这时流到区的水经过区阀门处理转发到特定的村,村里又通过村子的阀门将水转发到特定的房子中,房子中就开始可以任意处置水了。

    上面水到具体房子过程,跟请求处理转发过程相似。

    Http11NioProcessor类对请求进行包装处理。通过CoyoteAdapter通过管道请求转发到第一个阀门中,然后又找到其下属StandardHost,StandardHostValve阀门又将请求转发到StandardContextValve上下文对象的阀门中进行对应的处理后继续转发到StandardWrapperValve阀门。StandardWrapperValve类对应的是一个Servlet类,这里就会对请求进行具体处理了。

    到这里就告一段落了,发现源码里还有很多我不认识的它,深究我就输了,再见!

  • 相关阅读:
    ylbtech-dbs-m-YinTai(银泰网)
    ylbtech-memorandum(备忘录)-数据库设计
    设计工作-Axure
    RegexHelper
    convert image to base64
    MVC Movie App
    ASP.NET MVC file download sample
    MVC架构、WebForm与MVC对比
    第2章 数字之魅——子数组之和的最大值(二维)
    第2章 数字之魅——求数组的子数组之和的最大值
  • 原文地址:https://www.cnblogs.com/gne-hwz/p/7833194.html
Copyright © 2011-2022 走看看