1. 程式人生 > 實用技巧 >python 解析 url地址

python 解析 url地址

tomcat8.5.57原始碼閱讀筆記5.1 - 管道1. 從程式碼上看, 只獲取了 first, 那說好的很多閥門呢? 帶著疑問, 只能去看一下 StandardPipeLine 的閥門.

  1. 預設情況下, 這裡的getFirst() 獲取到的是 StandardEngineValve, 其實他是 basic.   

StandardPipeLine

他有兩個 閥門屬性:

  1. basic -- 末位閥門

  2. first -- 首尾閥門

除此之外, 沒找到任何閥門屬性了. 沒辦法, 只能接著看看閥門

Valve
Valve 裡面定義了兩個方法:

  1. public Valve getNext()

  2. public void setNext(Valve valve)

看到這裡, 總算明白了, 原來閥門本身, 也是一個指標, 指向了下一個閥門的位置. 使用閥門, 可以組成一個單向連結串列.

addValve()
明白了閥門是指標之後, 還需要知道, 增加閥門時的順序, 所以必須看一下 addValve() 方法.

複製程式碼
/**

  • 加入valve時, 會放到basic最近的位子上, 具體分兩種情況:

    1. first為空, 則放在first上 : first -> basic
    1. first不為空, 則放在離basic最近的位子上
  • first -> v1 -> v2 -> basic , 此時要插入 v3, 結果是: first -> v1 -> v2 -> v3 -> basic*/
    @Override
    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 (getState().isAvailable()) {
    if (valve instanceof Lifecycle) {
    try {
    ((Lifecycle) valve).start();
    } catch (LifecycleException e) {
    log.error(sm.getString("standardPipeline.valve.start"), e);
    }
    }
    }

    // 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();
    }
    }

    container.fireContainerEvent(Container.ADD_VALVE_EVENT, valve);
    }
    複製程式碼
    初始狀態下, first 是空的, 所有的閥門, 在新增的時候, 都是緊挨著basic的位置放的.

getFirst()
複製程式碼
/**

  • 拿取優先順序:(有頭拿頭, 沒頭拿尾)

    1. first存在, 則返回first
    1. first不存在, 則返回 basic
  • @return
    */
    @Override
    public Valve getFirst() {
    if (first != null) {
    return first;
    }

    return basic;
    }
    複製程式碼
    在獲取的時候, 當 first 為空時, 直接獲取 basic , 說明此時只有一個閥門

當first 不為空時, 則會拿取 first , 然後需要在 呼叫閥門的時候, 進行傳遞.

StandardEngineValve
複製程式碼
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;
}
if (request.isAsyncSupported()) {
    request.setAsyncSupported(host.getPipeline().isAsyncSupported());
}

// Ask this Host to process this request
//呼叫 StandardHostValve#invoke() 方法
host.getPipeline()   //-->StandardPipeline
        .getFirst()  //--> AccessLogValve --> ErrorReportValve --> StandardHostValve
        .invoke(request, response);

}
複製程式碼
StandardEngineValve 作為管道的 basic(末位) , 肩負著呼叫子節點的管道方法. 這裡啟動了 StandardHostValve
https://www.douban.com/group/topic/190623665/
https://movie.douban.com/group/topic/190623665/
https://movie.douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?type=followers
https://www.douban.com/group/topic/190623665/comments
https://www.douban.com/group/topic/190623665
https://douban.com/group/topic/190623665/
https://douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?sort=time
https://m.douban.com/group/topic/190623665/
https://m.douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?collect=yes&ck=None
https://www.douban.com/group/topic/190623665/comments/
http://www.douban.com/group/topic/190623665/
http://www.douban.com/group/topic/190623665
http://m.douban.com/group/topic/190623665/
http://m.douban.com/group/topic/190623665
http://www.douban.com/group/topic/190623665/?collect=yes&ck=None
http://www.douban.com/group/topic/190623665/?type=followers
http://www.douban.com/group/topic/190623665/?sort=time
http://movie.douban.com/group/topic/190623665/
http://movie.douban.com/group/topic/190623665
http://www.douban.com/group/topic/190623665/comments/
http://www.douban.com/group/topic/190623665/comments
http://douban.com/group/topic/190623665/
http://book.douban.com/group/topic/190623665/
http://book.douban.com/group/topic/190623665
http://music.douban.com/group/topic/190623665/
http://music.douban.com/group/topic/190623665
https://book.douban.com/group/topic/190623665/
https://book.douban.com/group/topic/190623665
https://music.douban.com/group/topic/190623665/
https://music.douban.com/group/topic/190623665

