ConnectingIOReactor一般是每个核心建立一个线程维护
作用是这个线程监听JAVA底层到NIO状态变化。然后会分发各个事件。
对IOEventDispatch就是其分发实现到入口。ioReactor会通过调用IOEventDispatch完成NIO事件到通知工作。
而 IOEventDispatch其实也是一个对先发通知到执行入口。
而出发IOEventDispatch动作的是AbstractMultiworkerIOReactor 其通过 AbstractIOReactor的实现BaseIOReactor达到把
JAVA NIO的Selector做的。一层一层到通知到上面的。
在AbstractMultiworkerIOReactor 中的workcount就是创建几个线程去监听Selector,AbstractMultiworkerIOReactor会创建相应个数到线程执行监听工作。
在说说 IOEventDispatch下面到这些类。当eventDispatch拿到了通知再通过NHttpClientHandler和在IOSession上下文中拿到的Conn去对Conn做一些自己想要到处理。
而NHttpClientHandler的默认实现AsyncNHttpClientHandler中的NHttpRequestExecutionHandler是为了隔离Connection与Request的关系。
通过 NHttpRequestExecutionHandler做最终执行但是在Request中是没有Connection的。不用考虑Connection只要考虑当前请求到上下文HttpContext。
达到业务到隔离。
针对通道到上下文是有Conn到信息的。
session.getAttribute(IOSession.ATTACHMENT_KEY);
session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
生成Http的上下文是有通道信息IOSession的So,可以从上下文中取出很多信息。
class SessionHttpContext implements HttpContext {
private final IOSession iosession;
还有就是在默认实现中到部分信息也是用的。
public interface ExecutionContext {
/**
* Attribute name of a {@link com.apache.http.HttpConnection} object that
* represents the actual HTTP connection.
*/
public static final String HTTP_CONNECTION = "http.connection";
/**
* Attribute name of a {@link com.apache.http.HttpRequest} object that
* represents the actual HTTP request.
*/
public static final String HTTP_REQUEST = "http.request";
/**
* Attribute name of a {@link com.apache.http.HttpResponse} object that
* represents the actual HTTP response.
*/
public static final String HTTP_RESPONSE = "http.response";
/**
* Attribute name of a {@link com.apache.http.HttpHost} object that
* represents the connection target.
*/
public static final String HTTP_TARGET_HOST = "http.target_host";
/**
* Attribute name of a {@link com.apache.http.HttpHost} object that
* represents the connection proxy.
*/
public static final String HTTP_PROXY_HOST = "http.proxy_host";
/**
* Attribute name of a {@link Boolean} object that represents the
* the flag indicating whether the actual request has been fully transmitted
* to the target host.
*/
public static final String HTTP_REQ_SENT = "http.request_sent";
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端