Class DefaultChannelGroup
java.lang.Object
- All Implemented Interfaces:
ChannelGroup, java.lang.Comparable<ChannelGroup>, java.lang.Iterable<Channel>, java.util.Collection<Channel>, java.util.Set<Channel>
The default
ChannelGroup implementation.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final EventExecutorprivate final java.lang.Stringprivate static final java.util.concurrent.atomic.AtomicIntegerprivate final ChannelFutureListenerprivate final booleanprivate final VoidChannelGroupFuture -
Constructor Summary
ConstructorsConstructorDescriptionDefaultChannelGroup(EventExecutor executor) Creates a new group with a generated name and the providedEventExecutorto notify theChannelGroupFutures.DefaultChannelGroup(EventExecutor executor, boolean stayClosed) Creates a new group with a generated name and the providedEventExecutorto notify theChannelGroupFutures.DefaultChannelGroup(java.lang.String name, EventExecutor executor) DefaultChannelGroup(java.lang.String name, EventExecutor executor, boolean stayClosed) -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidclear()close()Closes allChannels in this group.close(ChannelMatcher matcher) Closes allChannels in this group that are matched by the givenChannelMatcher.intbooleancontains(java.lang.Object o) deregister(ChannelMatcher matcher) Disconnects allChannels in this group from their remote peers.disconnect(ChannelMatcher matcher) Disconnects allChannels in this group from their remote peers, that are matched by the givenChannelMatcher.booleanequals(java.lang.Object o) flush()Flush allChannels in this group.flush(ChannelMatcher matcher) Flush allChannels in this group that are matched by the givenChannelMatcher.flushAndWrite(java.lang.Object message) flushAndWrite(java.lang.Object message, ChannelMatcher matcher) inthashCode()booleanisEmpty()java.util.Iterator<Channel> iterator()java.lang.Stringname()Returns the name of this group.Returns theChannelGroupFuturewhich will be notified when allChannels that are part of thisChannelGroup, at the time of calling, are closed.newCloseFuture(ChannelMatcher matcher) Returns theChannelGroupFuturewhich will be notified when allChannels that are part of thisChannelGroup, at the time of calling, are closed.booleanremove(java.lang.Object o) private static java.lang.ObjectsafeDuplicate(java.lang.Object message) intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] a) java.lang.StringtoString()write(java.lang.Object message) Writes the specifiedmessageto allChannels in this group.write(java.lang.Object message, ChannelMatcher matcher) Writes the specifiedmessageto allChannels in this group that are matched by the givenChannelMatcher.write(java.lang.Object message, ChannelMatcher matcher, boolean voidPromise) Writes the specifiedmessageto allChannels in this group that are matched by the givenChannelMatcher.writeAndFlush(java.lang.Object message) Shortcut for callingChannelGroup.write(Object)andChannelGroup.flush().writeAndFlush(java.lang.Object message, ChannelMatcher matcher) Shortcut for callingChannelGroup.write(Object)andChannelGroup.flush()and only act onChannels that are matched by theChannelMatcher.writeAndFlush(java.lang.Object message, ChannelMatcher matcher, boolean voidPromise) Shortcut for callingChannelGroup.write(Object, ChannelMatcher, boolean)andChannelGroup.flush()and only act onChannels that are matched by theChannelMatcher.Methods inherited from class java.util.AbstractSet
removeAllMethods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAllMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, streamMethods inherited from interface java.lang.Iterable
forEachMethods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll, spliterator
-
Field Details
-
nextId
private static final java.util.concurrent.atomic.AtomicInteger nextId -
name
private final java.lang.String name -
executor
-
serverChannels
-
nonServerChannels
-
remover
-
voidFuture
-
stayClosed
private final boolean stayClosed -
closed
private volatile boolean closed
-
-
Constructor Details
-
DefaultChannelGroup
Creates a new group with a generated name and the providedEventExecutorto notify theChannelGroupFutures. -
DefaultChannelGroup
Creates a new group with the specifiednameandEventExecutorto notify theChannelGroupFutures. Please note that different groups can have the same name, which means no duplicate check is done against group names. -
DefaultChannelGroup
Creates a new group with a generated name and the providedEventExecutorto notify theChannelGroupFutures.stayCloseddefines whether or not, this group can be closed more than once. Adding channels to a closed group will immediately close them, too. This makes it easy, to shutdown server and child channels at once. -
DefaultChannelGroup
Creates a new group with the specifiednameandEventExecutorto notify theChannelGroupFutures.stayCloseddefines whether or not, this group can be closed more than once. Adding channels to a closed group will immediately close them, too. This makes it easy, to shutdown server and child channels at once. Please note that different groups can have the same name, which means no duplicate check is done against group names.
-
-
Method Details
-
name
public java.lang.String name()Description copied from interface:ChannelGroupReturns the name of this group. A group name is purely for helping you to distinguish one group from others.- Specified by:
namein interfaceChannelGroup
-
find
Description copied from interface:ChannelGroup- Specified by:
findin interfaceChannelGroup- Returns:
- the matching
Channelif found.nullotherwise.
-
isEmpty
-
size
-
contains
-
add
-
remove
-
clear
-
iterator
-
toArray
-
toArray
-
close
Description copied from interface:ChannelGroupCloses allChannels in this group. If theChannelis connected to a remote peer or bound to a local address, it is automatically disconnected and unbound.- Specified by:
closein interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
disconnect
Description copied from interface:ChannelGroupDisconnects allChannels in this group from their remote peers.- Specified by:
disconnectin interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
deregister
- Specified by:
deregisterin interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
write
Description copied from interface:ChannelGroupWrites the specifiedmessageto allChannels in this group. If the specifiedmessageis an instance ofByteBuf, it is automatically duplicated to avoid a race condition. The same is true forByteBufHolder. Please note that this operation is asynchronous asChannel.write(Object)is.- Specified by:
writein interfaceChannelGroup- Returns:
- itself
-
safeDuplicate
private static java.lang.Object safeDuplicate(java.lang.Object message) -
write
Description copied from interface:ChannelGroupWrites the specifiedmessageto allChannels in this group that are matched by the givenChannelMatcher. If the specifiedmessageis an instance ofByteBuf, it is automatically duplicated to avoid a race condition. The same is true forByteBufHolder. Please note that this operation is asynchronous asChannel.write(Object)is.- Specified by:
writein interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
write
public ChannelGroupFuture write(java.lang.Object message, ChannelMatcher matcher, boolean voidPromise) Description copied from interface:ChannelGroupWrites the specifiedmessageto allChannels in this group that are matched by the givenChannelMatcher. If the specifiedmessageis an instance ofByteBuf, it is automatically duplicated to avoid a race condition. The same is true forByteBufHolder. Please note that this operation is asynchronous asChannel.write(Object)is. IfvoidPromiseistrueChannel.voidPromise()is used for the writes and so the same restrictions to the returnedChannelGroupFutureapply as to a void promise.- Specified by:
writein interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
flush
Description copied from interface:ChannelGroupFlush allChannels in this group. If the specifiedmessagesare an instance ofByteBuf, it is automatically duplicated to avoid a race condition. Please note that this operation is asynchronous asChannel.write(Object)is.- Specified by:
flushin interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
flushAndWrite
- Specified by:
flushAndWritein interfaceChannelGroup
-
writeAndFlush
Description copied from interface:ChannelGroupShortcut for callingChannelGroup.write(Object)andChannelGroup.flush().- Specified by:
writeAndFlushin interfaceChannelGroup
-
disconnect
Description copied from interface:ChannelGroupDisconnects allChannels in this group from their remote peers, that are matched by the givenChannelMatcher.- Specified by:
disconnectin interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
close
Description copied from interface:ChannelGroupCloses allChannels in this group that are matched by the givenChannelMatcher. If theChannelis connected to a remote peer or bound to a local address, it is automatically disconnected and unbound.- Specified by:
closein interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
deregister
- Specified by:
deregisterin interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
flush
Description copied from interface:ChannelGroupFlush allChannels in this group that are matched by the givenChannelMatcher. If the specifiedmessagesare an instance ofByteBuf, it is automatically duplicated to avoid a race condition. Please note that this operation is asynchronous asChannel.write(Object)is.- Specified by:
flushin interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
flushAndWrite
- Specified by:
flushAndWritein interfaceChannelGroup
-
writeAndFlush
Description copied from interface:ChannelGroupShortcut for callingChannelGroup.write(Object)andChannelGroup.flush()and only act onChannels that are matched by theChannelMatcher.- Specified by:
writeAndFlushin interfaceChannelGroup
-
writeAndFlush
public ChannelGroupFuture writeAndFlush(java.lang.Object message, ChannelMatcher matcher, boolean voidPromise) Description copied from interface:ChannelGroupShortcut for callingChannelGroup.write(Object, ChannelMatcher, boolean)andChannelGroup.flush()and only act onChannels that are matched by theChannelMatcher.- Specified by:
writeAndFlushin interfaceChannelGroup
-
newCloseFuture
Description copied from interface:ChannelGroupReturns theChannelGroupFuturewhich will be notified when allChannels that are part of thisChannelGroup, at the time of calling, are closed.- Specified by:
newCloseFuturein interfaceChannelGroup
-
newCloseFuture
Description copied from interface:ChannelGroupReturns theChannelGroupFuturewhich will be notified when allChannels that are part of thisChannelGroup, at the time of calling, are closed.- Specified by:
newCloseFuturein interfaceChannelGroup
-
hashCode
-
equals
-
compareTo
- Specified by:
compareToin interfacejava.lang.Comparable<ChannelGroup>
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.util.AbstractCollection<Channel>
-