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 defaultChannelPipelineimplementation. It is recommended to useChannels.pipeline()to create a newChannelPipelineinstance rather than calling the constructor directly.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classDefaultChannelPipeline.DefaultChannelHandlerContextprivate static classDefaultChannelPipeline.DiscardingChannelSink
-
Field Summary
Fields Modifier and Type Field Description private Channelchannel(package private) static ChannelSinkdiscardingSinkprivate DefaultChannelPipeline.DefaultChannelHandlerContexthead(package private) static InternalLoggerloggerprivate java.util.Map<java.lang.String,DefaultChannelPipeline.DefaultChannelHandlerContext>name2ctxprivate ChannelSinksinkprivate DefaultChannelPipeline.DefaultChannelHandlerContexttail
-
Constructor Summary
Constructors Constructor Description DefaultChannelPipeline()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAfter(java.lang.String baseName, java.lang.String name, ChannelHandler handler)Inserts aChannelHandlerafter an existing handler of this pipeline.voidaddBefore(java.lang.String baseName, java.lang.String name, ChannelHandler handler)Inserts aChannelHandlerbefore an existing handler of this pipeline.voidaddFirst(java.lang.String name, ChannelHandler handler)Inserts aChannelHandlerat the first position of this pipeline.voidaddLast(java.lang.String name, ChannelHandler handler)Appends aChannelHandlerat the last position of this pipeline.voidattach(Channel channel, ChannelSink sink)Attaches this pipeline to the specifiedChannelandChannelSink.private voidcallAfterAdd(ChannelHandlerContext ctx)private static voidcallAfterRemove(ChannelHandlerContext ctx)private static voidcallBeforeAdd(ChannelHandlerContext ctx)private static voidcallBeforeRemove(ChannelHandlerContext ctx)private voidcheckDuplicateName(java.lang.String name)ChannelFutureexecute(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 theChannelHandlerof the specified type in this pipeline.ChannelHandlerget(java.lang.String name)Returns theChannelHandlerwith the specified name in this pipeline.private DefaultChannelPipeline.DefaultChannelHandlerContextgetActualDownstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)private DefaultChannelPipeline.DefaultChannelHandlerContextgetActualUpstreamContext(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)ChannelgetChannel()Returns theChannelthat this pipeline is attached to.ChannelHandlerContextgetContext(java.lang.Class<? extends ChannelHandler> handlerType)Returns the context object of theChannelHandlerof the specified type in this pipeline.ChannelHandlerContextgetContext(java.lang.String name)Returns the context object of theChannelHandlerwith the specified name in this pipeline.ChannelHandlerContextgetContext(ChannelHandler handler)Returns the context object of the specifiedChannelHandlerin this pipeline.private DefaultChannelPipeline.DefaultChannelHandlerContextgetContextOrDie(java.lang.Class<? extends ChannelHandler> handlerType)private DefaultChannelPipeline.DefaultChannelHandlerContextgetContextOrDie(java.lang.String name)private DefaultChannelPipeline.DefaultChannelHandlerContextgetContextOrDie(ChannelHandler handler)ChannelHandlergetFirst()Returns the firstChannelHandlerin this pipeline.ChannelHandlergetLast()Returns the lastChannelHandlerin this pipeline.java.util.List<java.lang.String>getNames()Returns theListof the handler names.ChannelSinkgetSink()Returns theChannelSinkthat this pipeline is attached to.private voidinit(java.lang.String name, ChannelHandler handler)booleanisAttached()Returnstrueif and only if this pipeline is attached to aChannel.protected voidnotifyHandlerException(ChannelEvent e, java.lang.Throwable t)<T extends ChannelHandler>
Tremove(java.lang.Class<T> handlerType)Removes theChannelHandlerof the specified type from this pipelineChannelHandlerremove(java.lang.String name)Removes theChannelHandlerwith the specified name from this pipeline.voidremove(ChannelHandler handler)Removes the specifiedChannelHandlerfrom this pipeline.private DefaultChannelPipeline.DefaultChannelHandlerContextremove(DefaultChannelPipeline.DefaultChannelHandlerContext ctx)ChannelHandlerremoveFirst()Removes the firstChannelHandlerin this pipeline.ChannelHandlerremoveLast()Removes the lastChannelHandlerin this pipeline.<T extends ChannelHandler>
Treplace(java.lang.Class<T> oldHandlerType, java.lang.String newName, ChannelHandler newHandler)Replaces theChannelHandlerof the specified type with a new handler in this pipeline.ChannelHandlerreplace(java.lang.String oldName, java.lang.String newName, ChannelHandler newHandler)Replaces theChannelHandlerof the specified name with a new handler in this pipeline.voidreplace(ChannelHandler oldHandler, java.lang.String newName, ChannelHandler newHandler)Replaces the specifiedChannelHandlerwith a new handler in this pipeline.private ChannelHandlerreplace(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, java.lang.String newName, ChannelHandler newHandler)voidsendDownstream(ChannelEvent e)Sends the specifiedChannelEventto the lastChannelDownstreamHandlerin this pipeline.(package private) voidsendDownstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, ChannelEvent e)voidsendUpstream(ChannelEvent e)Sends the specifiedChannelEventto the firstChannelUpstreamHandlerin this pipeline.(package private) voidsendUpstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, ChannelEvent e)java.util.Map<java.lang.String,ChannelHandler>toMap()Converts this pipeline into an orderedMapwhose keys are handler names and whose values are handlers.java.lang.StringtoString()Returns theStringrepresentation 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:ChannelPipelineReturns theChannelthat this pipeline is attached to.- Specified by:
getChannelin interfaceChannelPipeline- Returns:
- the channel.
nullif this pipeline is not attached yet.
-
getSink
public ChannelSink getSink()
Description copied from interface:ChannelPipelineReturns theChannelSinkthat this pipeline is attached to.- Specified by:
getSinkin interfaceChannelPipeline- Returns:
- the sink.
nullif this pipeline is not attached yet.
-
attach
public void attach(Channel channel, ChannelSink sink)
Description copied from interface:ChannelPipelineAttaches this pipeline to the specifiedChannelandChannelSink. Once a pipeline is attached, it can't be detached nor attached again.- Specified by:
attachin interfaceChannelPipeline
-
isAttached
public boolean isAttached()
Description copied from interface:ChannelPipelineReturnstrueif and only if this pipeline is attached to aChannel.- Specified by:
isAttachedin interfaceChannelPipeline
-
addFirst
public void addFirst(java.lang.String name, ChannelHandler handler)Description copied from interface:ChannelPipelineInserts aChannelHandlerat the first position of this pipeline.- Specified by:
addFirstin 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:ChannelPipelineAppends aChannelHandlerat the last position of this pipeline.- Specified by:
addLastin 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:ChannelPipelineInserts aChannelHandlerbefore an existing handler of this pipeline.- Specified by:
addBeforein 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:ChannelPipelineInserts aChannelHandlerafter an existing handler of this pipeline.- Specified by:
addAfterin 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:ChannelPipelineRemoves the specifiedChannelHandlerfrom this pipeline.- Specified by:
removein interfaceChannelPipeline
-
remove
public ChannelHandler remove(java.lang.String name)
Description copied from interface:ChannelPipelineRemoves theChannelHandlerwith the specified name from this pipeline.- Specified by:
removein interfaceChannelPipeline- Returns:
- the removed handler
-
remove
public <T extends ChannelHandler> T remove(java.lang.Class<T> handlerType)
Description copied from interface:ChannelPipelineRemoves theChannelHandlerof the specified type from this pipeline- Specified by:
removein 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:ChannelPipelineRemoves the firstChannelHandlerin this pipeline.- Specified by:
removeFirstin interfaceChannelPipeline- Returns:
- the removed handler
-
removeLast
public ChannelHandler removeLast()
Description copied from interface:ChannelPipelineRemoves the lastChannelHandlerin this pipeline.- Specified by:
removeLastin interfaceChannelPipeline- Returns:
- the removed handler
-
replace
public void replace(ChannelHandler oldHandler, java.lang.String newName, ChannelHandler newHandler)
Description copied from interface:ChannelPipelineReplaces the specifiedChannelHandlerwith a new handler in this pipeline.- Specified by:
replacein interfaceChannelPipeline
-
replace
public ChannelHandler replace(java.lang.String oldName, java.lang.String newName, ChannelHandler newHandler)
Description copied from interface:ChannelPipelineReplaces theChannelHandlerof the specified name with a new handler in this pipeline.- Specified by:
replacein 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:ChannelPipelineReplaces theChannelHandlerof the specified type with a new handler in this pipeline.- Specified by:
replacein 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:ChannelPipelineReturns the firstChannelHandlerin this pipeline.- Specified by:
getFirstin interfaceChannelPipeline- Returns:
- the first handler.
nullif this pipeline is empty.
-
getLast
public ChannelHandler getLast()
Description copied from interface:ChannelPipelineReturns the lastChannelHandlerin this pipeline.- Specified by:
getLastin interfaceChannelPipeline- Returns:
- the last handler.
nullif this pipeline is empty.
-
get
public ChannelHandler get(java.lang.String name)
Description copied from interface:ChannelPipelineReturns theChannelHandlerwith the specified name in this pipeline.- Specified by:
getin interfaceChannelPipeline- Returns:
- the handler with the specified name.
nullif there's no such handler in this pipeline.
-
get
public <T extends ChannelHandler> T get(java.lang.Class<T> handlerType)
Description copied from interface:ChannelPipelineReturns theChannelHandlerof the specified type in this pipeline.- Specified by:
getin interfaceChannelPipeline- Returns:
- the handler of the specified handler type.
nullif there's no such handler in this pipeline.
-
getContext
public ChannelHandlerContext getContext(java.lang.String name)
Description copied from interface:ChannelPipelineReturns the context object of theChannelHandlerwith the specified name in this pipeline.- Specified by:
getContextin interfaceChannelPipeline- Returns:
- the context object of the handler with the specified name.
nullif there's no such handler in this pipeline.
-
getContext
public ChannelHandlerContext getContext(ChannelHandler handler)
Description copied from interface:ChannelPipelineReturns the context object of the specifiedChannelHandlerin this pipeline.- Specified by:
getContextin interfaceChannelPipeline- Returns:
- the context object of the specified handler.
nullif there's no such handler in this pipeline.
-
getContext
public ChannelHandlerContext getContext(java.lang.Class<? extends ChannelHandler> handlerType)
Description copied from interface:ChannelPipelineReturns the context object of theChannelHandlerof the specified type in this pipeline.- Specified by:
getContextin interfaceChannelPipeline- Returns:
- the context object of the handler of the specified type.
nullif there's no such handler in this pipeline.
-
getNames
public java.util.List<java.lang.String> getNames()
Description copied from interface:ChannelPipelineReturns theListof the handler names.- Specified by:
getNamesin interfaceChannelPipeline
-
toMap
public java.util.Map<java.lang.String,ChannelHandler> toMap()
Description copied from interface:ChannelPipelineConverts this pipeline into an orderedMapwhose keys are handler names and whose values are handlers.- Specified by:
toMapin interfaceChannelPipeline
-
toString
public java.lang.String toString()
Returns theStringrepresentation of this pipeline.- Overrides:
toStringin classjava.lang.Object
-
sendUpstream
public void sendUpstream(ChannelEvent e)
Description copied from interface:ChannelPipelineSends the specifiedChannelEventto the firstChannelUpstreamHandlerin this pipeline.- Specified by:
sendUpstreamin interfaceChannelPipeline
-
sendUpstream
void sendUpstream(DefaultChannelPipeline.DefaultChannelHandlerContext ctx, ChannelEvent e)
-
sendDownstream
public void sendDownstream(ChannelEvent e)
Description copied from interface:ChannelPipelineSends the specifiedChannelEventto the lastChannelDownstreamHandlerin this pipeline.- Specified by:
sendDownstreamin 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:ChannelPipelineSchedules the specified task to be executed in the I/O thread associated with this pipeline'sChannel.- Specified by:
executein 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)
-
-