Top Description Methods
io.netty.channel

public Interface ChannelPipeline

extends ChannelInboundInvoker, ChannelOutboundInvoker, Iterable<Map.Entry<String, ChannelHandler>>
Known Direct Implementers
io.netty.channel.DefaultChannelPipeline
Imports
io.netty.buffer.ByteBuf, io.netty.util.concurrent.DefaultEventExecutorGroup, .EventExecutorGroup, .UnorderedThreadPoolEventExecutor, java.net.SocketAddress, java.nio.ByteBuffer, java.nio.channels.SocketChannel, java.util.List, .Map, .Map.Entry, .NoSuchElementException

A list of ChannelHandlers which handles or intercepts inbound events and outbound operations of a Channel. ChannelPipeline implements an advanced form of the Intercepting Filter pattern to give a user full control over how an event is handled and how the ChannelHandlers in a pipeline interact with each other.

Creation of a pipeline

Each channel has its own pipeline and it is created automatically when a new channel is created.

How an event flows in a pipeline

The following diagram describes how I/O events are processed by ChannelHandlers in a ChannelPipeline typically. An I/O event is handled by either a ChannelInboundHandler or a ChannelOutboundHandler and be forwarded to its closest handler by calling the event propagation methods defined in ChannelHandlerContext, such as ChannelHandlerContext#fireChannelRead(Object) and ChannelHandlerContext#write(Object).
                                                I/O Request
                                           via Channel or
                                       ChannelHandlerContext
                                                     |
 +---------------------------------------------------+---------------+
 |                           ChannelPipeline         |               |
 |                                                  \|/              |
 |    +---------------------+            +-----------+----------+    |
 |    | Inbound Handler  N  |            | Outbound Handler  1  |    |
 |    +----------+----------+            +-----------+----------+    |
 |              /|\                                  |               |
 |               |                                  \|/              |
 |    +----------+----------+            +-----------+----------+    |
 |    | Inbound Handler N-1 |            | Outbound Handler  2  |    |
 |    +----------+----------+            +-----------+----------+    |
 |              /|\                                  .               |
 |               .                                   .               |
 | ChannelHandlerContext.fireIN_EVT() ChannelHandlerContext.OUT_EVT()|
 |        [ method call]                       [method call]         |
 |               .                                   .               |
 |               .                                  \|/              |
 |    +----------+----------+            +-----------+----------+    |
 |    | Inbound Handler  2  |            | Outbound Handler M-1 |    |
 |    +----------+----------+            +-----------+----------+    |
 |              /|\                                  |               |
 |               |                                  \|/              |
 |    +----------+----------+            +-----------+----------+    |
 |    | Inbound Handler  1  |            | Outbound Handler  M  |    |
 |    +----------+----------+            +-----------+----------+    |
 |              /|\                                  |               |
 +---------------+-----------------------------------+---------------+
                 |                                  \|/
 +---------------+-----------------------------------+---------------+
 |               |                                   |               |
 |       [ Socket.read() ]                    [ Socket.write() ]     |
 |                                                                   |
 |  Netty Internal I/O Threads (Transport Implementation)            |
 +-------------------------------------------------------------------+
An inbound event is handled by the inbound handlers in the bottom-up direction as shown on the left side of the diagram. An inbound handler usually handles the inbound data generated by the I/O thread on the bottom of the diagram. The inbound data is often read from a remote peer via the actual input operation such as SocketChannel#read(ByteBuffer). If an inbound event goes beyond the top inbound handler, it is discarded silently, or logged if it needs your attention.

An outbound event is handled by the outbound handler in the top-down direction as shown on the right side of the diagram. An outbound handler usually generates or transforms the outbound traffic such as write requests. If an outbound event goes beyond the bottom outbound handler, it is handled by an I/O thread associated with the Channel. The I/O thread often performs the actual output operation such as SocketChannel#write(ByteBuffer).

For example, let us assume that we created the following pipeline:

ChannelPipeline p = ...;
p.addLast("1", new InboundHandlerA());
p.addLast("2", new InboundHandlerB());
p.addLast("3", new OutboundHandlerA());
p.addLast("4", new OutboundHandlerB());
p.addLast("5", new InboundOutboundHandlerX());
In the example above, the class whose name starts with Inbound means it is an inbound handler. The class whose name starts with Outbound means it is a outbound handler.

