亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

分布式 - Jetty架構

libin19890520 / 2146人閱讀

摘要:實現(xiàn)為,即模式上一個依賴于下一個的調用,比如常見的就是這種模式。啟動實例化和設置運行時處理流程通常會實例化一個,注意的構造方法最終會調用依次將構成責任鏈因為這個連同都是類型。內部所有等執(zhí)行即。

Connectors

For each accepted TCP connection, the Connector asks a ConnectionFactory to create a Connection object that handles the network traffic on that TCP connection, parsing and generating bytes for a specific protocol.

比如:a ServerConnector configured with three factories: ProxyConnectionFactory, SslConnectionFactory and HttpConnectionFactory. Such connector will be able to handle PROXY protocol bytes coming from a load balancer such as HAProxy (with the ProxyConnectionFactory), then handle TLS bytes (with SslConnectionFactory) and therefore decrypting/encrypting the bytes from/to a remote client, and finally handling HTTP/1.1 bytes (with HttpConnectionFactory).

可以自己自定義ConnectionFactory實現(xiàn)來處理自定義的協(xié)議。

Handlers
// org.eclipse.jetty.server.Handler的方法:
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException;

Handlers有兩種模型:

Sequential handlers,即handlers依賴定義的順序,而上一個handler不依賴于下一個handler的調用。實現(xiàn)為org.eclipse.jetty.server.handler.HandlerCollection

Nested handlers,即 before/invokeNext/after 模式(上一個handler依賴于下一個handler的調用),比如常見的FilterChain就是這種模式。實現(xiàn)為org.eclipse.jetty.server.handler.HandlerWrapper

ServletHandler、ServletContextHandler

最基層的handler,常見的就是spring的DispacherServlet + 一些Filter。ServletHandler會被 ServletContextHandler 所持有。ServletContextHandler與ServletHandler是一對一的,邏輯上就是 web application context ,即SessionHandler、SecurityHandler、ServletHandler、GzipHandler的組合,常見的就是web.xml。

Server啟動

new Server(int port) -> 實例化QueuedThreadPool和ServerConnector

Server#setHandler 設置運行時處理流程:
通常會實例化一個ServletContextHandler,注意ServletContextHandler的構造方法最終會調用ServletContextHandler#relinkHandlers
依次將SessionHandler、SecurityHandler、GzipHandler、ServletHandler構成責任鏈(因為這4個handler連同ServletContextHandler都是HandlerWrapper
類型)。

Server#start即AbstractLifeCycle#start -> Server#doStart。以下步驟是Server#doStart

設置ErrorHandler

ShutdownThread通過Runtime.getRuntime().addShutdownHook(Thread)使得jvm關閉時會喚起ShutdownThread來stop Server

啟動ShutdownMonitor來監(jiān)聽遠端stop指令,可以設置STOP.HOST、STOP.PORT、STOP.KEY來啟用。

內部所有connector(ServerConnector等)執(zhí)行Connector#start 即AbstractLifeCycle#start。

AbstractNetworkConnector#doStart -> ServerConnector#open -> ServerConnector#openAcceptChannel 即綁定host、port到ServerSocket

Server運行時

由于Server繼承HandlerWrapper,運行時由其內部托管的handler實現(xiàn)(比如ServletContextHandler)。

HttpChannel#handle -> Server#handle(target, request, request, response)即HandlerWrapper的handle方法

注意:Server、ServletContextHandler、SessionHandler、SecurityHandler、GzipHandler、ServletHandler都是HandlerWrapper,即都在一條責任鏈上。
注意:ServletContextHandler、SessionHandler、ServletHandler繼承ScopedHandler,即調用鏈上是 ScopedHandler#handle(target, request, request, response) -> ScopedHandler#doScope入?yún)⒙?-> ScopedHandler#doHandle

所以最后請求request會傳遞到ServletHandler,通常會設置spring的DispatcherServlet作為ServletHandler的Servlet。

文章版權歸作者所有,未經(jīng)允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉載請注明本文地址:http://www.ezyhdfw.cn/yun/70992.html

相關文章

  • Java學習路線

    摘要:學習路線編程基礎語言語言基礎數(shù)據(jù)類型面向對象接口容器異常泛型反射注解流集合類加載機制字節(jié)碼執(zhí)行機制 Java學習路線 Java編程基礎 Java語言 Java語言基...

    不知名網(wǎng)友 評論0 收藏0
  • Docker和容器云落地一年后的反思

    摘要:這里我想從我在谷歌內部使用容器,并基于容器研發(fā)大規(guī)模生產(chǎn)平臺的經(jīng)驗中談談現(xiàn)有和谷歌容器環(huán)境的差別,并通過的實際案例落地經(jīng)驗總結下自身所帶來的一些謊言和誤區(qū)。 我與容器的緣分起源于我在 Google 內部研發(fā)容器集群管理系: Cluster Management。谷歌內部一切皆容器,搜索、視頻、大數(shù)據(jù)、內部工具等核心業(yè)務都以容器的方式運行在容器編排系統(tǒng) Borg 上。2014年,隨著公司...

    _ang 評論0 收藏0
  • [直播視頻] 《Java 微服務實踐 - Spring Boot 系列》限時折扣

    摘要:作為微服務的基礎設施之一,背靠強大的生態(tài)社區(qū),支撐技術體系。微服務實踐為系列講座,專題直播節(jié),時長高達小時,包括目前最流行技術,深入源碼分析,授人以漁的方式,幫助初學者深入淺出地掌握,為高階從業(yè)人員拋磚引玉。 簡介 目前業(yè)界最流行的微服務架構正在或者已被各種規(guī)模的互聯(lián)網(wǎng)公司廣泛接受和認可,業(yè)已成為互聯(lián)網(wǎng)開發(fā)人員必備技術。無論是互聯(lián)網(wǎng)、云計算還是大數(shù)據(jù),Java平臺已成為全棧的生態(tài)體系,...

    Enlightenment 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<