路径:
jetty-http、jetty-io、jetty-client、jetty-server
文档:
http://www.eclipse.org/jetty/documentation/9.4.7.v20170914/
https://yq.aliyun.com/articles/46916
1. jetty-http: http接口化模型定义&序列化(解析、构造)
2. jetty-io: 处理网络连接
两条线:连接的建立过程、读写处理过程
- 连接的建立过程
AbstractConnector.Acceptor.run->ServerConnector.accept->ServerConnector.accepted->SelectorManager.accept->ManagedSelector.
submit->ManagedSelector._actions(ManagedSelector.Accept)
ManagedSelector.Accept.run ->ManagedSelector._actions(CreateEndPoint)
- 读写处理过程
- selectorManager
任务提交到 managerdSelector,managerdSelector中的_strategy会被执行,执行连接任务,各个action
3. client:
HttpClient.send(HttpRequest)
-> HttpDestination.send(HttpRequest,ResponseListener)
-> HttpDestination.exchanges
HttpDestination.process(connection)
->HttpDestinationOverHTTP.send(Connection, HttpExchange)
->HttpConnectionOverHTTP.send(HttpExchange)
HttpConnectionOverHTTP.send(HttpExchange)
->HttpConnectionOverHTTP.Delegate.send(HttpExchange)->HttpConnection.send(HttpChannel , HttpExchange )
->HttpChannelOverHTTP.associate(HttpExchange)
->HttpChannelOverHTTP.send()
HttpChannelOverHTTP.send(HttpExchange)
->HttpSender.send(HttpExchange)->HttpSender.sendHeaders(exchange, content, CommitCallback)
->HttpSenderOverHTTP.sendHeaders(exchange, content, CommitCallback)->HeadersCallback(exchange, content, callback).iterate()
??HttpGenerator.generateRequest ,EndPoint.write()
sender 状态机 !!!
IteratingCallback 机制!!! 有意识的思路
HttpGenerator机制!!
EndPoint机制!!
sender 状态机 !!!
IteratingCallback 机制!!!
连接池管理:
version 8.1.x
使用Timeout实现超时管理逻辑,ConnectionIdleTask实现连接超时处理逻辑,HttpClient._threadPool完成调度执行。
_connections、_reservedConnections、_idleConnections 三个的关系
连接的管理,隐含在各个操作中:
getConnection,doSend,onConnectionFailed,returnConnection,returnIdleConnection会处理新建连接的操作;
onNewConnection,returnConnection 操作,发现没有缓存的exchange会将连接添加到idle池;
ConnectionIdleTask.expired,send(AbstractHttpConnection, HttpExchange) 会处理idel超时的连接
onNewConnection,returnConnection,doSend 会真正调用connection对象发送exchange;
??? 会返回连接
HttpClient:客户端接口,对客户提供功能
HttpDestination:管理到站点的连接
Connection:到站点的连接
Co