In the given example configuration, the handler evaluation order is 1, 2, 3, 4, 5 when an event goes inbound. When an event goes outbound, the order is 5, 4, 3, 2, 1. On top of this principle, ChannelPipeline skips the evaluation of certain handlers to shorten the stack depth:

Forwarding an event to the next handler

As you might noticed in the diagram shows, a handler has to invoke the event propagation methods in ChannelHandlerContext to forward an event to its next handler. Those methods include: and the following example shows how the event propagation is usually done:
public class MyInboundHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        System.out.println("Connected!");
        ctx.fireChannelActive();
    }
}

public class MyOutboundHandler extends ChannelOutboundHandlerAdapter {
    @Override
    public void close(ChannelHandlerContext ctx, ChannelPromise promise) {
        System.out.println("Closing ..");
        ctx.close(promise);
    }
}

Building a pipeline

A user is supposed to have one or more ChannelHandlers in a pipeline to receive I/O events (e.g. read) and to request I/O operations (e.g. write and close). For example, a typical server will have the following handlers in each channel's pipeline, but your mileage may vary depending on the complexity and characteristics of the protocol and business logic:

  1. Protocol Decoder - translates binary data (e.g. ByteBuf) into a Java object.
  2. Protocol Encoder - translates a Java object into binary data.
  3. Business Logic Handler - performs the actual business logic (e.g. database access).
and it could be represented as shown in the following example:
static final EventExecutorGroup group = new DefaultEventExecutorGroup(16);
...

ChannelPipeline pipeline = ch.pipeline();

pipeline.addLast("decoder", new MyProtocolDecoder());
pipeline.addLast("encoder", new MyProtocolEncoder());

// Tell the pipeline to run MyBusinessLogicHandler's event handler methods
// in a different thread than an I/O thread so that the I/O thread is not blocked by
// a time-consuming task.
// If your business logic is fully asynchronous or finished very quickly, you don't
// need to specify a group.
pipeline.addLast(group, "handler", new MyBusinessLogicHandler());
Be aware that while using DefaultEventLoopGroup will offload the operation from the EventLoop it will still process tasks in a serial fashion per ChannelHandlerContext and so guarantee ordering. Due the ordering it may still become a bottle-neck. If ordering is not a requirement for your use-case you may want to consider using UnorderedThreadPoolEventExecutor to maximize the parallelism of the task execution.

Thread safety

A ChannelHandler can be added or removed at any time because a ChannelPipeline is thread safe. For example, you can insert an encryption handler when sensitive information is about to be exchanged, and remove it after the exchange.

Method Summary

Modifier and TypeMethod and Description
public ChannelPipeline
addAfter(String
the name of the existing handler
baseName
,
String
the name of the handler to insert after
name
,
ChannelHandler
the handler to insert after
handler
)

Inserts a ChannelHandler after an existing handler of this pipeline.

public ChannelPipeline
addAfter(EventExecutorGroup
the EventExecutorGroup which will be used to execute the ChannelHandler methods
group
,
String
the name of the existing handler
baseName
,
String
the name of the handler to insert after
name
,
ChannelHandler
the handler to insert after
handler
)

Inserts a ChannelHandler after an existing handler of this pipeline.

public ChannelPipeline
addBefore(String
the name of the existing handler
baseName
,
String
the name of the handler to insert before
name
,
ChannelHandler
the handler to insert before
handler
)

Inserts a ChannelHandler before an existing handler of this pipeline.

public ChannelPipeline
addBefore(EventExecutorGroup
the EventExecutorGroup which will be used to execute the ChannelHandler methods
group
,
String
the name of the existing handler
baseName
,
String
the name of the handler to insert before
name
,
ChannelHandler
the handler to insert before
handler
)

Inserts a ChannelHandler before an existing handler of this pipeline.

public ChannelPipeline
addFirst(String
the name of the handler to insert first
name
,
ChannelHandler
the handler to insert first
handler
)

Inserts a ChannelHandler at the first position of this pipeline.

public ChannelPipeline
addFirst(EventExecutorGroup
the EventExecutorGroup which will be used to execute the ChannelHandler methods
group
,
String
the name of the handler to insert first
name
,
ChannelHandler
the handler to insert first
handler
)

Inserts a ChannelHandler at the first position of this pipeline.

