• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
DragonJ's PAD
阿蛟
博客园    首页    新随笔    联系   管理    订阅  订阅

HttpCore NIO 研究随笔 1

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";

} 

posted @ 2011-09-22 00:05  啊蛟  阅读(2148)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3