pipeline的執行順序

陈鸿圳發表於2024-05-27

假設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()】

相關文章