public ChannelPipeline
addFirst(ChannelHandler...
the handlers to insert first
handlers
)

Inserts ChannelHandlers at the first position of this pipeline.

public ChannelPipeline
addFirst(EventExecutorGroup
the EventExecutorGroup which will be used to execute the ChannelHandlers methods.
group
,
ChannelHandler...
the handlers to insert first
handlers
)

Inserts ChannelHandlers at the first position of this pipeline.

public ChannelPipeline
addLast(String
the name of the handler to append
name
,
ChannelHandler
the handler to append
handler
)

Appends a ChannelHandler at the last position of this pipeline.

public ChannelPipeline
addLast(EventExecutorGroup
the EventExecutorGroup which will be used to execute the ChannelHandler methods
group
,
String
the name of the handler to append
name
,
ChannelHandler
the handler to append
handler
)

Appends a ChannelHandler at the last position of this pipeline.

public ChannelPipeline
addLast(ChannelHandler...
the handlers to insert last
handlers
)

Inserts ChannelHandlers at the last position of this pipeline.

public ChannelPipeline
addLast(EventExecutorGroup
the EventExecutorGroup which will be used to execute the ChannelHandlers methods.
group
,
ChannelHandler...
the handlers to insert last
handlers
)

Inserts ChannelHandlers at the last position of this pipeline.

public Channel

Returns:

the channel. null if this pipeline is not attached yet.
channel
()

Returns the Channel that this pipeline is attached to.

public ChannelHandlerContext

Returns:

the context object of the specified handler. null if there's no such handler in this pipeline.
context
(ChannelHandler handler)

Returns the context object of the specified ChannelHandler in this pipeline.

public ChannelHandlerContext

Returns:

the context object of the handler with the specified name. null if there's no such handler in this pipeline.
context
(String name)

Returns the context object of the ChannelHandler with the specified name in this pipeline.

public ChannelHandlerContext

Returns:

the context object of the handler of the specified type. null if there's no such handler in this pipeline.
context
(Class<? extends ChannelHandler> handlerType)

Returns the context object of the ChannelHandler of the specified type in this pipeline.

public ChannelPipeline
fireChannelActive()

Redeclares io.netty.channel.ChannelInboundInvoker.fireChannelActive.

A Channel is active now, which means it is connected.
public ChannelPipeline
fireChannelInactive()

Redeclares io.netty.channel.ChannelInboundInvoker.fireChannelInactive.

A Channel is inactive now, which means it is closed.
public ChannelPipeline
public ChannelPipeline
public ChannelPipeline
public ChannelPipeline
public ChannelPipeline
public ChannelPipeline
fireExceptionCaught(Throwable cause)

Redeclares io.netty.channel.ChannelInboundInvoker.fireExceptionCaught.

A Channel received an Throwable in one of its inbound operations.
public ChannelPipeline
public ChannelHandler

Returns:

the first handler. null if this pipeline is empty.
first
()

Returns the first ChannelHandler in this pipeline.

public ChannelHandlerContext

Returns:

the context of the first handler. null if this pipeline is empty.
firstContext
()

Returns the context of the first ChannelHandler in this pipeline.

public ChannelPipeline
flush()

Redeclares io.netty.channel.ChannelOutboundInvoker.flush.

Request to flush all pending messages via this ChannelOutboundInvoker.
public ChannelHandler

Returns:

the handler with the specified name. null if there's no such handler in this pipeline.
get
(String name)

Returns the ChannelHandler with the specified name in this pipeline.

public <T extends ChannelHandler> T

Returns:

the handler of the specified handler type. null if there's no such handler in this pipeline.
get
(Class<T> handlerType)

Returns the ChannelHandler of the specified type in this pipeline.

public ChannelHandler

Returns:

the last handler. null if this pipeline is empty.
last
()

Returns the last ChannelHandler in this pipeline.

public ChannelHandlerContext

Returns:

the context of the last handler. null if this pipeline is empty.
lastContext
()

Returns the context of the last ChannelHandler in this pipeline.

public List<String>
names()

Returns the List of the handler names.

public ChannelPipeline
remove(ChannelHandler
the ChannelHandler to remove
handler
)

Removes the specified ChannelHandler from this pipeline.

public ChannelHandler

Returns:

the removed handler
remove
(String
the name under which the ChannelHandler was stored.
name
)

