摘要:實(shí)現(xiàn)為,即模式上一個(gè)依賴于下一個(gè)的調(diào)用,比如常見的就是這種模式。啟動(dòng)實(shí)例化和設(shè)置運(yùn)行時(shí)處理流程通常會(huì)實(shí)例化一個(gè),注意的構(gòu)造方法最終會(huì)調(diào)用依次將構(gòu)成責(zé)任鏈因?yàn)檫@個(gè)連同都是類型。內(nèi)部所有等執(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實(shí)現(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依賴定義的順序,而上一個(gè)handler不依賴于下一個(gè)handler的調(diào)用。實(shí)現(xiàn)為org.eclipse.jetty.server.handler.HandlerCollection
Nested handlers,即 before/invokeNext/after 模式(上一個(gè)handler依賴于下一個(gè)handler的調(diào)用),比如常見的FilterChain就是這種模式。實(shí)現(xiàn)為org.eclipse.jetty.server.handler.HandlerWrapper
ServletHandler、ServletContextHandler最基層的handler,常見的就是spring的DispacherServlet + 一些Filter。ServletHandler會(huì)被 ServletContextHandler 所持有。ServletContextHandler與ServletHandler是一對(duì)一的,邏輯上就是 web application context ,即SessionHandler、SecurityHandler、ServletHandler、GzipHandler的組合,常見的就是web.xml。
Server啟動(dòng)new Server(int port) -> 實(shí)例化QueuedThreadPool和ServerConnector
Server#setHandler 設(shè)置運(yùn)行時(shí)處理流程:
通常會(huì)實(shí)例化一個(gè)ServletContextHandler,注意ServletContextHandler的構(gòu)造方法最終會(huì)調(diào)用ServletContextHandler#relinkHandlers
依次將SessionHandler、SecurityHandler、GzipHandler、ServletHandler構(gòu)成責(zé)任鏈(因?yàn)檫@4個(gè)handler連同ServletContextHandler都是HandlerWrapper
類型)。
Server#start即AbstractLifeCycle#start -> Server#doStart。以下步驟是Server#doStart
設(shè)置ErrorHandler
ShutdownThread通過Runtime.getRuntime().addShutdownHook(Thread)使得jvm關(guān)閉時(shí)會(huì)喚起ShutdownThread來stop Server
啟動(dòng)ShutdownMonitor來監(jiān)聽遠(yuǎn)端stop指令,可以設(shè)置STOP.HOST、STOP.PORT、STOP.KEY來啟用。
內(nèi)部所有connector(ServerConnector等)執(zhí)行Connector#start 即AbstractLifeCycle#start。
AbstractNetworkConnector#doStart -> ServerConnector#open -> ServerConnector#openAcceptChannel 即綁定host、port到ServerSocket
Server運(yùn)行時(shí)由于Server繼承HandlerWrapper,運(yùn)行時(shí)由其內(nèi)部托管的handler實(shí)現(xiàn)(比如ServletContextHandler)。
HttpChannel#handle -> Server#handle(target, request, request, response)即HandlerWrapper的handle方法
注意:Server、ServletContextHandler、SessionHandler、SecurityHandler、GzipHandler、ServletHandler都是HandlerWrapper,即都在一條責(zé)任鏈上。
注意:ServletContextHandler、SessionHandler、ServletHandler繼承ScopedHandler,即調(diào)用鏈上是 ScopedHandler#handle(target, request, request, response) -> ScopedHandler#doScope入?yún)⒙?-> ScopedHandler#doHandle
所以最后請(qǐng)求request會(huì)傳遞到ServletHandler,通常會(huì)設(shè)置spring的DispatcherServlet作為ServletHandler的Servlet。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/70992.html
摘要:學(xué)習(xí)路線編程基礎(chǔ)語言語言基礎(chǔ)數(shù)據(jù)類型面向?qū)ο蠼涌谌萜鳟惓7盒头瓷渥⒔饬骷项惣虞d機(jī)制字節(jié)碼執(zhí)行機(jī)制 Java學(xué)習(xí)路線 Java編程基礎(chǔ) Java語言 Java語言基...
摘要:這里我想從我在谷歌內(nèi)部使用容器,并基于容器研發(fā)大規(guī)模生產(chǎn)平臺(tái)的經(jīng)驗(yàn)中談?wù)劕F(xiàn)有和谷歌容器環(huán)境的差別,并通過的實(shí)際案例落地經(jīng)驗(yàn)總結(jié)下自身所帶來的一些謊言和誤區(qū)。 我與容器的緣分起源于我在 Google 內(nèi)部研發(fā)容器集群管理系: Cluster Management。谷歌內(nèi)部一切皆容器,搜索、視頻、大數(shù)據(jù)、內(nèi)部工具等核心業(yè)務(wù)都以容器的方式運(yùn)行在容器編排系統(tǒng) Borg 上。2014年,隨著公司...
摘要:作為微服務(wù)的基礎(chǔ)設(shè)施之一,背靠強(qiáng)大的生態(tài)社區(qū),支撐技術(shù)體系。微服務(wù)實(shí)踐為系列講座,專題直播節(jié),時(shí)長高達(dá)小時(shí),包括目前最流行技術(shù),深入源碼分析,授人以漁的方式,幫助初學(xué)者深入淺出地掌握,為高階從業(yè)人員拋磚引玉。 簡介 目前業(yè)界最流行的微服務(wù)架構(gòu)正在或者已被各種規(guī)模的互聯(lián)網(wǎng)公司廣泛接受和認(rèn)可,業(yè)已成為互聯(lián)網(wǎng)開發(fā)人員必備技術(shù)。無論是互聯(lián)網(wǎng)、云計(jì)算還是大數(shù)據(jù),Java平臺(tái)已成為全棧的生態(tài)體系,...
閱讀 2982·2023-04-25 19:08
閱讀 1455·2021-11-16 11:45
閱讀 2026·2021-10-13 09:40
閱讀 4206·2021-09-30 09:47
閱讀 2462·2019-08-30 15:44
閱讀 2355·2019-08-30 13:03
閱讀 1415·2019-08-30 12:56
閱讀 1921·2019-08-26 14:04