假设pipeline里面有这样的handler顺序
OutBoundHandler1
InBoundHandler1
OutBoundHandler2
InBoundHandler2
- 当在【InBoundHandler1】里面执行【ctx.write()】时
- 向上执行触发【OutBoundHandler1.write()】方法
- 由于【OutBoundHandler2】在【InBoundHandler1】的下面,所以【OutBoundHandler1.write()】不会执行
- 当在【InBoundHandler1】里面执行【ctx.fireChannelRead()】时
- 先执行【in】再执行【out】,所以【InBoundHandler2.channelRead0()】会比【OutBoundHandler1、OutBoundHandler2】的【read()】先执行
- 向下执行,所以【InBoundHandler2.channelRead0()】会被触发。
- 执行完【in】之后,开始执行【out】,【OutBoundHandler2】在【OutBoundHandler1】的下面,所以【OutBoundHandler2.read()】先执行
- 最后执行【OutBoundHandler1.read()】
- 当在【InBoundHandler2】里面执行【ctx.fireChannelRead()】时
- 由于【InBoundHandler1】在【InBoundHandler2】的前面,所以不执行
- 执行【OutBoundHandler2.read()】
- 再执行【OutBoundHandler1.read()】