Removes the ChannelHandler with the specified name from this pipeline.

public <
the type of the handler
T extends ChannelHandler
>
T

Returns:

the removed handler
remove
(Class<T>
the type of the handler
handlerType
)

Removes the ChannelHandler of the specified type from this pipeline.

public ChannelHandler

Returns:

the removed handler
removeFirst
()

Removes the first ChannelHandler in this pipeline.

public ChannelHandler

Returns:

the removed handler
removeLast
()

Removes the last ChannelHandler in this pipeline.

public ChannelPipeline

Returns:

itself
replace
(ChannelHandler
the ChannelHandler to be replaced
oldHandler
,
String
the name under which the replacement should be added
newName
,
ChannelHandler
the ChannelHandler which is used as replacement
newHandler
)

Replaces the specified ChannelHandler with a new handler in this pipeline.

public ChannelHandler

Returns:

the removed handler
replace
(String
the name of the ChannelHandler to be replaced
oldName
,
String
the name under which the replacement should be added
newName
,
ChannelHandler
the ChannelHandler which is used as replacement
newHandler
)

Replaces the ChannelHandler of the specified name with a new handler in this pipeline.

public <T extends ChannelHandler> T

Returns:

the removed handler
replace
(Class<T>
the type of the handler to be removed
oldHandlerType
,
String
the name under which the replacement should be added
newName
,
ChannelHandler
the ChannelHandler which is used as replacement
newHandler
)

Replaces the ChannelHandler of the specified type with a new handler in this pipeline.

public Map<String, ChannelHandler>
toMap()

Converts this pipeline into an ordered Map whose keys are handler names and whose values are handlers.

Inherited from io.netty.channel.ChannelOutboundInvoker:
bindbindclosecloseconnectconnectconnectconnectderegisterderegisterdisconnectdisconnectnewFailedFuturenewProgressivePromisenewPromisenewSucceededFuturereadvoidPromisewritewritewriteAndFlushwriteAndFlush
Inherited from java.lang.Iterable:
forEachiteratorspliterator

Method Detail

addAfterback to summary
public ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler)

Inserts a ChannelHandler after an existing handler of this pipeline.

Parameters
baseName:String

the name of the existing handler

name:String

the name of the handler to insert after

handler:ChannelHandler

the handler to insert after

Exceptions
NoSuchElementException:
if there's no such entry with the specified baseName
IllegalArgumentException:
if there's an entry with the same name already in the pipeline
NullPointerException:
if the specified baseName or handler is null
addAfterback to summary
public ChannelPipeline addAfter(EventExecutorGroup group, String baseName, String name, ChannelHandler handler)

Inserts a ChannelHandler after an existing handler of this pipeline.

Parameters
group:EventExecutorGroup

the EventExecutorGroup which will be used to execute the ChannelHandler methods

baseName:String

the name of the existing handler

name:String

the name of the handler to insert after

handler:ChannelHandler

the handler to insert after

Exceptions
NoSuchElementException:
if there's no such entry with the specified baseName
IllegalArgumentException:
if there's an entry with the same name already in the pipeline
NullPointerException:
if the specified baseName or handler is null
addBeforeback to summary
public ChannelPipeline addBefore(String baseName, String name, ChannelHandler handler)

Inserts a ChannelHandler before an existing handler of this pipeline.

Parameters
baseName:String

the name of the existing handler

name:String

the name of the handler to insert before

handler:ChannelHandler

the handler to insert before

Exceptions
NoSuchElementException:
if there's no such entry with the specified baseName
IllegalArgumentException:
if there's an entry with the same name already in the pipeline
NullPointerException:
if the specified baseName or handler is null
addBeforeback to summary
public ChannelPipeline addBefore(EventExecutorGroup group, String baseName, String name, ChannelHandler handler)

Inserts a ChannelHandler before an existing handler of this pipeline.

Parameters
group:EventExecutorGroup

the EventExecutorGroup which will be used to execute the ChannelHandler methods

baseName:String

the name of the existing handler

name:String

the name of the handler to insert before

handler:ChannelHandler

the handler to insert before

Exceptions
NoSuchElementException:
if there's no such entry with the specified baseName
IllegalArgumentException:
if there's an entry with the same name already in the pipeline
NullPointerException:
if the specified baseName or handler is null
addFirstback to summary
public ChannelPipeline addFirst(String name, ChannelHandler handler)

