Set that contains open Channels and provides
various bulk operations on them. Using ChannelGroup, you can
categorize Channels into a meaningful group (e.g. on a per-service
or per-state basis.) A closed Channel is automatically removed from
the collection, so that you don't need to worry about the life cycle of the
added Channel. A Channel can belong to more than one
ChannelGroup.
Channels
If you need to broadcast a message to more than one Channel, you can
add the Channels associated with the recipients and call ChannelGroup#write(Object):
ChannelGrouprecipients = newDefaultChannelGroup(GlobalEventExecutor.INSTANCE); recipients.add(channelA); recipients.add(channelB); .. recipients.write(Unpooled.copiedBuffer( "Service will shut down for maintenance in 5 minutes.",CharsetUtil.UTF_8));
ChannelGroup
If both ServerChannels and non-ServerChannels exist in the
same ChannelGroup, any requested I/O operations on the group are
performed for the ServerChannels first and then for the others.
This rule is very useful when you shut down a server in one shot:
ChannelGroupallChannels = newDefaultChannelGroup(GlobalEventExecutor.INSTANCE); public static void main(String[] args) throws Exception {ServerBootstrapb = newServerBootstrap(..); ... b.childHandler(new MyHandler()); // Start the server b.getPipeline().addLast("handler", new MyHandler());ChannelserverChannel = b.bind(..).sync(); allChannels.add(serverChannel); ... Wait until the shutdown signal reception ... // Close the serverChannel and then all accepted connections. allChannels.close().awaitUninterruptibly(); } public class MyHandler extendsChannelInboundHandlerAdapter{@Overridepublic void channelActive(ChannelHandlerContextctx) { // closed on shutdown. allChannels.add(ctx.channel()); super.channelActive(ctx); } }
| Modifier and Type | Method and Description |
|---|---|
| public ChannelGroupFuture | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channelsCloses all |
| public ChannelGroupFuture | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channelsCloses all |
| public ChannelGroupFuture | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channels
Deprecated
This method will be removed in the next major feature release.
|
| public ChannelGroupFuture | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channels
Deprecated
This method will be removed in the next major feature release.
|
| public ChannelGroupFuture | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channelsDisconnects all |
| public ChannelGroupFuture | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channelsDisconnects all |
| public Channel | |
| public ChannelGroup | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channelsFlush all |
| public ChannelGroup | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channelsFlush all |
| public ChannelGroupFuture | |
| public ChannelGroupFuture | flushAndWrite(Object message, ChannelMatcher matcher)
Deprecated
Use
writeAndFlush(Object, ChannelMatcher) instead.
|
| public String | |
| public ChannelGroupFuture | newCloseFuture()
Returns the |
| public ChannelGroupFuture | newCloseFuture(ChannelMatcher matcher)
Returns the |
| public ChannelGroupFuture | |
| public ChannelGroupFuture | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channelsWrites the specified |
| public ChannelGroupFuture | Returns: theChannelGroupFuture instance that notifies when
the operation is done for all channelsWrites the specified |
| public ChannelGroupFuture | |
| public ChannelGroupFuture | writeAndFlush(Object message, ChannelMatcher matcher)
Shortcut for calling |
| public ChannelGroupFuture | writeAndFlush(Object message, ChannelMatcher matcher, boolean voidPromise)
Shortcut for calling |
| close | back to summary |
|---|---|
| public ChannelGroupFuture close() Closes all
| |
| close | back to summary |
|---|---|
| public ChannelGroupFuture close(ChannelMatcher matcher) Closes all
| |
| deregister | back to summary |
|---|---|
| public ChannelGroupFuture deregister()
Deprecated This method will be removed in the next major feature release.
Deregister all
| |
| deregister | back to summary |
|---|---|
| public ChannelGroupFuture deregister(ChannelMatcher matcher)
Deprecated This method will be removed in the next major feature release.
Deregister all
| |
| disconnect | back to summary |
|---|---|
| public ChannelGroupFuture disconnect() Disconnects all
| |
| disconnect | back to summary |
|---|---|
| public ChannelGroupFuture disconnect(ChannelMatcher matcher) Disconnects all
| |
| find | back to summary |
|---|---|
| public Channel find(ChannelId id) | |
| flush | back to summary |
|---|---|
| public ChannelGroup flush() Flush all
| |
| flush | back to summary |
|---|---|
| public ChannelGroup flush(ChannelMatcher matcher) Flush all
| |
| flushAndWrite | back to summary |
|---|---|
| public ChannelGroupFuture flushAndWrite(Object message)
Deprecated Use
| |
| flushAndWrite | back to summary |
|---|---|
| public ChannelGroupFuture flushAndWrite(Object message, ChannelMatcher matcher)
Deprecated Use
| |
| name | back to summary |
|---|---|
| public String name() Returns the name of this group. A group name is purely for helping you to distinguish one group from others. | |
| newCloseFuture | back to summary |
|---|---|
| public ChannelGroupFuture newCloseFuture() Returns the | |
| newCloseFuture | back to summary |
|---|---|
| public ChannelGroupFuture newCloseFuture(ChannelMatcher matcher) Returns the | |
| write | back to summary |
|---|---|
| public ChannelGroupFuture write(Object message) Writes the specified
| |
| write | back to summary |
|---|---|
| public ChannelGroupFuture write(Object message, ChannelMatcher matcher) Writes the specified
| |
| write | back to summary |
|---|---|
| public ChannelGroupFuture write(Object message, ChannelMatcher matcher, boolean voidPromise) Writes the specified
| |
| writeAndFlush | back to summary |
|---|---|
| public ChannelGroupFuture writeAndFlush(Object message) Shortcut for calling | |
| writeAndFlush | back to summary |
|---|---|
| public ChannelGroupFuture writeAndFlush(Object message, ChannelMatcher matcher) Shortcut for calling | |
| writeAndFlush | back to summary |
|---|---|
| public ChannelGroupFuture writeAndFlush(Object message, ChannelMatcher matcher, boolean voidPromise) Shortcut for calling | |