public final class Channels extends Object
Channel
, ChannelHandler
, and ChannelPipeline
.
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)
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.
Modifier and Type | Method and Description |
---|---|
static void |
bind(ChannelHandlerContext ctx,
ChannelFuture future,
SocketAddress localAddress)
Sends a
"bind" request to the
ChannelDownstreamHandler which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext . |
static ChannelFuture |
bind(Channel channel,
SocketAddress localAddress)
Sends a
"bind" request to the last
ChannelDownstreamHandler in the ChannelPipeline of
the specified Channel . |
static ChannelFuture |
close(Channel channel)
Sends a
"close" request to the last
ChannelDownstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
close(ChannelHandlerContext ctx,
ChannelFuture future)
Sends a
"close" request to the
ChannelDownstreamHandler which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext . |
static void |
connect(ChannelHandlerContext ctx,
ChannelFuture future,
SocketAddress remoteAddress)
Sends a
"connect" request to the
ChannelDownstreamHandler which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext . |
static ChannelFuture |
connect(Channel channel,
SocketAddress remoteAddress)
Sends a
"connect" request to the last
ChannelDownstreamHandler in the ChannelPipeline of
the specified Channel . |
static ChannelFuture |
disconnect(Channel channel)
Sends a
"disconnect" request to the last
ChannelDownstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
disconnect(ChannelHandlerContext ctx,
ChannelFuture future)
Sends a
"disconnect" request to the
ChannelDownstreamHandler which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext . |
static ChannelFuture |
failedFuture(Channel channel,
Throwable cause)
Creates a new
ChannelFuture which has failed already for the
specified Channel . |
static void |
fireChannelBound(ChannelHandlerContext ctx,
SocketAddress localAddress)
Sends a
"channelBound" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static void |
fireChannelBound(Channel channel,
SocketAddress localAddress)
Sends a
"channelBound" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
fireChannelClosed(Channel channel)
Sends a
"channelClosed" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
fireChannelClosed(ChannelHandlerContext ctx)
Sends a
"channelClosed" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static ChannelFuture |
fireChannelClosedLater(Channel channel)
Sends a
"channelClosed" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel once the io-thread runs again. |
static void |
fireChannelConnected(ChannelHandlerContext ctx,
SocketAddress remoteAddress)
Sends a
"channelConnected" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static void |
fireChannelConnected(Channel channel,
SocketAddress remoteAddress)
Sends a
"channelConnected" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
fireChannelDisconnected(Channel channel)
Sends a
"channelDisconnected" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
fireChannelDisconnected(ChannelHandlerContext ctx)
Sends a
"channelDisconnected" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static ChannelFuture |
fireChannelDisconnectedLater(Channel channel)
Sends a
"channelDisconnected" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel once the io-thread runs again. |
static void |
fireChannelInterestChanged(Channel channel)
Sends a
"channelInterestChanged" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
fireChannelInterestChanged(ChannelHandlerContext ctx)
Sends a
"channelInterestChanged" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static ChannelFuture |
fireChannelInterestChangedLater(Channel channel)
Sends a
"channelInterestChanged" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel once the io-thread runs again. |
static void |
fireChannelOpen(Channel channel)
Sends a
"channelOpen" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
fireChannelOpen(ChannelHandlerContext ctx)
Sends a
"channelOpen" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static void |
fireChannelUnbound(Channel channel)
Sends a
"channelUnbound" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
fireChannelUnbound(ChannelHandlerContext ctx)
Sends a
"channelUnbound" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static ChannelFuture |
fireChannelUnboundLater(Channel channel)
Sends a
"channelUnbound" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel once the io-thread runs again. |
static void |
fireExceptionCaught(ChannelHandlerContext ctx,
Throwable cause)
Sends a
"exceptionCaught" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static void |
fireExceptionCaught(Channel channel,
Throwable cause)
Sends a
"exceptionCaught" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static ChannelFuture |
fireExceptionCaughtLater(ChannelHandlerContext ctx,
Throwable cause)
Sends a
"exceptionCaught" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext once the io-thread runs again. |
static ChannelFuture |
fireExceptionCaughtLater(Channel channel,
Throwable cause)
Sends a
"exceptionCaught" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel once the io-thread runs again. |
static void |
fireMessageReceived(ChannelHandlerContext ctx,
Object message)
Sends a
"messageReceived" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static void |
fireMessageReceived(ChannelHandlerContext ctx,
Object message,
SocketAddress remoteAddress)
Sends a
"messageReceived" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static void |
fireMessageReceived(Channel channel,
Object message)
Sends a
"messageReceived" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
fireMessageReceived(Channel channel,
Object message,
SocketAddress remoteAddress)
Sends a
"messageReceived" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel belongs. |
static void |
fireWriteComplete(ChannelHandlerContext ctx,
long amount)
Sends a
"writeComplete" event to the
ChannelUpstreamHandler which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext . |
static void |
fireWriteComplete(Channel channel,
long amount)
Sends a
"writeComplete" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel . |
static ChannelFuture |
fireWriteCompleteLater(Channel channel,
long amount)
Sends a
"writeComplete" event to the first
ChannelUpstreamHandler in the ChannelPipeline of
the specified Channel in the next io-thread. |
static ChannelFuture |
future(Channel channel)
Creates a new non-cancellable
ChannelFuture for the specified
Channel . |
static ChannelFuture |
future(Channel channel,
boolean cancellable)
Creates a new
ChannelFuture for the specified Channel . |
static ChannelPipeline |
pipeline()
Creates a new
ChannelPipeline . |
static ChannelPipeline |
pipeline(ChannelHandler... handlers)
Creates a new
ChannelPipeline which contains the specified
ChannelHandler s. |
static ChannelPipeline |
pipeline(ChannelPipeline pipeline)
Creates a new
ChannelPipeline which contains the same entries
with the specified pipeline . |
static ChannelPipelineFactory |
pipelineFactory(ChannelPipeline pipeline)
Creates a new
ChannelPipelineFactory which creates a new
ChannelPipeline which contains the same entries with the
specified pipeline . |
static void |
setInterestOps(ChannelHandlerContext ctx,
ChannelFuture future,
int interestOps)
Sends a
"setInterestOps" request to the
ChannelDownstreamHandler which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext . |
static ChannelFuture |
setInterestOps(Channel channel,
int interestOps)
Sends a
"setInterestOps" request to the last
ChannelDownstreamHandler in the ChannelPipeline of
the specified Channel . |
static ChannelFuture |
succeededFuture(Channel channel)
Creates a new
ChannelFuture which is already succeeded for the
specified Channel . |
static ChannelFuture |
unbind(Channel channel)
Sends a
"unbind" request to the last
ChannelDownstreamHandler in the ChannelPipeline of
the specified Channel . |
static void |
unbind(ChannelHandlerContext ctx,
ChannelFuture future)
Sends a
"unbind" request to the
ChannelDownstreamHandler which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext . |
static void |
write(ChannelHandlerContext ctx,
ChannelFuture future,
Object message)
Sends a
"write" request to the
ChannelDownstreamHandler which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext . |
static void |
write(ChannelHandlerContext ctx,
ChannelFuture future,
Object message,
SocketAddress remoteAddress)
Sends a
"write" request to the
ChannelDownstreamHandler which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext . |
static ChannelFuture |
write(Channel channel,
Object message)
Sends a
"write" request to the last
ChannelDownstreamHandler in the ChannelPipeline of
the specified Channel . |
static ChannelFuture |
write(Channel channel,
Object message,
SocketAddress remoteAddress)
Sends a
"write" request to the last
ChannelDownstreamHandler in the ChannelPipeline of
the specified Channel . |
public static ChannelPipeline pipeline()
ChannelPipeline
.public static ChannelPipeline pipeline(ChannelHandler... handlers)
ChannelPipeline
which contains the specified
ChannelHandler
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.public static ChannelPipeline pipeline(ChannelPipeline pipeline)
ChannelPipeline
which contains the same entries
with the specified pipeline
. Please note that only the names
and the references of the ChannelHandler
s will be copied; a new
ChannelHandler
instance will never be created.public static ChannelPipelineFactory pipelineFactory(ChannelPipeline pipeline)
ChannelPipelineFactory
which creates a new
ChannelPipeline
which contains the same entries with the
specified pipeline
. Please note that only the names and the
references of the ChannelHandler
s will be copied; a new
ChannelHandler
instance will never be created.public static ChannelFuture future(Channel channel)
ChannelFuture
for the specified
Channel
.public static ChannelFuture future(Channel channel, boolean cancellable)
ChannelFuture
for the specified Channel
.cancellable
- true
if and only if the returned future
can be canceled by ChannelFuture.cancel()
public static ChannelFuture succeededFuture(Channel channel)
ChannelFuture
which is already succeeded for the
specified Channel
.public static ChannelFuture failedFuture(Channel channel, Throwable cause)
ChannelFuture
which has failed already for the
specified Channel
.cause
- the cause of the failurepublic static void fireChannelOpen(Channel channel)
"channelOpen"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
. If the specified channel has a parent,
a "childChannelOpen"
event will be sent, too.public static void fireChannelOpen(ChannelHandlerContext ctx)
"channelOpen"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.
Please note that this method does not trigger a
"childChannelOpen"
event unlike fireChannelOpen(Channel)
method.
public static void fireChannelBound(Channel channel, SocketAddress localAddress)
"channelBound"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
.localAddress
- the local address where the specified channel is boundpublic static void fireChannelBound(ChannelHandlerContext ctx, SocketAddress localAddress)
"channelBound"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.localAddress
- the local address where the specified channel is boundpublic static void fireChannelConnected(Channel channel, SocketAddress remoteAddress)
"channelConnected"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
.remoteAddress
- the remote address where the specified channel is connectedpublic static void fireChannelConnected(ChannelHandlerContext ctx, SocketAddress remoteAddress)
"channelConnected"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.remoteAddress
- the remote address where the specified channel is connectedpublic static void fireMessageReceived(Channel channel, Object message)
"messageReceived"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
.message
- the received messagepublic static void fireMessageReceived(Channel channel, Object message, SocketAddress remoteAddress)
"messageReceived"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
belongs.message
- the received messageremoteAddress
- the remote address where the received message
came frompublic static void fireMessageReceived(ChannelHandlerContext ctx, Object message)
"messageReceived"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.message
- the received messagepublic static void fireMessageReceived(ChannelHandlerContext ctx, Object message, SocketAddress remoteAddress)
"messageReceived"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.message
- the received messageremoteAddress
- the remote address where the received message
came frompublic static ChannelFuture fireWriteCompleteLater(Channel channel, long amount)
"writeComplete"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
in the next io-thread.public static void fireWriteComplete(Channel channel, long amount)
"writeComplete"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
.public static void fireWriteComplete(ChannelHandlerContext ctx, long amount)
"writeComplete"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.public static ChannelFuture fireChannelInterestChangedLater(Channel channel)
"channelInterestChanged"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
once the io-thread runs again.public static void fireChannelInterestChanged(Channel channel)
"channelInterestChanged"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
.public static void fireChannelInterestChanged(ChannelHandlerContext ctx)
"channelInterestChanged"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.public static ChannelFuture fireChannelDisconnectedLater(Channel channel)
"channelDisconnected"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
once the io-thread runs again.public static void fireChannelDisconnected(Channel channel)
"channelDisconnected"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
.public static void fireChannelDisconnected(ChannelHandlerContext ctx)
"channelDisconnected"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.public static ChannelFuture fireChannelUnboundLater(Channel channel)
"channelUnbound"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
once the io-thread runs again.public static void fireChannelUnbound(Channel channel)
"channelUnbound"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
.public static void fireChannelUnbound(ChannelHandlerContext ctx)
"channelUnbound"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.public static ChannelFuture fireChannelClosedLater(Channel channel)
"channelClosed"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
once the io-thread runs again.public static void fireChannelClosed(Channel channel)
"channelClosed"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
.public static void fireChannelClosed(ChannelHandlerContext ctx)
"channelClosed"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.public static ChannelFuture fireExceptionCaughtLater(Channel channel, Throwable cause)
"exceptionCaught"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
once the io-thread runs again.public static ChannelFuture fireExceptionCaughtLater(ChannelHandlerContext ctx, Throwable cause)
"exceptionCaught"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
once the io-thread runs again.public static void fireExceptionCaught(Channel channel, Throwable cause)
"exceptionCaught"
event to the first
ChannelUpstreamHandler
in the ChannelPipeline
of
the specified Channel
.public static void fireExceptionCaught(ChannelHandlerContext ctx, Throwable cause)
"exceptionCaught"
event to the
ChannelUpstreamHandler
which is placed in the closest upstream
from the handler associated with the specified
ChannelHandlerContext
.public static ChannelFuture bind(Channel channel, SocketAddress localAddress)
"bind"
request to the last
ChannelDownstreamHandler
in the ChannelPipeline
of
the specified Channel
.channel
- the channel to bindlocalAddress
- the local address to bind toChannelFuture
which will be notified when the
bind operation is donepublic static void bind(ChannelHandlerContext ctx, ChannelFuture future, SocketAddress localAddress)
"bind"
request to the
ChannelDownstreamHandler
which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext
.ctx
- the contextfuture
- the future which will be notified when the bind
operation is donelocalAddress
- the local address to bind topublic static void unbind(ChannelHandlerContext ctx, ChannelFuture future)
"unbind"
request to the
ChannelDownstreamHandler
which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext
.ctx
- the contextfuture
- the future which will be notified when the unbind
operation is donepublic static ChannelFuture unbind(Channel channel)
"unbind"
request to the last
ChannelDownstreamHandler
in the ChannelPipeline
of
the specified Channel
.channel
- the channel to unbindChannelFuture
which will be notified when the
unbind operation is donepublic static ChannelFuture connect(Channel channel, SocketAddress remoteAddress)
"connect"
request to the last
ChannelDownstreamHandler
in the ChannelPipeline
of
the specified Channel
.channel
- the channel to attempt a connectionremoteAddress
- the remote address to connect toChannelFuture
which will be notified when the
connection attempt is donepublic static void connect(ChannelHandlerContext ctx, ChannelFuture future, SocketAddress remoteAddress)
"connect"
request to the
ChannelDownstreamHandler
which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext
.ctx
- the contextfuture
- the future which will be notified when the connection
attempt is doneremoteAddress
- the remote address to connect topublic static ChannelFuture write(Channel channel, Object message)
"write"
request to the last
ChannelDownstreamHandler
in the ChannelPipeline
of
the specified Channel
.channel
- the channel to write a messagemessage
- the message to write to the channelChannelFuture
which will be notified when the
write operation is donepublic static void write(ChannelHandlerContext ctx, ChannelFuture future, Object message)
"write"
request to the
ChannelDownstreamHandler
which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext
.ctx
- the contextfuture
- the future which will be notified when the write
operation is donepublic static ChannelFuture write(Channel channel, Object message, SocketAddress remoteAddress)
"write"
request to the last
ChannelDownstreamHandler
in the ChannelPipeline
of
the specified Channel
.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 addressChannelFuture
which will be notified when the
write operation is donepublic static void write(ChannelHandlerContext ctx, ChannelFuture future, Object message, SocketAddress remoteAddress)
"write"
request to the
ChannelDownstreamHandler
which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext
.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.public static ChannelFuture setInterestOps(Channel channel, int interestOps)
"setInterestOps"
request to the last
ChannelDownstreamHandler
in the ChannelPipeline
of
the specified Channel
.channel
- the channel to change its interestOpsinterestOps
- the new interestOpsChannelFuture
which will be notified when the
interestOps is changedpublic static void setInterestOps(ChannelHandlerContext ctx, ChannelFuture future, int interestOps)
"setInterestOps"
request to the
ChannelDownstreamHandler
which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext
.ctx
- the contextfuture
- the future which will be notified when the interestOps is
changed.public static ChannelFuture disconnect(Channel channel)
"disconnect"
request to the last
ChannelDownstreamHandler
in the ChannelPipeline
of
the specified Channel
.channel
- the channel to disconnectChannelFuture
which will be notified on disconnectionpublic static void disconnect(ChannelHandlerContext ctx, ChannelFuture future)
"disconnect"
request to the
ChannelDownstreamHandler
which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext
.ctx
- the contextfuture
- the future which will be notified on disconnectionpublic static ChannelFuture close(Channel channel)
"close"
request to the last
ChannelDownstreamHandler
in the ChannelPipeline
of
the specified Channel
.channel
- the channel to closeChannelFuture
which will be notified on closurepublic static void close(ChannelHandlerContext ctx, ChannelFuture future)
"close"
request to the
ChannelDownstreamHandler
which is placed in the closest
downstream from the handler associated with the specified
ChannelHandlerContext
.ctx
- the contextfuture
- the future which will be notified on closureCopyright © 2008-2014 The Netty Project. All Rights Reserved.