Inserts a ChannelHandler at the first position of this pipeline.

Parameters
name:String

the name of the handler to insert first

handler:ChannelHandler

the handler to insert first

Exceptions
IllegalArgumentException:
if there's an entry with the same name already in the pipeline
NullPointerException:
if the specified handler is null
addFirstback to summary
public ChannelPipeline addFirst(EventExecutorGroup group, String name, ChannelHandler handler)

Inserts a ChannelHandler at the first position of this pipeline.

Parameters
group:EventExecutorGroup

the EventExecutorGroup which will be used to execute the ChannelHandler methods

name:String

the name of the handler to insert first

handler:ChannelHandler

the handler to insert first

Exceptions
IllegalArgumentException:
if there's an entry with the same name already in the pipeline
NullPointerException:
if the specified handler is null
addFirstback to summary
public ChannelPipeline addFirst(ChannelHandler... handlers)

Inserts ChannelHandlers at the first position of this pipeline.

Parameters
handlers:ChannelHandler[]

the handlers to insert first

addFirstback to summary
public ChannelPipeline addFirst(EventExecutorGroup group, ChannelHandler... handlers)

Inserts ChannelHandlers at the first position of this pipeline.

Parameters
group:EventExecutorGroup

the EventExecutorGroup which will be used to execute the ChannelHandlers methods.

handlers:ChannelHandler[]

the handlers to insert first

addLastback to summary
public ChannelPipeline addLast(String name, ChannelHandler handler)

Appends a ChannelHandler at the last position of this pipeline.

Parameters
name:String

the name of the handler to append

handler:ChannelHandler

the handler to append

Exceptions
IllegalArgumentException:
if there's an entry with the same name already in the pipeline
NullPointerException:
if the specified handler is null
addLastback to summary
public ChannelPipeline addLast(EventExecutorGroup group, String name, ChannelHandler handler)

Appends a ChannelHandler at the last position of this pipeline.

Parameters
group:EventExecutorGroup

the EventExecutorGroup which will be used to execute the ChannelHandler methods

name:String

the name of the handler to append

handler:ChannelHandler

the handler to append

Exceptions
IllegalArgumentException:
if there's an entry with the same name already in the pipeline
NullPointerException:
if the specified handler is null
addLastback to summary
public ChannelPipeline addLast(ChannelHandler... handlers)

Inserts ChannelHandlers at the last position of this pipeline.

Parameters
handlers:ChannelHandler[]

the handlers to insert last

addLastback to summary
public ChannelPipeline addLast(EventExecutorGroup group, ChannelHandler... handlers)

Inserts ChannelHandlers at the last position of this pipeline.

Parameters
group:EventExecutorGroup

the EventExecutorGroup which will be used to execute the ChannelHandlers methods.

handlers:ChannelHandler[]

the handlers to insert last

channelback to summary
public Channel channel()

Returns the Channel that this pipeline is attached to.

Returns:Channel

the channel. null if this pipeline is not attached yet.

contextback to summary
public ChannelHandlerContext context(ChannelHandler handler)

Returns the context object of the specified ChannelHandler in this pipeline.

Returns:ChannelHandlerContext

the context object of the specified handler. null if there's no such handler in this pipeline.

contextback to summary
public ChannelHandlerContext context(String name)

Returns the context object of the ChannelHandler with the specified name in this pipeline.

Returns:ChannelHandlerContext

the context object of the handler with the specified name. null if there's no such handler in this pipeline.

contextback to summary
public ChannelHandlerContext context(Class<? extends ChannelHandler> handlerType)

Returns the context object of the ChannelHandler of the specified type in this pipeline.

Returns:ChannelHandlerContext

the context object of the handler of the specified type. null if there's no such handler in this pipeline.

fireChannelActiveback to summary
public ChannelPipeline fireChannelActive()

Redeclares io.netty.channel.ChannelInboundInvoker.fireChannelActive.

Doc from io.netty.channel.ChannelInboundInvoker.fireChannelActive.

A Channel is active now, which means it is connected. This will result in having the ChannelInboundHandler#channelActive(ChannelHandlerContext) method called of the next ChannelInboundHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelInactiveback to summary
public ChannelPipeline fireChannelInactive()

