jetty分析

路径:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值