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

转载于:https://www.cnblogs.com/DragonJ/archive/2011/09/22/2184594.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值