Redeclares io.netty.channel.ChannelInboundInvoker.fireChannelInactive.

Doc from io.netty.channel.ChannelInboundInvoker.fireChannelInactive.

A Channel is inactive now, which means it is closed. This will result in having the ChannelInboundHandler#channelInactive(ChannelHandlerContext) method called of the next ChannelInboundHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelReadback to summary
public ChannelPipeline fireChannelRead(Object msg)

Redeclares io.netty.channel.ChannelInboundInvoker.fireChannelRead.

Doc from io.netty.channel.ChannelInboundInvoker.fireChannelRead.

A Channel received a message. This will result in having the ChannelInboundHandler#channelRead(ChannelHandlerContext, Object) method called of the next ChannelInboundHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelReadCompleteback to summary
public ChannelPipeline fireChannelReadComplete()

Redeclares io.netty.channel.ChannelInboundInvoker.fireChannelReadComplete.

Doc from io.netty.channel.ChannelInboundInvoker.fireChannelReadComplete.

Triggers an ChannelInboundHandler#channelReadComplete(ChannelHandlerContext) event to the next ChannelInboundHandler in the ChannelPipeline.

Annotations
@Override
fireChannelRegisteredback to summary
public ChannelPipeline fireChannelRegistered()

Redeclares io.netty.channel.ChannelInboundInvoker.fireChannelRegistered.

Doc from io.netty.channel.ChannelInboundInvoker.fireChannelRegistered.

A Channel was registered to its EventLoop. This will result in having the ChannelInboundHandler#channelRegistered(ChannelHandlerContext) method called of the next ChannelInboundHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelUnregisteredback to summary
public ChannelPipeline fireChannelUnregistered()

Redeclares io.netty.channel.ChannelInboundInvoker.fireChannelUnregistered.

Doc from io.netty.channel.ChannelInboundInvoker.fireChannelUnregistered.

A Channel was unregistered from its EventLoop. This will result in having the ChannelInboundHandler#channelUnregistered(ChannelHandlerContext) method called of the next ChannelInboundHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelWritabilityChangedback to summary
public ChannelPipeline fireChannelWritabilityChanged()

Redeclares io.netty.channel.ChannelInboundInvoker.fireChannelWritabilityChanged.

Doc from io.netty.channel.ChannelInboundInvoker.fireChannelWritabilityChanged.

Triggers an ChannelInboundHandler#channelWritabilityChanged(ChannelHandlerContext) event to the next ChannelInboundHandler in the ChannelPipeline.

Annotations
@Override
fireExceptionCaughtback to summary
public ChannelPipeline fireExceptionCaught(Throwable cause)

Redeclares io.netty.channel.ChannelInboundInvoker.fireExceptionCaught.

Doc from io.netty.channel.ChannelInboundInvoker.fireExceptionCaught.

A Channel received an Throwable in one of its inbound operations. This will result in having the ChannelInboundHandler#exceptionCaught(ChannelHandlerContext, Throwable) method called of the next ChannelInboundHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireUserEventTriggeredback to summary
public ChannelPipeline fireUserEventTriggered(Object event)

Redeclares io.netty.channel.ChannelInboundInvoker.fireUserEventTriggered.

Doc from io.netty.channel.ChannelInboundInvoker.fireUserEventTriggered.

A Channel received an user defined event. This will result in having the ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object) method called of the next ChannelInboundHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
firstback to summary
public ChannelHandler first()

Returns the first ChannelHandler in this pipeline.

Returns:ChannelHandler

the first handler. null if this pipeline is empty.

firstContextback to summary
public ChannelHandlerContext firstContext()

Returns the context of the first ChannelHandler in this pipeline.

Returns:ChannelHandlerContext

the context of the first handler. null if this pipeline is empty.

flushback to summary
public ChannelPipeline flush()

Redeclares io.netty.channel.ChannelOutboundInvoker.flush.

Doc from io.netty.channel.ChannelOutboundInvoker.flush.

Request to flush all pending messages via this ChannelOutboundInvoker.

Annotations
@Override
getback to summary
public ChannelHandler get(String name)

Returns the ChannelHandler with the specified name in this pipeline.

Returns:ChannelHandler

the handler with the specified name. null if there's no such handler in this pipeline.

getback to summary
public <T extends ChannelHandler> T get(Class<T> handlerType)

