Package org.jboss.netty.channel
Class DefaultChannelPipeline
- java.lang.Object
-
- org.jboss.netty.channel.DefaultChannelPipeline
-
- All Implemented Interfaces:
ChannelPipeline
- Direct Known Subclasses:
AbstractCodecEmbedder.EmbeddedChannelPipeline
public class DefaultChannelPipeline extends java.lang.Object implements ChannelPipeline
The defaultChannelPipeline
implementation. It is recommended to useChannels.pipeline()
to create a newChannelPipeline
instance rather than calling the constructor directly.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
DefaultChannelPipeline.DefaultChannelHandlerContext
private static class
DefaultChannelPipeline.DiscardingChannelSink
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description DefaultChannelPipeline()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAfter(java.lang.String baseName, java.lang.String name, ChannelHandler handler)
Inserts aChannelHandler
after an existing handler of this pipeline.void
addBefore(java.lang.String baseName, java.lang.String name, ChannelHandler handler)
Inserts aChannelHandler
before an existing handler of this pipeline.void
addFirst(java.lang.String name, ChannelHandler handler)
Inserts aChannelHandler
at the first position of this pipeline.void
addLast(java.lang.String name, ChannelHandler handler)
Appends aChannelHandler
at the last position of this pipeline.void
attach(Channel channel, ChannelSink sink)
Attaches this pipeline to the specifiedChannel
andChannelSink
.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'sChannel
.<T extends ChannelHandler>
Tget(java.lang.Class<T> handlerType)
Returns theChannelHandler
of the specified type in this pipeline.ChannelHandler
get(java.lang.String name)
Returns theChannelHandler
with the specified name in this pipeline.private DefaultChannelPipeline.DefaultChannelHandlerContext
getActualDownstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)
private DefaultChannelPipeline.DefaultChannelHandlerContext
getActualUpstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)
Channel
getChannel()
Returns theChannel
that this pipeline is attached to.ChannelHandlerContext
getContext(java.lang.Class<? extends ChannelHandler> handlerType)
Returns the context object of theChannelHandler
of the specified type in this pipeline.ChannelHandlerContext
getContext(java.lang.String name)
Returns the context object of theChannelHandler
with the specified name in this pipeline.ChannelHandlerContext
getContext(ChannelHandler handler)
Returns the context object of the specifiedChannelHandler
in this pipeline.private DefaultChannelPipeline.DefaultChannelHandlerContext
getContextOrDie(java.lang.Class<? extends ChannelHandler> handlerType)
private DefaultChannelPipeline.DefaultChannelHandlerContext
getContextOrDie(java.lang.String name)
private DefaultChannelPipeline.DefaultChannelHandlerContext
getContextOrDie(ChannelHandler handler)
ChannelHandler
getFirst()
Returns the firstChannelHandler
in this pipeline.ChannelHandler
getLast()
Returns the lastChannelHandler
in this pipeline.java.util.List<java.lang.String>
getNames()
Returns theList
of the handler names.ChannelSink
getSink()
Returns theChannelSink
that this pipeline is attached to.private void
init(java.lang.String name, ChannelHandler handler)
boolean
isAttached()
Returnstrue
if and only if this pipeline is attached to aChannel
.protected void
notifyHandlerException(ChannelEvent e, java.lang.Throwable t)
<T extends ChannelHandler>
Tremove(java.lang.Class<T> handlerType)
Removes theChannelHandler
of the specified type from this pipelineChannelHandler
remove(java.lang.String name)
Removes theChannelHandler
with the specified name from this pipeline.void
remove(ChannelHandler handler)
Removes the specifiedChannelHandler
from this pipeline.private DefaultChannelPipeline.DefaultChannelHandlerContext
remove(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)
ChannelHandler
removeFirst()
Removes the firstChannelHandler
in this pipeline.ChannelHandler
removeLast()
Removes the lastChannelHandler
in this pipeline.<T extends ChannelHandler>
Treplace(java.lang.Class<T> oldHandlerType, java.lang.String newName, ChannelHandler newHandler)
Replaces theChannelHandler
of the specified type with a new handler in this pipeline.ChannelHandler
replace(java.lang.String oldName, java.lang.String newName, ChannelHandler newHandler)
Replaces theChannelHandler
of the specified name with a new handler in this pipeline.void
replace(ChannelHandler oldHandler, java.lang.String newName, ChannelHandler newHandler)
Replaces the specifiedChannelHandler
with a new handler in this pipeline.private ChannelHandler
replace(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, java.lang.String newName, ChannelHandler newHandler)
void
sendDownstream(ChannelEvent e)
Sends the specifiedChannelEvent
to the lastChannelDownstreamHandler
in this pipeline.(package private) void
sendDownstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, ChannelEvent e)
void
sendUpstream(ChannelEvent e)
Sends the specifiedChannelEvent
to the firstChannelUpstreamHandler
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 orderedMap
whose keys are handler names and whose values are handlers.java.lang.String
toString()
Returns theString
representation of this pipeline.
-
-
-
Field Detail
-
logger
static final InternalLogger logger
-
discardingSink
static final ChannelSink discardingSink
-
channel
private volatile Channel channel
-
sink
private volatile ChannelSink sink
-
head
private volatile DefaultChannelPipeline.DefaultChannelHandlerContext head
-
tail
private volatile DefaultChannelPipeline.DefaultChannelHandlerContext tail
-
name2ctx
private final java.util.Map<java.lang.String,DefaultChannelPipeline.DefaultChannelHandlerContext> name2ctx
-
-
Method Detail
-
getChannel
public Channel getChannel()
Description copied from interface:ChannelPipeline
Returns theChannel
that this pipeline is attached to.- Specified by:
getChannel
in interfaceChannelPipeline
- Returns:
- the channel.
null
if this pipeline is not attached yet.
-
getSink
public ChannelSink getSink()
Description copied from interface:ChannelPipeline
Returns theChannelSink
that this pipeline is attached to.- Specified by:
getSink
in interfaceChannelPipeline
- Returns:
- the sink.
null
if this pipeline is not attached yet.
-
attach
public void attach(Channel channel, ChannelSink sink)
Description copied from interface:ChannelPipeline
Attaches this pipeline to the specifiedChannel
andChannelSink
. Once a pipeline is attached, it can't be detached nor attached again.- Specified by:
attach
in interfaceChannelPipeline
-
isAttached
public boolean isAttached()
Description copied from interface:ChannelPipeline
Returnstrue
if and only if this pipeline is attached to aChannel
.- Specified by:
isAttached
in interfaceChannelPipeline
-
addFirst
public void addFirst(java.lang.String name, ChannelHandler handler)
Description copied from interface:ChannelPipeline
Inserts aChannelHandler
at the first position of this pipeline.- Specified by:
addFirst
in interfaceChannelPipeline
- Parameters:
name
- the name of the handler to insert firsthandler
- the handler to insert first
-
addLast
public void addLast(java.lang.String name, ChannelHandler handler)
Description copied from interface:ChannelPipeline
Appends aChannelHandler
at the last position of this pipeline.- Specified by:
addLast
in interfaceChannelPipeline
- Parameters:
name
- the name of the handler to appendhandler
- the handler to append
-
addBefore
public void addBefore(java.lang.String baseName, java.lang.String name, ChannelHandler handler)
Description copied from interface:ChannelPipeline
Inserts aChannelHandler
before an existing handler of this pipeline.- Specified by:
addBefore
in interfaceChannelPipeline
- Parameters:
baseName
- the name of the existing handlername
- the name of the handler to insert beforehandler
- the handler to insert before
-
addAfter
public void addAfter(java.lang.String baseName, java.lang.String name, ChannelHandler handler)
Description copied from interface:ChannelPipeline
Inserts aChannelHandler
after an existing handler of this pipeline.- Specified by:
addAfter
in interfaceChannelPipeline
- Parameters:
baseName
- the name of the existing handlername
- the name of the handler to insert afterhandler
- the handler to insert after
-
remove
public void remove(ChannelHandler handler)
Description copied from interface:ChannelPipeline
Removes the specifiedChannelHandler
from this pipeline.- Specified by:
remove
in interfaceChannelPipeline
-
remove
public ChannelHandler remove(java.lang.String name)
Description copied from interface:ChannelPipeline
Removes theChannelHandler
with the specified name from this pipeline.- Specified by:
remove
in interfaceChannelPipeline
- Returns:
- the removed handler
-
remove
public <T extends ChannelHandler> T remove(java.lang.Class<T> handlerType)
Description copied from interface:ChannelPipeline
Removes theChannelHandler
of the specified type from this pipeline- Specified by:
remove
in interfaceChannelPipeline
- Type Parameters:
T
- the type of the handler- Parameters:
handlerType
- the type of the handler- Returns:
- the removed handler
-
remove
private DefaultChannelPipeline.DefaultChannelHandlerContext remove(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)
-
removeFirst
public ChannelHandler removeFirst()
Description copied from interface:ChannelPipeline
Removes the firstChannelHandler
in this pipeline.- Specified by:
removeFirst
in interfaceChannelPipeline
- Returns:
- the removed handler
-
removeLast
public ChannelHandler removeLast()
Description copied from interface:ChannelPipeline
Removes the lastChannelHandler
in this pipeline.- Specified by:
removeLast
in interfaceChannelPipeline
- Returns:
- the removed handler
-
replace
public void replace(ChannelHandler oldHandler, java.lang.String newName, ChannelHandler newHandler)
Description copied from interface:ChannelPipeline
Replaces the specifiedChannelHandler
with a new handler in this pipeline.- Specified by:
replace
in interfaceChannelPipeline
-
replace
public ChannelHandler replace(java.lang.String oldName, java.lang.String newName, ChannelHandler newHandler)
Description copied from interface:ChannelPipeline
Replaces theChannelHandler
of the specified name with a new handler in this pipeline.- Specified by:
replace
in interfaceChannelPipeline
- Returns:
- the removed handler
-
replace
public <T extends ChannelHandler> T replace(java.lang.Class<T> oldHandlerType, java.lang.String newName, ChannelHandler newHandler)
Description copied from interface:ChannelPipeline
Replaces theChannelHandler
of the specified type with a new handler in this pipeline.- Specified by:
replace
in interfaceChannelPipeline
- Returns:
- the removed handler
-
replace
private ChannelHandler replace(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, java.lang.String newName, ChannelHandler newHandler)
-
callBeforeAdd
private static void callBeforeAdd(ChannelHandlerContext ctx)
-
callAfterAdd
private void callAfterAdd(ChannelHandlerContext ctx)
-
callBeforeRemove
private static void callBeforeRemove(ChannelHandlerContext ctx)
-
callAfterRemove
private static void callAfterRemove(ChannelHandlerContext ctx)
-
getFirst
public ChannelHandler getFirst()
Description copied from interface:ChannelPipeline
Returns the firstChannelHandler
in this pipeline.- Specified by:
getFirst
in interfaceChannelPipeline
- Returns:
- the first handler.
null
if this pipeline is empty.
-
getLast
public ChannelHandler getLast()
Description copied from interface:ChannelPipeline
Returns the lastChannelHandler
in this pipeline.- Specified by:
getLast
in interfaceChannelPipeline
- Returns:
- the last handler.
null
if this pipeline is empty.
-
get
public ChannelHandler get(java.lang.String name)
Description copied from interface:ChannelPipeline
Returns theChannelHandler
with the specified name in this pipeline.- Specified by:
get
in interfaceChannelPipeline
- Returns:
- the handler with the specified name.
null
if there's no such handler in this pipeline.
-
get
public <T extends ChannelHandler> T get(java.lang.Class<T> handlerType)
Description copied from interface:ChannelPipeline
Returns theChannelHandler
of the specified type in this pipeline.- Specified by:
get
in interfaceChannelPipeline
- Returns:
- the handler of the specified handler type.
null
if there's no such handler in this pipeline.
-
getContext
public ChannelHandlerContext getContext(java.lang.String name)
Description copied from interface:ChannelPipeline
Returns the context object of theChannelHandler
with the specified name in this pipeline.- Specified by:
getContext
in interfaceChannelPipeline
- Returns:
- the context object of the handler with the specified name.
null
if there's no such handler in this pipeline.
-
getContext
public ChannelHandlerContext getContext(ChannelHandler handler)
Description copied from interface:ChannelPipeline
Returns the context object of the specifiedChannelHandler
in this pipeline.- Specified by:
getContext
in interfaceChannelPipeline
- Returns:
- the context object of the specified handler.
null
if there's no such handler in this pipeline.
-
getContext
public ChannelHandlerContext getContext(java.lang.Class<? extends ChannelHandler> handlerType)
Description copied from interface:ChannelPipeline
Returns the context object of theChannelHandler
of the specified type in this pipeline.- Specified by:
getContext
in interfaceChannelPipeline
- Returns:
- the context object of the handler of the specified type.
null
if there's no such handler in this pipeline.
-
getNames
public java.util.List<java.lang.String> getNames()
Description copied from interface:ChannelPipeline
Returns theList
of the handler names.- Specified by:
getNames
in interfaceChannelPipeline
-
toMap
public java.util.Map<java.lang.String,ChannelHandler> toMap()
Description copied from interface:ChannelPipeline
Converts this pipeline into an orderedMap
whose keys are handler names and whose values are handlers.- Specified by:
toMap
in interfaceChannelPipeline
-
toString
public java.lang.String toString()
Returns theString
representation of this pipeline.- Overrides:
toString
in classjava.lang.Object
-
sendUpstream
public void sendUpstream(ChannelEvent e)
Description copied from interface:ChannelPipeline
Sends the specifiedChannelEvent
to the firstChannelUpstreamHandler
in this pipeline.- Specified by:
sendUpstream
in interfaceChannelPipeline
-
sendUpstream
void sendUpstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, ChannelEvent e)
-
sendDownstream
public void sendDownstream(ChannelEvent e)
Description copied from interface:ChannelPipeline
Sends the specifiedChannelEvent
to the lastChannelDownstreamHandler
in this pipeline.- Specified by:
sendDownstream
in interfaceChannelPipeline
-
sendDownstream
void sendDownstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, ChannelEvent e)
-
getActualUpstreamContext
private DefaultChannelPipeline.DefaultChannelHandlerContext getActualUpstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)
-
getActualDownstreamContext
private DefaultChannelPipeline.DefaultChannelHandlerContext getActualDownstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)
-
execute
public ChannelFuture execute(java.lang.Runnable task)
Description copied from interface:ChannelPipeline
Schedules the specified task to be executed in the I/O thread associated with this pipeline'sChannel
.- Specified by:
execute
in interfaceChannelPipeline
-
notifyHandlerException
protected void notifyHandlerException(ChannelEvent e, java.lang.Throwable t)
-
init
private void init(java.lang.String name, ChannelHandler handler)
-
checkDuplicateName
private void checkDuplicateName(java.lang.String name)
-
getContextOrDie
private DefaultChannelPipeline.DefaultChannelHandlerContext getContextOrDie(java.lang.String name)
-
getContextOrDie
private DefaultChannelPipeline.DefaultChannelHandlerContext getContextOrDie(ChannelHandler handler)
-
getContextOrDie
private DefaultChannelPipeline.DefaultChannelHandlerContext getContextOrDie(java.lang.Class<? extends ChannelHandler> handlerType)
-
-