https://www.douban.com/group/topic/190623665/
https://movie.douban.com/group/topic/190623665/
https://movie.douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?type=followers
https://www.douban.com/group/topic/190623665/comments
https://www.douban.com/group/topic/190623665
https://douban.com/group/topic/190623665/
https://douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?sort=time
https://m.douban.com/group/topic/190623665/
https://m.douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?collect=yes&ck=None
https://www.douban.com/group/topic/190623665/comments/
http://www.douban.com/group/topic/190623665/
http://www.douban.com/group/topic/190623665
http://m.douban.com/group/topic/190623665/
http://m.douban.com/group/topic/190623665
http://www.douban.com/group/topic/190623665/?collect=yes&ck=None
http://www.douban.com/group/topic/190623665/?type=followers
http://www.douban.com/group/topic/190623665/?sort=time
http://movie.douban.com/group/topic/190623665/
http://movie.douban.com/group/topic/190623665
http://www.douban.com/group/topic/190623665/comments/
http://www.douban.com/group/topic/190623665/comments
http://douban.com/group/topic/190623665/
http://book.douban.com/group/topic/190623665/
http://book.douban.com/group/topic/190623665
http://music.douban.com/group/topic/190623665/
http://music.douban.com/group/topic/190623665
https://book.douban.com/group/topic/190623665/
https://book.douban.com/group/topic/190623665
https://music.douban.com/group/topic/190623665/
https://music.douban.com/group/topic/190623665

https://www.douban.com/group/topic/190623665/
https://movie.douban.com/group/topic/190623665/
https://movie.douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?type=followers
https://www.douban.com/group/topic/190623665/comments
https://www.douban.com/group/topic/190623665
https://douban.com/group/topic/190623665/
https://douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?sort=time
https://m.douban.com/group/topic/190623665/
https://m.douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?collect=yes&ck=None
https://www.douban.com/group/topic/190623665/comments/
http://www.douban.com/group/topic/190623665/
http://www.douban.com/group/topic/190623665
http://m.douban.com/group/topic/190623665/
http://m.douban.com/group/topic/190623665
http://www.douban.com/group/topic/190623665/?collect=yes&ck=None
http://www.douban.com/group/topic/190623665/?type=followers
http://www.douban.com/group/topic/190623665/?sort=time
http://movie.douban.com/group/topic/190623665/
http://movie.douban.com/group/topic/190623665
http://www.douban.com/group/topic/190623665/comments/
http://www.douban.com/group/topic/190623665/comments
http://douban.com/group/topic/190623665/
http://book.douban.com/group/topic/190623665/
http://book.douban.com/group/topic/190623665
http://music.douban.com/group/topic/190623665/
http://music.douban.com/group/topic/190623665
https://book.douban.com/group/topic/190623665/
https://book.douban.com/group/topic/190623665
https://music.douban.com/group/topic/190623665/
https://music.douban.com/group/topic/190623665

https://www.douban.com/group/topic/190623665/
https://movie.douban.com/group/topic/190623665/
https://movie.douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?type=followers
https://www.douban.com/group/topic/190623665/comments
https://www.douban.com/group/topic/190623665
https://douban.com/group/topic/190623665/
https://douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?sort=time
https://m.douban.com/group/topic/190623665/
https://m.douban.com/group/topic/190623665
https://www.douban.com/group/topic/190623665/?collect=yes&ck=None
https://www.douban.com/group/topic/190623665/comments/
http://www.douban.com/group/topic/190623665/
http://www.douban.com/group/topic/190623665
http://m.douban.com/group/topic/190623665/
http://m.douban.com/group/topic/190623665
http://www.douban.com/group/topic/190623665/?collect=yes&ck=None
http://www.douban.com/group/topic/190623665/?type=followers
http://www.douban.com/group/topic/190623665/?sort=time
http://movie.douban.com/group/topic/190623665/
http://movie.douban.com/group/topic/190623665
http://www.douban.com/group/topic/190623665/comments/
http://www.douban.com/group/topic/190623665/comments
http://douban.com/group/topic/190623665/
http://book.douban.com/group/topic/190623665/
http://book.douban.com/group/topic/190623665
http://music.douban.com/group/topic/190623665/
http://music.douban.com/group/topic/190623665
https://book.douban.com/group/topic/190623665/
https://book.douban.com/group/topic/190623665
https://music.douban.com/group/topic/190623665/
https://music.douban.com/group/topic/190623665

AccessLogValve