Package io.netty.channel.group
Class DefaultChannelGroup
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<Channel>
-
- io.netty.channel.group.DefaultChannelGroup
-
- All Implemented Interfaces:
ChannelGroup,java.lang.Comparable<ChannelGroup>,java.lang.Iterable<Channel>,java.util.Collection<Channel>,java.util.Set<Channel>
public class DefaultChannelGroup extends java.util.AbstractSet<Channel> implements ChannelGroup
The defaultChannelGroupimplementation.
-
-
Constructor Summary
Constructors Constructor Description DefaultChannelGroup(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Channel channel)voidclear()ChannelGroupFutureclose()Closes allChannels in this group.ChannelGroupFutureclose(ChannelMatcher matcher)Closes allChannels in this group that are matched by the givenChannelMatcher.intcompareTo(ChannelGroup o)booleancontains(java.lang.Object o)ChannelGroupFuturederegister()ChannelGroupFuturederegister(ChannelMatcher matcher)ChannelGroupFuturedisconnect()Disconnects allChannels in this group from their remote peers.ChannelGroupFuturedisconnect(ChannelMatcher matcher)Disconnects allChannels in this group from their remote peers, that are matched by the givenChannelMatcher.booleanequals(java.lang.Object o)Channelfind(ChannelId id)ChannelGroupflush()Flush allChannels in this group.ChannelGroupflush(ChannelMatcher matcher)Flush allChannels in this group that are matched by the givenChannelMatcher.ChannelGroupFutureflushAndWrite(java.lang.Object message)ChannelGroupFutureflushAndWrite(java.lang.Object message, ChannelMatcher matcher)inthashCode()booleanisEmpty()java.util.Iterator<Channel>iterator()java.lang.Stringname()Returns the name of this group.ChannelGroupFuturenewCloseFuture()Returns theChannelGroupFuturewhich will be notified when allChannels that are part of thisChannelGroup, at the time of calling, are closed.ChannelGroupFuturenewCloseFuture(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)intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()ChannelGroupFuturewrite(java.lang.Object message)Writes the specifiedmessageto allChannels in this group.ChannelGroupFuturewrite(java.lang.Object message, ChannelMatcher matcher)Writes the specifiedmessageto allChannels in this group that are matched by the givenChannelMatcher.ChannelGroupFuturewrite(java.lang.Object message, ChannelMatcher matcher, boolean voidPromise)Writes the specifiedmessageto allChannels in this group that are matched by the givenChannelMatcher.ChannelGroupFuturewriteAndFlush(java.lang.Object message)Shortcut for callingChannelGroup.write(Object)andChannelGroup.flush().ChannelGroupFuturewriteAndFlush(java.lang.Object message, ChannelMatcher matcher)Shortcut for callingChannelGroup.write(Object)andChannelGroup.flush()and only act onChannels that are matched by theChannelMatcher.ChannelGroupFuturewriteAndFlush(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.
-
-
-
Constructor Detail
-
DefaultChannelGroup
public DefaultChannelGroup(EventExecutor executor)
Creates a new group with a generated name and the providedEventExecutorto notify theChannelGroupFutures.
-
DefaultChannelGroup
public DefaultChannelGroup(java.lang.String name, EventExecutor executor)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
public DefaultChannelGroup(EventExecutor executor, boolean stayClosed)
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
public DefaultChannelGroup(java.lang.String name, EventExecutor executor, boolean stayClosed)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 Detail
-
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
public Channel find(ChannelId id)
Description copied from interface:ChannelGroup- Specified by:
findin interfaceChannelGroup- Returns:
- the matching
Channelif found.nullotherwise.
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
contains
public boolean contains(java.lang.Object o)
-
add
public boolean add(Channel channel)
-
remove
public boolean remove(java.lang.Object o)
-
clear
public void clear()
-
iterator
public java.util.Iterator<Channel> iterator()
-
toArray
public java.lang.Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
close
public ChannelGroupFuture 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
public ChannelGroupFuture 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
public ChannelGroupFuture deregister()
- Specified by:
deregisterin interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
write
public ChannelGroupFuture write(java.lang.Object message)
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
-
write
public ChannelGroupFuture write(java.lang.Object message, ChannelMatcher matcher)
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
public ChannelGroup 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
public ChannelGroupFuture flushAndWrite(java.lang.Object message)
- Specified by:
flushAndWritein interfaceChannelGroup
-
writeAndFlush
public ChannelGroupFuture writeAndFlush(java.lang.Object message)
Description copied from interface:ChannelGroupShortcut for callingChannelGroup.write(Object)andChannelGroup.flush().- Specified by:
writeAndFlushin interfaceChannelGroup
-
disconnect
public ChannelGroupFuture disconnect(ChannelMatcher matcher)
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
public ChannelGroupFuture close(ChannelMatcher matcher)
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
public ChannelGroupFuture deregister(ChannelMatcher matcher)
- Specified by:
deregisterin interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
flush
public ChannelGroup flush(ChannelMatcher matcher)
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
public ChannelGroupFuture flushAndWrite(java.lang.Object message, ChannelMatcher matcher)
- Specified by:
flushAndWritein interfaceChannelGroup
-
writeAndFlush
public ChannelGroupFuture writeAndFlush(java.lang.Object message, ChannelMatcher matcher)
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
public ChannelGroupFuture 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
public ChannelGroupFuture newCloseFuture(ChannelMatcher matcher)
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
public int hashCode()
-
equals
public boolean equals(java.lang.Object o)
-
compareTo
public int compareTo(ChannelGroup o)
- Specified by:
compareToin interfacejava.lang.Comparable<ChannelGroup>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<Channel>
-
-