源码


栗子
ch.pipeline().addLast(new InboundHandler1());
ch.pipeline().addLast(new InboundHandler2());
ch.pipeline().addLast(new OutboundHandler1());
ch.pipeline().addLast(new OutboundHandler2());
链表中的顺序为head->in1->in2->out1->out2->tail
输出:
InboundHandler1
InboundHandler2
OutboundHandler2
OutboundHandler1
一次请求过来,先read,再write,根据顺序
read : in1 in2
write: out2 out1
所以最后的顺序就是 in1 in2 out 2 out1


拾遗
由head开始的往下传播的事件
fireChannelActive
fireChannelInactive
fireExceptionCaught
fireChannelRead
fireChannelReadComplete
…等等
由tail开始的往上传播的事件
bind
connect
write
flush
…等等
InboundHandler关心的事件:
MASK_EXCEPTION_CAUGHT
MASK_CHANNEL_REGISTERED
MASK_CHANNEL_ACTIVE
MASK_CHANNEL_READ
MASK_CHANNEL_READ_COMPLETE
…等等
OutboundHanlder关心的事件:
MASK_EXCEPTION_CAUGHT
MASK_BIND
MASK_CLOSE
MASK_READ
MASK_WRITE
MASK_FLUSH
…等等
参考:
https://blog.youkuaiyun.com/zhengchao1991/article/details/103583766
https://blog.youkuaiyun.com/qq_41737716/article/details/94734196
https://blog.youkuaiyun.com/zhengchao1991/article/details/103583766
本文探讨了Netty中事件的传播过程,从源码层面分析了读写事件的顺序,如read事件触发in1、in2,write事件触发out2、out1。同时,详细列举了由head和tail开始传播的事件,分别涉及InboundHandler和OutboundHandler关心的不同事件类型。通过参考多个优快云博客,深入理解Netty的内在机制。
2902

被折叠的 条评论
为什么被折叠?



