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 void
bind
(ChannelHandlerContext ctx, ChannelFuture future, SocketAddress localAddress) Sends a"bind"
request to theChannelDownstreamHandler
which is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext
.static ChannelFuture
bind
(Channel channel, SocketAddress localAddress) Sends a"bind"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.static ChannelFuture
Sends a"close"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
close
(ChannelHandlerContext ctx, ChannelFuture future) Sends a"close"
request to theChannelDownstreamHandler
which is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext
.static void
connect
(ChannelHandlerContext ctx, ChannelFuture future, SocketAddress remoteAddress) Sends a"connect"
request to theChannelDownstreamHandler
which is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext
.static ChannelFuture
connect
(Channel channel, SocketAddress remoteAddress) Sends a"connect"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.static ChannelFuture
disconnect
(Channel channel) Sends a"disconnect"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
disconnect
(ChannelHandlerContext ctx, ChannelFuture future) Sends a"disconnect"
request to theChannelDownstreamHandler
which is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext
.static ChannelFuture
failedFuture
(Channel channel, Throwable cause) Creates a newChannelFuture
which has failed already for the specifiedChannel
.private static int
filterDownstreamInterestOps
(int interestOps) static void
fireChannelBound
(ChannelHandlerContext ctx, SocketAddress localAddress) Sends a"channelBound"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static void
fireChannelBound
(Channel channel, SocketAddress localAddress) Sends a"channelBound"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
fireChannelClosed
(Channel channel) Sends a"channelClosed"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
Sends a"channelClosed"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static ChannelFuture
fireChannelClosedLater
(Channel channel) Sends a"channelClosed"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again.static void
fireChannelConnected
(ChannelHandlerContext ctx, SocketAddress remoteAddress) Sends a"channelConnected"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static void
fireChannelConnected
(Channel channel, SocketAddress remoteAddress) Sends a"channelConnected"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
fireChannelDisconnected
(Channel channel) Sends a"channelDisconnected"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
Sends a"channelDisconnected"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static ChannelFuture
fireChannelDisconnectedLater
(Channel channel) Sends a"channelDisconnected"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again.static void
fireChannelInterestChanged
(Channel channel) Sends a"channelInterestChanged"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
Sends a"channelInterestChanged"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static ChannelFuture
fireChannelInterestChangedLater
(Channel channel) Sends a"channelInterestChanged"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again.static void
fireChannelOpen
(Channel channel) Sends a"channelOpen"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
Sends a"channelOpen"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static void
fireChannelUnbound
(Channel channel) Sends a"channelUnbound"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
Sends a"channelUnbound"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static ChannelFuture
fireChannelUnboundLater
(Channel channel) Sends a"channelUnbound"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again.private static void
fireChildChannelStateChanged
(Channel channel, Channel childChannel) static void
fireExceptionCaught
(ChannelHandlerContext ctx, Throwable cause) Sends a"exceptionCaught"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static void
fireExceptionCaught
(Channel channel, Throwable cause) Sends a"exceptionCaught"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static ChannelFuture
fireExceptionCaughtLater
(ChannelHandlerContext ctx, Throwable cause) Sends a"exceptionCaught"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
once the io-thread runs again.static ChannelFuture
fireExceptionCaughtLater
(Channel channel, Throwable cause) Sends a"exceptionCaught"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again.static void
fireMessageReceived
(ChannelHandlerContext ctx, Object message) Sends a"messageReceived"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static void
fireMessageReceived
(ChannelHandlerContext ctx, Object message, SocketAddress remoteAddress) Sends a"messageReceived"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static void
fireMessageReceived
(Channel channel, Object message) Sends a"messageReceived"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
fireMessageReceived
(Channel channel, Object message, SocketAddress remoteAddress) Sends a"messageReceived"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
belongs.static void
fireWriteComplete
(ChannelHandlerContext ctx, long amount) Sends a"writeComplete"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
.static void
fireWriteComplete
(Channel channel, long amount) Sends a"writeComplete"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.static ChannelFuture
fireWriteCompleteLater
(Channel channel, long amount) Sends a"writeComplete"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
in the next io-thread.static ChannelFuture
Creates a new non-cancellableChannelFuture
for the specifiedChannel
.static ChannelFuture
Creates a newChannelFuture
for the specifiedChannel
.static ChannelPipeline
pipeline()
Creates a newChannelPipeline
.static ChannelPipeline
pipeline
(ChannelHandler... handlers) Creates a newChannelPipeline
which contains the specifiedChannelHandler
s.static ChannelPipeline
pipeline
(ChannelPipeline pipeline) Creates a newChannelPipeline
which contains the same entries with the specifiedpipeline
.static ChannelPipelineFactory
pipelineFactory
(ChannelPipeline pipeline) Creates a newChannelPipelineFactory
which creates a newChannelPipeline
which contains the same entries with the specifiedpipeline
.static void
setInterestOps
(ChannelHandlerContext ctx, ChannelFuture future, int interestOps) Sends a"setInterestOps"
request to theChannelDownstreamHandler
which is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext
.static ChannelFuture
setInterestOps
(Channel channel, int interestOps) Sends a"setInterestOps"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.static ChannelFuture
succeededFuture
(Channel channel) Creates a newChannelFuture
which is already succeeded for the specifiedChannel
.static ChannelFuture
Sends a"unbind"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.static void
unbind
(ChannelHandlerContext ctx, ChannelFuture future) Sends a"unbind"
request to theChannelDownstreamHandler
which is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext
.private static void
validateInterestOps
(int interestOps) static void
write
(ChannelHandlerContext ctx, ChannelFuture future, Object message) Sends a"write"
request to theChannelDownstreamHandler
which is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext
.static void
write
(ChannelHandlerContext ctx, ChannelFuture future, Object message, SocketAddress remoteAddress) Sends a"write"
request to theChannelDownstreamHandler
which is placed in the closest downstream from the handler associated with the specifiedChannelHandlerContext
.static ChannelFuture
Sends a"write"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.static ChannelFuture
write
(Channel channel, Object message, SocketAddress remoteAddress) Sends a"write"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.
-
Constructor Details
-
Channels
private Channels()
-
-
Method Details
-
pipeline
Creates a newChannelPipeline
. -
pipeline
Creates a newChannelPipeline
which contains the specifiedChannelHandler
s. 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 newChannelPipeline
which contains the same entries with the specifiedpipeline
. Please note that only the names and the references of theChannelHandler
s will be copied; a newChannelHandler
instance will never be created. -
pipelineFactory
Creates a newChannelPipelineFactory
which creates a newChannelPipeline
which contains the same entries with the specifiedpipeline
. Please note that only the names and the references of theChannelHandler
s will be copied; a newChannelHandler
instance will never be created. -
future
Creates a new non-cancellableChannelFuture
for the specifiedChannel
. -
future
Creates a newChannelFuture
for the specifiedChannel
.- Parameters:
cancellable
-true
if and only if the returned future can be canceled byChannelFuture.cancel()
-
succeededFuture
Creates a newChannelFuture
which is already succeeded for the specifiedChannel
. -
failedFuture
Creates a newChannelFuture
which has failed already for the specifiedChannel
.- Parameters:
cause
- the cause of the failure
-
fireChannelOpen
Sends a"channelOpen"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
. If the specified channel has a parent, a"childChannelOpen"
event will be sent, too. -
fireChannelOpen
Sends a"channelOpen"
event to theChannelUpstreamHandler
which 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 firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
localAddress
- the local address where the specified channel is bound
-
fireChannelBound
Sends a"channelBound"
event to theChannelUpstreamHandler
which 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 firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
remoteAddress
- the remote address where the specified channel is connected
-
fireChannelConnected
Sends a"channelConnected"
event to theChannelUpstreamHandler
which 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 firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
message
- the received message
-
fireMessageReceived
public static void fireMessageReceived(Channel channel, Object message, SocketAddress remoteAddress) Sends a"messageReceived"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
belongs.- Parameters:
message
- the received messageremoteAddress
- the remote address where the received message came from
-
fireMessageReceived
Sends a"messageReceived"
event to theChannelUpstreamHandler
which 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 theChannelUpstreamHandler
which 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 firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
in the next io-thread. -
fireWriteComplete
Sends a"writeComplete"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
. -
fireWriteComplete
Sends a"writeComplete"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
. -
fireChannelInterestChangedLater
Sends a"channelInterestChanged"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again. -
fireChannelInterestChanged
Sends a"channelInterestChanged"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
. -
fireChannelInterestChanged
Sends a"channelInterestChanged"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
. -
fireChannelDisconnectedLater
Sends a"channelDisconnected"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again. -
fireChannelDisconnected
Sends a"channelDisconnected"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
. -
fireChannelDisconnected
Sends a"channelDisconnected"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
. -
fireChannelUnboundLater
Sends a"channelUnbound"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again. -
fireChannelUnbound
Sends a"channelUnbound"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
. -
fireChannelUnbound
Sends a"channelUnbound"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
. -
fireChannelClosedLater
Sends a"channelClosed"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again. -
fireChannelClosed
Sends a"channelClosed"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
. -
fireChannelClosed
Sends a"channelClosed"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
. -
fireExceptionCaughtLater
Sends a"exceptionCaught"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
once the io-thread runs again. -
fireExceptionCaughtLater
Sends a"exceptionCaught"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
once the io-thread runs again. -
fireExceptionCaught
Sends a"exceptionCaught"
event to the firstChannelUpstreamHandler
in theChannelPipeline
of the specifiedChannel
. -
fireExceptionCaught
Sends a"exceptionCaught"
event to theChannelUpstreamHandler
which is placed in the closest upstream from the handler associated with the specifiedChannelHandlerContext
. -
fireChildChannelStateChanged
-
bind
Sends a"bind"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
channel
- the channel to bindlocalAddress
- the local address to bind to- Returns:
- the
ChannelFuture
which 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 theChannelDownstreamHandler
which 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 theChannelDownstreamHandler
which 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 lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
channel
- the channel to unbind- Returns:
- the
ChannelFuture
which will be notified when the unbind operation is done
-
connect
Sends a"connect"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
channel
- the channel to attempt a connectionremoteAddress
- the remote address to connect to- Returns:
- the
ChannelFuture
which 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 theChannelDownstreamHandler
which 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 lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
channel
- the channel to write a messagemessage
- the message to write to the channel- Returns:
- the
ChannelFuture
which will be notified when the write operation is done
-
write
Sends a"write"
request to theChannelDownstreamHandler
which 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 lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
channel
- the channel to write a messagemessage
- the message to write to the channelremoteAddress
- the destination of the message.null
to use the default remote address- Returns:
- the
ChannelFuture
which 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 theChannelDownstreamHandler
which 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.null
to use the default remote address.
-
setInterestOps
Sends a"setInterestOps"
request to the lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
channel
- the channel to change its interestOpsinterestOps
- the new interestOps- Returns:
- the
ChannelFuture
which will be notified when the interestOps is changed
-
setInterestOps
Sends a"setInterestOps"
request to theChannelDownstreamHandler
which 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 lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
channel
- the channel to disconnect- Returns:
- the
ChannelFuture
which will be notified on disconnection
-
disconnect
Sends a"disconnect"
request to theChannelDownstreamHandler
which 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 lastChannelDownstreamHandler
in theChannelPipeline
of the specifiedChannel
.- Parameters:
channel
- the channel to close- Returns:
- the
ChannelFuture
which will be notified on closure
-
close
Sends a"close"
request to theChannelDownstreamHandler
which 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)
-