org.jboss.netty.channel
Class Channels

java.lang.Object
  extended by org.jboss.netty.channel.Channels

public class Channels
extends Object

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.

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.

Version:
$Rev: 2210 $, $Date: 2010-03-04 08:11:39 +0900 (Thu, 04 Mar 2010) $
Author:
The Netty Project, Trustin Lee

Method Summary
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 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 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 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 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 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 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 ChannelHandlers.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

pipeline

public static ChannelPipeline pipeline()
Creates a new ChannelPipeline.


pipeline

public static ChannelPipeline pipeline(ChannelHandler... handlers)
Creates a new ChannelPipeline which contains the specified ChannelHandlers. 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

public static ChannelPipeline pipeline(ChannelPipeline pipeline)
Creates a new ChannelPipeline which contains the same entries with the specified pipeline. Please note that only the names and the references of the ChannelHandlers will be copied; a new ChannelHandler instance will never be created.


pipelineFactory

public static ChannelPipelineFactory pipelineFactory(ChannelPipeline pipeline)
Creates a new 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 ChannelHandlers will be copied; a new ChannelHandler instance will never be created.


future

public static ChannelFuture future(Channel channel)
Creates a new non-cancellable ChannelFuture for the specified Channel.


future

public static ChannelFuture future(Channel channel,
                                   boolean cancellable)
Creates a new ChannelFuture for the specified Channel.

Parameters:
cancellable - true if and only if the returned future can be canceled by ChannelFuture.cancel()

succeededFuture

public static ChannelFuture succeededFuture(Channel channel)
Creates a new ChannelFuture which is already succeeded for the specified Channel.


failedFuture

public static ChannelFuture failedFuture(Channel channel,
                                         Throwable cause)
Creates a new ChannelFuture which has failed already for the specified Channel.

Parameters:
cause - the cause of the failure

fireChannelOpen

public static void fireChannelOpen(Channel channel)
Sends a "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.


fireChannelOpen

public 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.

Please note that this method does not trigger a "childChannelOpen" event unlike fireChannelOpen(Channel) method.


fireChannelBound

public static void fireChannelBound(Channel channel,
                                    SocketAddress localAddress)
Sends a "channelBound" event to the first ChannelUpstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
localAddress - the local address where the specified channel is bound

fireChannelBound

public 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.

Parameters:
localAddress - the local address where the specified channel is bound

fireChannelConnected

public static void fireChannelConnected(Channel channel,
                                        SocketAddress remoteAddress)
Sends a "channelConnected" event to the first ChannelUpstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
remoteAddress - the remote address where the specified channel is connected

fireChannelConnected

public 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.

Parameters:
remoteAddress - the remote address where the specified channel is connected

fireMessageReceived

public static void fireMessageReceived(Channel channel,
                                       Object message)
Sends a "messageReceived" event to the first ChannelUpstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
message - the received message

fireMessageReceived

public 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.

Parameters:
message - the received message
remoteAddress - the remote address where the received message came from

fireMessageReceived

public 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.

Parameters:
message - the received message

fireMessageReceived

public 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.

Parameters:
message - the received message
remoteAddress - the remote address where the received message came from

fireWriteComplete

public static void fireWriteComplete(Channel channel,
                                     long amount)
Sends a "writeComplete" event to the first ChannelUpstreamHandler in the ChannelPipeline of the specified Channel.


fireWriteComplete

public 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.


fireChannelInterestChanged

public static void fireChannelInterestChanged(Channel channel)
Sends a "channelInterestChanged" event to the first ChannelUpstreamHandler in the ChannelPipeline of the specified Channel.


fireChannelInterestChanged

public 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.


fireChannelDisconnected

public static void fireChannelDisconnected(Channel channel)
Sends a "channelDisconnected" event to the first ChannelUpstreamHandler in the ChannelPipeline of the specified Channel.


fireChannelDisconnected

public 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.


fireChannelUnbound

public static void fireChannelUnbound(Channel channel)
Sends a "channelUnbound" event to the first ChannelUpstreamHandler in the ChannelPipeline of the specified Channel.


fireChannelUnbound

public 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.


fireChannelClosed

public static void fireChannelClosed(Channel channel)
Sends a "channelClosed" event to the first ChannelUpstreamHandler in the ChannelPipeline of the specified Channel.


fireChannelClosed

public 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.


fireExceptionCaught

public static void fireExceptionCaught(Channel channel,
                                       Throwable cause)
Sends a "exceptionCaught" event to the first ChannelUpstreamHandler in the ChannelPipeline of the specified Channel.


fireExceptionCaught

public 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.


bind

public static ChannelFuture bind(Channel channel,
                                 SocketAddress localAddress)
Sends a "bind" request to the last ChannelDownstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
channel - the channel to bind
localAddress - 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 the ChannelDownstreamHandler which is placed in the closest downstream from the handler associated with the specified ChannelHandlerContext.

Parameters:
ctx - the context
future - the future which will be notified when the bind operation is done
localAddress - the local address to bind to

unbind

public 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.

Parameters:
ctx - the context
future - the future which will be notified when the unbind operation is done

unbind

public static ChannelFuture unbind(Channel channel)
Sends a "unbind" request to the last ChannelDownstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
channel - the channel to unbind
Returns:
the ChannelFuture which will be notified when the unbind operation is done

connect

public static ChannelFuture connect(Channel channel,
                                    SocketAddress remoteAddress)
Sends a "connect" request to the last ChannelDownstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
channel - the channel to attempt a connection
remoteAddress - 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 the ChannelDownstreamHandler which is placed in the closest downstream from the handler associated with the specified ChannelHandlerContext.

Parameters:
ctx - the context
future - the future which will be notified when the connection attempt is done
remoteAddress - the remote address to connect to

write

public static ChannelFuture write(Channel channel,
                                  Object message)
Sends a "write" request to the last ChannelDownstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
channel - the channel to write a message
message - the message to write to the channel
Returns:
the ChannelFuture which will be notified when the write operation is done

write

public 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.

Parameters:
ctx - the context
future - the future which will be notified when the write operation is done

write

public static ChannelFuture write(Channel channel,
                                  Object message,
                                  SocketAddress remoteAddress)
Sends a "write" request to the last ChannelDownstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
channel - the channel to write a message
message - the message to write to the channel
remoteAddress - 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 the ChannelDownstreamHandler which is placed in the closest downstream from the handler associated with the specified ChannelHandlerContext.

Parameters:
ctx - the context
future - the future which will be notified when the write operation is done
message - the message to write to the channel
remoteAddress - the destination of the message. null to use the default remote address.

setInterestOps

public static ChannelFuture setInterestOps(Channel channel,
                                           int interestOps)
Sends a "setInterestOps" request to the last ChannelDownstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
channel - the channel to change its interestOps
interestOps - the new interestOps
Returns:
the ChannelFuture which will be notified when the interestOps is changed

setInterestOps

public 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.

Parameters:
ctx - the context
future - the future which will be notified when the interestOps is changed.

disconnect

public static ChannelFuture disconnect(Channel channel)
Sends a "disconnect" request to the last ChannelDownstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
channel - the channel to disconnect
Returns:
the ChannelFuture which will be notified on disconnection

disconnect

public 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.

Parameters:
ctx - the context
future - the future which will be notified on disconnection

close

public static ChannelFuture close(Channel channel)
Sends a "close" request to the last ChannelDownstreamHandler in the ChannelPipeline of the specified Channel.

Parameters:
channel - the channel to close
Returns:
the ChannelFuture which will be notified on closure

close

public 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.

Parameters:
ctx - the context
future - the future which will be notified on closure


Copyright © 2008-2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.