This section describes Netty components

Pipeline

In Netty, a Channel corresponds to a Pipeline, and all the processing logic for this Channel is performed in the Pipeline. The Pipeline is a two-way list, and each node is a ChannelHandlerContext object. This object gets all the context information associated with a Channel, and this object wraps one important object, the logical handler ChannelHandler. A Pipeline can be represented as the following structure for code to discard a service:

Our own DiscardServerHandler will be sandwiched between Netty’s existing ChannelHandlerContext objects to create the above bidirectional list structure.

We continue to see next to abandon the service code comments (3), our own handler inherited a ChannelInboundHandlerAdapter, we also introduce the Inbound is a what concept here.

In Pipeline, event propagation is divided into two types: Inbound event and Outbound event. Let’s take a screenshot of Netty source code to better understand it.

Can be seen from the chart on the left side of the content, the Inbound event triggered by a Socket read event, and from the bottom of the Inbound Handler1 by calling ChannelHandlerContext. FireIN_EVT () up to deal with them one by one. Outbound, on the other hand, is from top to bottom. The idea is to break down what needs to be done into different stages, each of which is handled by a separate unit.