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 aNioEventLoop, 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.,
ServerBootstrapAcceptoris added in theinitmethod)^[600-developer-big-data-netty-netty-02.md]. - Registration: When
register0completes, the pipeline invokesfireChannelRegisteredto notify handlers of the successful registration^[600-developer-big-data-netty-netty-02.md]. - Activation: Upon successful binding via
doBind, the pipeline triggersfireChannelActive^[600-developer-big-data-netty-netty-02.md].
Related Concepts¶
- NioServerSocketChannel
- [[NioEventLoop]]
Sources¶
^[600-developer-big-data-netty-netty-02.md]