Skip to content

Netty pipeline architecture

The Netty pipeline architecture is a core component of framework's design that manages the flow of I/O events and data processing within a [[Channel]]. It is implemented as a list of ChannelHandler objects, organized within a ChannelPipeline, where each handler processes specific events or transforms data as it passes through the chain^[600-developer-big-data-netty-netty-02.md].

Structure

The pipeline consists of a linked list of ChannelHandlerContext objects^[600-developer-big-data-netty-netty-02.md]. These contexts wrap the user-defined ChannelHandler instances and contain the necessary context to propagate events upstream or downstream. The architecture typically begins with a "head" context and ends with a "tail" context^[600-developer-big-data-netty-netty-02.md].

ChannelHandlerContext

Each ChannelHandlerContext serves as the binding element between the ChannelPipeline and the ChannelHandler^[600-developer-big-data-netty-netty-02.md]. It holds references to:

  • The Channel: The network component associated with the pipeline.
  • The Handler: The specific logic processor attached to this context.
  • The EventExecutor: Often a NioEventLoop, responsible for executing the handler's logic^[600-developer-big-data-netty-netty-02.md].

The context facilitates the "fire" methods (e.g., fireChannelRegistered) that propagate events to the next handler in the chain^[600-developer-big-data-netty-netty-02.md].

Lifecycle

During channel initialization, the pipeline is automatically created and associated with the channel^[600-developer-big-data-netty-netty-02.md]. As the channel transitions through states—such as registration and binding—the pipeline triggers specific lifecycle events:

  • Initialization: Handlers can be added during the bootstrap process (e.g., ServerBootstrapAcceptor is added in the init method)^[600-developer-big-data-netty-netty-02.md].
  • Registration: When register0 completes, the pipeline invokes fireChannelRegistered to notify handlers of the successful registration^[600-developer-big-data-netty-netty-02.md].
  • Activation: Upon successful binding via doBind, the pipeline triggers fireChannelActive^[600-developer-big-data-netty-netty-02.md].

Sources

^[600-developer-big-data-netty-netty-02.md]