InBound Netty analysis of propagation, outBound, abnormal events in the pipeline

inBound event

  When an IO event occurs, such as link establishment, Link Shutdown, read operation is completed (register, read, active) , will have an event, the event pipeline propagation and processing. pipeline to fireXXX methods are named, their implementation varies depending on the feature from IO thread to inBound Event Handler business users, but similar processing steps. as follows:

(1) corresponding to the call fireXXX HeadHandler method.

(2) perform logical operations related to the event.

  When calling ChannelHandlerContext.fireXXX (fireChannelRead ()) method, the event will be spread down from the current node is to find the next ChannelInBoundHandler, then call channelXXX method ChannelInBoundHandler, if not covered channelXXX method, the default will be in the news Pipeline propagates from start to finish, and finally calls the method channelXXX tail node, if the message has been invoked method to channelXXX tail node foregoing description channelHandler not process the message, such message until the tail node, the end node needs certain release, prevent memory leaks.

  SimpleChannelInBoundHandler of channelRead0 method will help automatically release ByteBuf , it channelRead method calls channelRead0 () and release ByteBuf.

outBound event

   Initiated by the user or the code thread IO operation is called outBound event. The order of addition and spread ChannelOutBoundHandler sequence of events is reversed. The outBound event is looking for the next ChannelOutBoundHandler, method calls the handler will eventually spread from Head to Tail node node.

  Summary: When each pipeline propagation method used to call, the node or a tail node from the head begins to spread, and the use ChannelHandlerContext is propagated from the beginning of the current node.

Exception Propagation

  Does not distinguish between abnormal propagation is inBoundHandler or outBoundHandler , exceptions are spread on top. Exception handler and sequence spread sequence is correlated added (same). Abnormal communication is directly next to get a current node by default, will eventually spread to exceptionCaught Tail node (), Tail node will eventually print this exception, the exception notification has not been processed. If we say that we need to do a deal with an exception, it is best to add an exception handler in the last pipeline, ultimately to be a unified abnormal processing.

Guess you like

Origin www.cnblogs.com/xiaobaituyun/p/10991219.html