Package org.jboss.netty.channel
Class Channels
java.lang.Object
org.jboss.netty.channel.Channels
A helper class which provides various convenience methods related with
Channel, ChannelHandler, and ChannelPipeline.
Factory methods
It is always recommended to use the factory methods provided by
Channels rather than calling the constructor of the implementation
types.
pipeline()pipeline(ChannelPipeline)pipelineFactory(ChannelPipeline)succeededFuture(Channel)failedFuture(Channel, Throwable)
Upstream and downstream event generation
Various event generation methods are provided to simplify the generation of
upstream events and downstream events. It is always recommended to use the
event generation methods provided by Channels rather than calling
ChannelHandlerContext.sendUpstream(ChannelEvent) or
ChannelHandlerContext.sendDownstream(ChannelEvent) by yourself.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidbind(ChannelHandlerContext ctx, ChannelFuture future, SocketAddress localAddress) Sends a"bind"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.static ChannelFuturebind(Channel channel, SocketAddress localAddress) Sends a"bind"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.static ChannelFutureSends a"close"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.static voidclose(ChannelHandlerContext ctx, ChannelFuture future) Sends a"close"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.static voidconnect(ChannelHandlerContext ctx, ChannelFuture future, SocketAddress remoteAddress) Sends a"connect"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.static ChannelFutureconnect(Channel channel, SocketAddress remoteAddress) Sends a"connect"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.static ChannelFuturedisconnect(Channel channel) Sends a"disconnect"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.static voiddisconnect(ChannelHandlerContext ctx, ChannelFuture future) Sends a"disconnect"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.static ChannelFuturefailedFuture(Channel channel, Throwable cause) Creates a newChannelFuturewhich has failed already for the specifiedChannel.private static intfilterDownstreamInterestOps(int interestOps) static voidfireChannelBound(ChannelHandlerContext ctx, SocketAddress localAddress) Sends a"channelBound"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static voidfireChannelBound(Channel channel, SocketAddress localAddress) Sends a"channelBound"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static voidfireChannelClosed(Channel channel) Sends a"channelClosed"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static voidSends a"channelClosed"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static ChannelFuturefireChannelClosedLater(Channel channel) Sends a"channelClosed"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again.static voidfireChannelConnected(ChannelHandlerContext ctx, SocketAddress remoteAddress) Sends a"channelConnected"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static voidfireChannelConnected(Channel channel, SocketAddress remoteAddress) Sends a"channelConnected"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static voidfireChannelDisconnected(Channel channel) Sends a"channelDisconnected"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static voidSends a"channelDisconnected"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static ChannelFuturefireChannelDisconnectedLater(Channel channel) Sends a"channelDisconnected"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again.static voidfireChannelInterestChanged(Channel channel) Sends a"channelInterestChanged"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static voidSends a"channelInterestChanged"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static ChannelFuturefireChannelInterestChangedLater(Channel channel) Sends a"channelInterestChanged"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again.static voidfireChannelOpen(Channel channel) Sends a"channelOpen"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static voidSends a"channelOpen"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static voidfireChannelUnbound(Channel channel) Sends a"channelUnbound"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static voidSends a"channelUnbound"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static ChannelFuturefireChannelUnboundLater(Channel channel) Sends a"channelUnbound"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again.private static voidfireChildChannelStateChanged(Channel channel, Channel childChannel) static voidfireExceptionCaught(ChannelHandlerContext ctx, Throwable cause) Sends a"exceptionCaught"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static voidfireExceptionCaught(Channel channel, Throwable cause) Sends a"exceptionCaught"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static ChannelFuturefireExceptionCaughtLater(ChannelHandlerContext ctx, Throwable cause) Sends a"exceptionCaught"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContextonce the io-thread runs again.static ChannelFuturefireExceptionCaughtLater(Channel channel, Throwable cause) Sends a"exceptionCaught"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again.static voidfireMessageReceived(ChannelHandlerContext ctx, Object message) Sends a"messageReceived"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static voidfireMessageReceived(ChannelHandlerContext ctx, Object message, SocketAddress remoteAddress) Sends a"messageReceived"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static voidfireMessageReceived(Channel channel, Object message) Sends a"messageReceived"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static voidfireMessageReceived(Channel channel, Object message, SocketAddress remoteAddress) Sends a"messageReceived"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelbelongs.static voidfireWriteComplete(ChannelHandlerContext ctx, long amount) Sends a"writeComplete"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.static voidfireWriteComplete(Channel channel, long amount) Sends a"writeComplete"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.static ChannelFuturefireWriteCompleteLater(Channel channel, long amount) Sends a"writeComplete"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelin the next io-thread.static ChannelFutureCreates a new non-cancellableChannelFuturefor the specifiedChannel.static ChannelFutureCreates a newChannelFuturefor the specifiedChannel.static ChannelPipelinepipeline()Creates a newChannelPipeline.static ChannelPipelinepipeline(ChannelHandler... handlers) Creates a newChannelPipelinewhich contains the specifiedChannelHandlers.static ChannelPipelinepipeline(ChannelPipeline pipeline) Creates a newChannelPipelinewhich contains the same entries with the specifiedpipeline.static ChannelPipelineFactorypipelineFactory(ChannelPipeline pipeline) Creates a newChannelPipelineFactorywhich creates a newChannelPipelinewhich contains the same entries with the specifiedpipeline.static voidsetInterestOps(ChannelHandlerContext ctx, ChannelFuture future, int interestOps) Sends a"setInterestOps"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.static ChannelFuturesetInterestOps(Channel channel, int interestOps) Sends a"setInterestOps"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.static ChannelFuturesucceededFuture(Channel channel) Creates a newChannelFuturewhich is already succeeded for the specifiedChannel.static ChannelFutureSends a"unbind"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.static voidunbind(ChannelHandlerContext ctx, ChannelFuture future) Sends a"unbind"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.private static voidvalidateInterestOps(int interestOps) static voidwrite(ChannelHandlerContext ctx, ChannelFuture future, Object message) Sends a"write"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.static voidwrite(ChannelHandlerContext ctx, ChannelFuture future, Object message, SocketAddress remoteAddress) Sends a"write"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.static ChannelFutureSends a"write"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.static ChannelFuturewrite(Channel channel, Object message, SocketAddress remoteAddress) Sends a"write"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.
-
Constructor Details
-
Channels
private Channels()
-
-
Method Details
-
pipeline
Creates a newChannelPipeline. -
pipeline
Creates a newChannelPipelinewhich contains the specifiedChannelHandlers. The names of the specified handlers are generated automatically; the first handler's name is"0", the second handler's name is"1", the third handler's name is"2", and so on. -
pipeline
Creates a newChannelPipelinewhich contains the same entries with the specifiedpipeline. Please note that only the names and the references of theChannelHandlers will be copied; a newChannelHandlerinstance will never be created. -
pipelineFactory
Creates a newChannelPipelineFactorywhich creates a newChannelPipelinewhich contains the same entries with the specifiedpipeline. Please note that only the names and the references of theChannelHandlers will be copied; a newChannelHandlerinstance will never be created. -
future
Creates a new non-cancellableChannelFuturefor the specifiedChannel. -
future
Creates a newChannelFuturefor the specifiedChannel.- Parameters:
cancellable-trueif and only if the returned future can be canceled byChannelFuture.cancel()
-
succeededFuture
Creates a newChannelFuturewhich is already succeeded for the specifiedChannel. -
failedFuture
Creates a newChannelFuturewhich has failed already for the specifiedChannel.- Parameters:
cause- the cause of the failure
-
fireChannelOpen
Sends a"channelOpen"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel. If the specified channel has a parent, a"childChannelOpen"event will be sent, too. -
fireChannelOpen
Sends a"channelOpen"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.Please note that this method does not trigger a
"childChannelOpen"event unlikefireChannelOpen(Channel)method. -
fireChannelBound
Sends a"channelBound"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
localAddress- the local address where the specified channel is bound
-
fireChannelBound
Sends a"channelBound"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
localAddress- the local address where the specified channel is bound
-
fireChannelConnected
Sends a"channelConnected"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
remoteAddress- the remote address where the specified channel is connected
-
fireChannelConnected
Sends a"channelConnected"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
remoteAddress- the remote address where the specified channel is connected
-
fireMessageReceived
Sends a"messageReceived"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
message- the received message
-
fireMessageReceived
public static void fireMessageReceived(Channel channel, Object message, SocketAddress remoteAddress) Sends a"messageReceived"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelbelongs.- Parameters:
message- the received messageremoteAddress- the remote address where the received message came from
-
fireMessageReceived
Sends a"messageReceived"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
message- the received message
-
fireMessageReceived
public static void fireMessageReceived(ChannelHandlerContext ctx, Object message, SocketAddress remoteAddress) Sends a"messageReceived"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
message- the received messageremoteAddress- the remote address where the received message came from
-
fireWriteCompleteLater
Sends a"writeComplete"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelin the next io-thread. -
fireWriteComplete
Sends a"writeComplete"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel. -
fireWriteComplete
Sends a"writeComplete"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext. -
fireChannelInterestChangedLater
Sends a"channelInterestChanged"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again. -
fireChannelInterestChanged
Sends a"channelInterestChanged"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel. -
fireChannelInterestChanged
Sends a"channelInterestChanged"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext. -
fireChannelDisconnectedLater
Sends a"channelDisconnected"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again. -
fireChannelDisconnected
Sends a"channelDisconnected"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel. -
fireChannelDisconnected
Sends a"channelDisconnected"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext. -
fireChannelUnboundLater
Sends a"channelUnbound"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again. -
fireChannelUnbound
Sends a"channelUnbound"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel. -
fireChannelUnbound
Sends a"channelUnbound"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext. -
fireChannelClosedLater
Sends a"channelClosed"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again. -
fireChannelClosed
Sends a"channelClosed"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel. -
fireChannelClosed
Sends a"channelClosed"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext. -
fireExceptionCaughtLater
Sends a"exceptionCaught"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannelonce the io-thread runs again. -
fireExceptionCaughtLater
Sends a"exceptionCaught"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContextonce the io-thread runs again. -
fireExceptionCaught
Sends a"exceptionCaught"event to the firstChannelUpstreamHandlerin theChannelPipelineof the specifiedChannel. -
fireExceptionCaught
Sends a"exceptionCaught"event to theChannelUpstreamHandlerwhich is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext. -
fireChildChannelStateChanged
-
bind
Sends a"bind"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
channel- the channel to bindlocalAddress- the local address to bind to- Returns:
- the
ChannelFuturewhich will be notified when the bind operation is done
-
bind
public static void bind(ChannelHandlerContext ctx, ChannelFuture future, SocketAddress localAddress) Sends a"bind"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
ctx- the contextfuture- the future which will be notified when the bind operation is donelocalAddress- the local address to bind to
-
unbind
Sends a"unbind"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
ctx- the contextfuture- the future which will be notified when the unbind operation is done
-
unbind
Sends a"unbind"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
channel- the channel to unbind- Returns:
- the
ChannelFuturewhich will be notified when the unbind operation is done
-
connect
Sends a"connect"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
channel- the channel to attempt a connectionremoteAddress- the remote address to connect to- Returns:
- the
ChannelFuturewhich will be notified when the connection attempt is done
-
connect
public static void connect(ChannelHandlerContext ctx, ChannelFuture future, SocketAddress remoteAddress) Sends a"connect"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
ctx- the contextfuture- the future which will be notified when the connection attempt is doneremoteAddress- the remote address to connect to
-
write
Sends a"write"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
channel- the channel to write a messagemessage- the message to write to the channel- Returns:
- the
ChannelFuturewhich will be notified when the write operation is done
-
write
Sends a"write"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
ctx- the contextfuture- the future which will be notified when the write operation is done
-
write
Sends a"write"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
channel- the channel to write a messagemessage- the message to write to the channelremoteAddress- the destination of the message.nullto use the default remote address- Returns:
- the
ChannelFuturewhich will be notified when the write operation is done
-
write
public static void write(ChannelHandlerContext ctx, ChannelFuture future, Object message, SocketAddress remoteAddress) Sends a"write"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
ctx- the contextfuture- the future which will be notified when the write operation is donemessage- the message to write to the channelremoteAddress- the destination of the message.nullto use the default remote address.
-
setInterestOps
Sends a"setInterestOps"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
channel- the channel to change its interestOpsinterestOps- the new interestOps- Returns:
- the
ChannelFuturewhich will be notified when the interestOps is changed
-
setInterestOps
Sends a"setInterestOps"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
ctx- the contextfuture- the future which will be notified when the interestOps is changed.
-
disconnect
Sends a"disconnect"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
channel- the channel to disconnect- Returns:
- the
ChannelFuturewhich will be notified on disconnection
-
disconnect
Sends a"disconnect"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
ctx- the contextfuture- the future which will be notified on disconnection
-
close
Sends a"close"request to the lastChannelDownstreamHandlerin theChannelPipelineof the specifiedChannel.- Parameters:
channel- the channel to close- Returns:
- the
ChannelFuturewhich will be notified on closure
-
close
Sends a"close"request to theChannelDownstreamHandlerwhich is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext.- Parameters:
ctx- the contextfuture- the future which will be notified on closure
-
validateInterestOps
private static void validateInterestOps(int interestOps) -
filterDownstreamInterestOps
private static int filterDownstreamInterestOps(int interestOps)
-