Returns the ChannelHandler of the specified type in this pipeline.

Returns:T

the handler of the specified handler type. null if there's no such handler in this pipeline.

lastback to summary
public ChannelHandler last()

Returns the last ChannelHandler in this pipeline.

Returns:ChannelHandler

the last handler. null if this pipeline is empty.

lastContextback to summary
public ChannelHandlerContext lastContext()

Returns the context of the last ChannelHandler in this pipeline.

Returns:ChannelHandlerContext

the context of the last handler. null if this pipeline is empty.

namesback to summary
public List<String> names()

Returns the List of the handler names.

removeback to summary
public ChannelPipeline remove(ChannelHandler handler)

Removes the specified ChannelHandler from this pipeline.

Parameters
handler:ChannelHandler

the ChannelHandler to remove

Exceptions
NoSuchElementException:
if there's no such handler in this pipeline
NullPointerException:
if the specified handler is null
removeback to summary
public ChannelHandler remove(String name)

Removes the ChannelHandler with the specified name from this pipeline.

Parameters
name:String

the name under which the ChannelHandler was stored.

Returns:ChannelHandler

the removed handler

Exceptions
NoSuchElementException:
if there's no such handler with the specified name in this pipeline
NullPointerException:
if the specified name is null
removeback to summary
public <T extends ChannelHandler> T remove(Class<T> handlerType)

Removes the ChannelHandler of the specified type from this pipeline.

Parameters
<T>
the type of the handler
handlerType:Class<T>

the type of the handler

Returns:T

the removed handler

Exceptions
NoSuchElementException:
if there's no such handler of the specified type in this pipeline
NullPointerException:
if the specified handler type is null
removeFirstback to summary
public ChannelHandler removeFirst()

Removes the first ChannelHandler in this pipeline.

Returns:ChannelHandler

the removed handler

Exceptions
NoSuchElementException:
if this pipeline is empty
removeLastback to summary
public ChannelHandler removeLast()

Removes the last ChannelHandler in this pipeline.

Returns:ChannelHandler

the removed handler

Exceptions
NoSuchElementException:
if this pipeline is empty
replaceback to summary
public ChannelPipeline replace(ChannelHandler oldHandler, String newName, ChannelHandler newHandler)

Replaces the specified ChannelHandler with a new handler in this pipeline.

Parameters
oldHandler:ChannelHandler

the ChannelHandler to be replaced

newName:String

the name under which the replacement should be added

newHandler:ChannelHandler

the ChannelHandler which is used as replacement

Returns:ChannelPipeline

itself

Exceptions
NoSuchElementException:
if the specified old handler does not exist in this pipeline
IllegalArgumentException:
if a handler with the specified new name already exists in this pipeline, except for the handler to be replaced
NullPointerException:
if the specified old handler or new handler is null
replaceback to summary
public ChannelHandler replace(String oldName, String newName, ChannelHandler newHandler)

Replaces the ChannelHandler of the specified name with a new handler in this pipeline.

Parameters
oldName:String

the name of the ChannelHandler to be replaced

newName:String

the name under which the replacement should be added

newHandler:ChannelHandler

the ChannelHandler which is used as replacement

Returns:ChannelHandler

the removed handler

Exceptions
NoSuchElementException:
if the handler with the specified old name does not exist in this pipeline
IllegalArgumentException:
if a handler with the specified new name already exists in this pipeline, except for the handler to be replaced
NullPointerException:
if the specified old handler or new handler is null
replaceback to summary
public <T extends ChannelHandler> T replace(Class<T> oldHandlerType, String newName, ChannelHandler newHandler)

Replaces the ChannelHandler of the specified type with a new handler in this pipeline.

Parameters
oldHandlerType:Class<T>

the type of the handler to be removed

newName:String

the name under which the replacement should be added

newHandler:ChannelHandler

the ChannelHandler which is used as replacement

Returns:T

the removed handler

Exceptions
NoSuchElementException:
if the handler of the specified old handler type does not exist in this pipeline
IllegalArgumentException:
if a handler with the specified new name already exists in this pipeline, except for the handler to be replaced
NullPointerException:
if the specified old handler or new handler is null
toMapback to summary
public Map<String, ChannelHandler> toMap()

Converts this pipeline into an ordered Map whose keys are handler names and whose values are handlers.