public class DefaultChannelPipeline extends java.lang.Object implements ChannelPipeline
ChannelPipeline implementation. It is recommended
to use Channels.pipeline() to create a new ChannelPipeline
instance rather than calling the constructor directly.| Modifier and Type | Class and Description |
|---|---|
private class |
DefaultChannelPipeline.DefaultChannelHandlerContext |
private static class |
DefaultChannelPipeline.DiscardingChannelSink |
| Modifier and Type | Field and Description |
|---|---|
private Channel |
channel |
(package private) static ChannelSink |
discardingSink |
private DefaultChannelPipeline.DefaultChannelHandlerContext |
head |
(package private) static InternalLogger |
logger |
private java.util.Map<java.lang.String,DefaultChannelPipeline.DefaultChannelHandlerContext> |
name2ctx |
private ChannelSink |
sink |
private DefaultChannelPipeline.DefaultChannelHandlerContext |
tail |
| Constructor and Description |
|---|
DefaultChannelPipeline() |
| Modifier and Type | Method and Description |
|---|---|
void |
addAfter(java.lang.String baseName,
java.lang.String name,
ChannelHandler handler)
Inserts a
ChannelHandler after an existing handler of this
pipeline. |
void |
addBefore(java.lang.String baseName,
java.lang.String name,
ChannelHandler handler)
Inserts a
ChannelHandler before an existing handler of this
pipeline. |
void |
addFirst(java.lang.String name,
ChannelHandler handler)
Inserts a
ChannelHandler at the first position of this pipeline. |
void |
addLast(java.lang.String name,
ChannelHandler handler)
Appends a
ChannelHandler at the last position of this pipeline. |
void |
attach(Channel channel,
ChannelSink sink)
Attaches this pipeline to the specified
Channel and
ChannelSink. |
private void |
callAfterAdd(ChannelHandlerContext ctx) |
private static void |
callAfterRemove(ChannelHandlerContext ctx) |
private static void |
callBeforeAdd(ChannelHandlerContext ctx) |
private static void |
callBeforeRemove(ChannelHandlerContext ctx) |
private void |
checkDuplicateName(java.lang.String name) |
ChannelFuture |
execute(java.lang.Runnable task)
Schedules the specified task to be executed in the I/O thread associated
with this pipeline's
Channel. |
<T extends ChannelHandler> |
get(java.lang.Class<T> handlerType)
Returns the
ChannelHandler of the specified type in this
pipeline. |
ChannelHandler |
get(java.lang.String name)
Returns the
ChannelHandler with the specified name in this
pipeline. |
private DefaultChannelPipeline.DefaultChannelHandlerContext |
getActualDownstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx) |
private DefaultChannelPipeline.DefaultChannelHandlerContext |
getActualUpstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx) |
Channel |
getChannel()
Returns the
Channel that this pipeline is attached to. |
ChannelHandlerContext |
getContext(ChannelHandler handler)
Returns the context object of the specified
ChannelHandler in
this pipeline. |
ChannelHandlerContext |
getContext(java.lang.Class<? extends ChannelHandler> handlerType)
Returns the context object of the
ChannelHandler of the
specified type in this pipeline. |
ChannelHandlerContext |
getContext(java.lang.String name)
Returns the context object of the
ChannelHandler with the
specified name in this pipeline. |
private DefaultChannelPipeline.DefaultChannelHandlerContext |
getContextOrDie(ChannelHandler handler) |
private DefaultChannelPipeline.DefaultChannelHandlerContext |
getContextOrDie(java.lang.Class<? extends ChannelHandler> handlerType) |
private DefaultChannelPipeline.DefaultChannelHandlerContext |
getContextOrDie(java.lang.String name) |
ChannelHandler |
getFirst()
Returns the first
ChannelHandler in this pipeline. |
ChannelHandler |
getLast()
Returns the last
ChannelHandler in this pipeline. |
java.util.List<java.lang.String> |
getNames()
Returns the
List of the handler names. |
ChannelSink |
getSink()
Returns the
ChannelSink that this pipeline is attached to. |
private void |
init(java.lang.String name,
ChannelHandler handler) |
boolean |
isAttached()
Returns
true if and only if this pipeline is attached to
a Channel. |
protected void |
notifyHandlerException(ChannelEvent e,
java.lang.Throwable t) |
void |
remove(ChannelHandler handler)
Removes the specified
ChannelHandler from this pipeline. |
<T extends ChannelHandler> |
remove(java.lang.Class<T> handlerType)
Removes the
ChannelHandler of the specified type from this
pipeline |
private DefaultChannelPipeline.DefaultChannelHandlerContext |
remove(DefaultChannelPipeline.DefaultChannelHandlerContext ctx) |
ChannelHandler |
remove(java.lang.String name)
Removes the
ChannelHandler with the specified name from this
pipeline. |
ChannelHandler |
removeFirst()
Removes the first
ChannelHandler in this pipeline. |
ChannelHandler |
removeLast()
Removes the last
ChannelHandler in this pipeline. |
void |
replace(ChannelHandler oldHandler,
java.lang.String newName,
ChannelHandler newHandler)
Replaces the specified
ChannelHandler with a new handler in
this pipeline. |
<T extends ChannelHandler> |
replace(java.lang.Class<T> oldHandlerType,
java.lang.String newName,
ChannelHandler newHandler)
Replaces the
ChannelHandler of the specified type with a new
handler in this pipeline. |
private ChannelHandler |
replace(DefaultChannelPipeline.DefaultChannelHandlerContext ctx,
java.lang.String newName,
ChannelHandler newHandler) |
ChannelHandler |
replace(java.lang.String oldName,
java.lang.String newName,
ChannelHandler newHandler)
Replaces the
ChannelHandler of the specified name with a new
handler in this pipeline. |
void |
sendDownstream(ChannelEvent e)
Sends the specified
ChannelEvent to the last
ChannelDownstreamHandler in this pipeline. |
(package private) void |
sendDownstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx,
ChannelEvent e) |
void |
sendUpstream(ChannelEvent e)
Sends the specified
ChannelEvent to the first
ChannelUpstreamHandler in this pipeline. |
(package private) void |
sendUpstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx,
ChannelEvent e) |
java.util.Map<java.lang.String,ChannelHandler> |
toMap()
Converts this pipeline into an ordered
Map whose keys are
handler names and whose values are handlers. |
java.lang.String |
toString()
Returns the
String representation of this pipeline. |
static final InternalLogger logger
static final ChannelSink discardingSink
private volatile Channel channel
private volatile ChannelSink sink
private volatile DefaultChannelPipeline.DefaultChannelHandlerContext head
private volatile DefaultChannelPipeline.DefaultChannelHandlerContext tail
private final java.util.Map<java.lang.String,DefaultChannelPipeline.DefaultChannelHandlerContext> name2ctx
public Channel getChannel()
ChannelPipelineChannel that this pipeline is attached to.getChannel in interface ChannelPipelinenull if this pipeline is not attached yet.public ChannelSink getSink()
ChannelPipelineChannelSink that this pipeline is attached to.getSink in interface ChannelPipelinenull if this pipeline is not attached yet.public void attach(Channel channel, ChannelSink sink)
ChannelPipelineChannel and
ChannelSink. Once a pipeline is attached, it can't be detached
nor attached again.attach in interface ChannelPipelinepublic boolean isAttached()
ChannelPipelinetrue if and only if this pipeline is attached to
a Channel.isAttached in interface ChannelPipelinepublic void addFirst(java.lang.String name,
ChannelHandler handler)
ChannelPipelineChannelHandler at the first position of this pipeline.addFirst in interface ChannelPipelinename - the name of the handler to insert firsthandler - the handler to insert firstpublic void addLast(java.lang.String name,
ChannelHandler handler)
ChannelPipelineChannelHandler at the last position of this pipeline.addLast in interface ChannelPipelinename - the name of the handler to appendhandler - the handler to appendpublic void addBefore(java.lang.String baseName,
java.lang.String name,
ChannelHandler handler)
ChannelPipelineChannelHandler before an existing handler of this
pipeline.addBefore in interface ChannelPipelinebaseName - the name of the existing handlername - the name of the handler to insert beforehandler - the handler to insert beforepublic void addAfter(java.lang.String baseName,
java.lang.String name,
ChannelHandler handler)
ChannelPipelineChannelHandler after an existing handler of this
pipeline.addAfter in interface ChannelPipelinebaseName - the name of the existing handlername - the name of the handler to insert afterhandler - the handler to insert afterpublic void remove(ChannelHandler handler)
ChannelPipelineChannelHandler from this pipeline.remove in interface ChannelPipelinepublic ChannelHandler remove(java.lang.String name)
ChannelPipelineChannelHandler with the specified name from this
pipeline.remove in interface ChannelPipelinepublic <T extends ChannelHandler> T remove(java.lang.Class<T> handlerType)
ChannelPipelineChannelHandler of the specified type from this
pipelineremove in interface ChannelPipelineT - the type of the handlerhandlerType - the type of the handlerprivate DefaultChannelPipeline.DefaultChannelHandlerContext remove(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)
public ChannelHandler removeFirst()
ChannelPipelineChannelHandler in this pipeline.removeFirst in interface ChannelPipelinepublic ChannelHandler removeLast()
ChannelPipelineChannelHandler in this pipeline.removeLast in interface ChannelPipelinepublic void replace(ChannelHandler oldHandler, java.lang.String newName, ChannelHandler newHandler)
ChannelPipelineChannelHandler with a new handler in
this pipeline.replace in interface ChannelPipelinepublic ChannelHandler replace(java.lang.String oldName, java.lang.String newName, ChannelHandler newHandler)
ChannelPipelineChannelHandler of the specified name with a new
handler in this pipeline.replace in interface ChannelPipelinepublic <T extends ChannelHandler> T replace(java.lang.Class<T> oldHandlerType, java.lang.String newName, ChannelHandler newHandler)
ChannelPipelineChannelHandler of the specified type with a new
handler in this pipeline.replace in interface ChannelPipelineprivate ChannelHandler replace(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, java.lang.String newName, ChannelHandler newHandler)
private static void callBeforeAdd(ChannelHandlerContext ctx)
private void callAfterAdd(ChannelHandlerContext ctx)
private static void callBeforeRemove(ChannelHandlerContext ctx)
private static void callAfterRemove(ChannelHandlerContext ctx)
public ChannelHandler getFirst()
ChannelPipelineChannelHandler in this pipeline.getFirst in interface ChannelPipelinenull if this pipeline is empty.public ChannelHandler getLast()
ChannelPipelineChannelHandler in this pipeline.getLast in interface ChannelPipelinenull if this pipeline is empty.public ChannelHandler get(java.lang.String name)
ChannelPipelineChannelHandler with the specified name in this
pipeline.get in interface ChannelPipelinenull if there's no such handler in this pipeline.public <T extends ChannelHandler> T get(java.lang.Class<T> handlerType)
ChannelPipelineChannelHandler of the specified type in this
pipeline.get in interface ChannelPipelinenull if there's no such handler in this pipeline.public ChannelHandlerContext getContext(java.lang.String name)
ChannelPipelineChannelHandler with the
specified name in this pipeline.getContext in interface ChannelPipelinenull if there's no such handler in this pipeline.public ChannelHandlerContext getContext(ChannelHandler handler)
ChannelPipelineChannelHandler in
this pipeline.getContext in interface ChannelPipelinenull if there's no such handler in this pipeline.public ChannelHandlerContext getContext(java.lang.Class<? extends ChannelHandler> handlerType)
ChannelPipelineChannelHandler of the
specified type in this pipeline.getContext in interface ChannelPipelinenull if there's no such handler in this pipeline.public java.util.List<java.lang.String> getNames()
ChannelPipelineList of the handler names.getNames in interface ChannelPipelinepublic java.util.Map<java.lang.String,ChannelHandler> toMap()
ChannelPipelineMap whose keys are
handler names and whose values are handlers.toMap in interface ChannelPipelinepublic java.lang.String toString()
String representation of this pipeline.toString in class java.lang.Objectpublic void sendUpstream(ChannelEvent e)
ChannelPipelineChannelEvent to the first
ChannelUpstreamHandler in this pipeline.sendUpstream in interface ChannelPipelinevoid sendUpstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, ChannelEvent e)
public void sendDownstream(ChannelEvent e)
ChannelPipelineChannelEvent to the last
ChannelDownstreamHandler in this pipeline.sendDownstream in interface ChannelPipelinevoid sendDownstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, ChannelEvent e)
private DefaultChannelPipeline.DefaultChannelHandlerContext getActualUpstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)
private DefaultChannelPipeline.DefaultChannelHandlerContext getActualDownstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)
public ChannelFuture execute(java.lang.Runnable task)
ChannelPipelineChannel.execute in interface ChannelPipelineprotected void notifyHandlerException(ChannelEvent e, java.lang.Throwable t)
private void init(java.lang.String name,
ChannelHandler handler)
private void checkDuplicateName(java.lang.String name)
private DefaultChannelPipeline.DefaultChannelHandlerContext getContextOrDie(java.lang.String name)
private DefaultChannelPipeline.DefaultChannelHandlerContext getContextOrDie(ChannelHandler handler)
private DefaultChannelPipeline.DefaultChannelHandlerContext getContextOrDie(java.lang.Class<? extends ChannelHandler> handlerType)