Package io.netty.channel.group
Class DefaultChannelGroup
- All Implemented Interfaces:
ChannelGroup
,Comparable<ChannelGroup>
,Iterable<Channel>
,Collection<Channel>
,Set<Channel>
The default
ChannelGroup
implementation.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final EventExecutor
private final String
private static final AtomicInteger
private final ConcurrentMap
<ChannelId, Channel> private final ChannelFutureListener
private final ConcurrentMap
<ChannelId, Channel> private final boolean
private final VoidChannelGroupFuture
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultChannelGroup
(EventExecutor executor) Creates a new group with a generated name and the providedEventExecutor
to notify theChannelGroupFuture
s.DefaultChannelGroup
(EventExecutor executor, boolean stayClosed) Creates a new group with a generated name and the providedEventExecutor
to notify theChannelGroupFuture
s.DefaultChannelGroup
(String name, EventExecutor executor) DefaultChannelGroup
(String name, EventExecutor executor, boolean stayClosed) -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
clear()
close()
Closes allChannel
s in this group.close
(ChannelMatcher matcher) Closes allChannel
s in this group that are matched by the givenChannelMatcher
.int
boolean
deregister
(ChannelMatcher matcher) Disconnects allChannel
s in this group from their remote peers.disconnect
(ChannelMatcher matcher) Disconnects allChannel
s in this group from their remote peers, that are matched by the givenChannelMatcher
.boolean
flush()
Flush allChannel
s in this group.flush
(ChannelMatcher matcher) Flush allChannel
s in this group that are matched by the givenChannelMatcher
.flushAndWrite
(Object message) flushAndWrite
(Object message, ChannelMatcher matcher) int
hashCode()
boolean
isEmpty()
iterator()
name()
Returns the name of this group.Returns theChannelGroupFuture
which will be notified when allChannel
s that are part of thisChannelGroup
, at the time of calling, are closed.newCloseFuture
(ChannelMatcher matcher) Returns theChannelGroupFuture
which will be notified when allChannel
s that are part of thisChannelGroup
, at the time of calling, are closed.boolean
private static Object
safeDuplicate
(Object message) int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] a) toString()
Writes the specifiedmessage
to allChannel
s in this group.write
(Object message, ChannelMatcher matcher) Writes the specifiedmessage
to allChannel
s in this group that are matched by the givenChannelMatcher
.write
(Object message, ChannelMatcher matcher, boolean voidPromise) Writes the specifiedmessage
to allChannel
s in this group that are matched by the givenChannelMatcher
.writeAndFlush
(Object message) Shortcut for callingChannelGroup.write(Object)
andChannelGroup.flush()
.writeAndFlush
(Object message, ChannelMatcher matcher) Shortcut for callingChannelGroup.write(Object)
andChannelGroup.flush()
and only act onChannel
s that are matched by theChannelMatcher
.writeAndFlush
(Object message, ChannelMatcher matcher, boolean voidPromise) Shortcut for callingChannelGroup.write(Object, ChannelMatcher, boolean)
andChannelGroup.flush()
and only act onChannel
s that are matched by theChannelMatcher
.Methods inherited from class java.util.AbstractSet
removeAll
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll, spliterator
-
Field Details
-
nextId
-
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 providedEventExecutor
to notify theChannelGroupFuture
s. -
DefaultChannelGroup
Creates a new group with the specifiedname
andEventExecutor
to notify theChannelGroupFuture
s. 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 providedEventExecutor
to notify theChannelGroupFuture
s.stayClosed
defines 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 specifiedname
andEventExecutor
to notify theChannelGroupFuture
s.stayClosed
defines 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
Description copied from interface:ChannelGroup
Returns the name of this group. A group name is purely for helping you to distinguish one group from others.- Specified by:
name
in interfaceChannelGroup
-
find
Description copied from interface:ChannelGroup
- Specified by:
find
in interfaceChannelGroup
- Returns:
- the matching
Channel
if found.null
otherwise.
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<Channel>
- Specified by:
isEmpty
in interfaceSet<Channel>
- Overrides:
isEmpty
in classAbstractCollection<Channel>
-
size
public int size()- Specified by:
size
in interfaceCollection<Channel>
- Specified by:
size
in interfaceSet<Channel>
- Specified by:
size
in classAbstractCollection<Channel>
-
contains
- Specified by:
contains
in interfaceCollection<Channel>
- Specified by:
contains
in interfaceSet<Channel>
- Overrides:
contains
in classAbstractCollection<Channel>
-
add
- Specified by:
add
in interfaceCollection<Channel>
- Specified by:
add
in interfaceSet<Channel>
- Overrides:
add
in classAbstractCollection<Channel>
-
remove
- Specified by:
remove
in interfaceCollection<Channel>
- Specified by:
remove
in interfaceSet<Channel>
- Overrides:
remove
in classAbstractCollection<Channel>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<Channel>
- Specified by:
clear
in interfaceSet<Channel>
- Overrides:
clear
in classAbstractCollection<Channel>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<Channel>
- Specified by:
toArray
in interfaceSet<Channel>
- Overrides:
toArray
in classAbstractCollection<Channel>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<Channel>
- Specified by:
toArray
in interfaceSet<Channel>
- Overrides:
toArray
in classAbstractCollection<Channel>
-
close
Description copied from interface:ChannelGroup
Closes allChannel
s in this group. If theChannel
is connected to a remote peer or bound to a local address, it is automatically disconnected and unbound.- Specified by:
close
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
disconnect
Description copied from interface:ChannelGroup
Disconnects allChannel
s in this group from their remote peers.- Specified by:
disconnect
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
deregister
- Specified by:
deregister
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
write
Description copied from interface:ChannelGroup
Writes the specifiedmessage
to allChannel
s in this group. If the specifiedmessage
is an instance ofByteBuf
, it is automatically duplicated to avoid a race condition. The same is true forByteBufHolder
. Please note that this operation is asynchronous asChannelOutboundInvoker.write(Object)
is.- Specified by:
write
in interfaceChannelGroup
- Returns:
- itself
-
safeDuplicate
-
write
Description copied from interface:ChannelGroup
Writes the specifiedmessage
to allChannel
s in this group that are matched by the givenChannelMatcher
. If the specifiedmessage
is an instance ofByteBuf
, it is automatically duplicated to avoid a race condition. The same is true forByteBufHolder
. Please note that this operation is asynchronous asChannelOutboundInvoker.write(Object)
is.- Specified by:
write
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
write
Description copied from interface:ChannelGroup
Writes the specifiedmessage
to allChannel
s in this group that are matched by the givenChannelMatcher
. If the specifiedmessage
is an instance ofByteBuf
, it is automatically duplicated to avoid a race condition. The same is true forByteBufHolder
. Please note that this operation is asynchronous asChannelOutboundInvoker.write(Object)
is. IfvoidPromise
istrue
ChannelOutboundInvoker.voidPromise()
is used for the writes and so the same restrictions to the returnedChannelGroupFuture
apply as to a void promise.- Specified by:
write
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
flush
Description copied from interface:ChannelGroup
Flush allChannel
s in this group. If the specifiedmessages
are an instance ofByteBuf
, it is automatically duplicated to avoid a race condition. Please note that this operation is asynchronous asChannelOutboundInvoker.write(Object)
is.- Specified by:
flush
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
flushAndWrite
- Specified by:
flushAndWrite
in interfaceChannelGroup
-
writeAndFlush
Description copied from interface:ChannelGroup
Shortcut for callingChannelGroup.write(Object)
andChannelGroup.flush()
.- Specified by:
writeAndFlush
in interfaceChannelGroup
-
disconnect
Description copied from interface:ChannelGroup
Disconnects allChannel
s in this group from their remote peers, that are matched by the givenChannelMatcher
.- Specified by:
disconnect
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
close
Description copied from interface:ChannelGroup
Closes allChannel
s in this group that are matched by the givenChannelMatcher
. If theChannel
is connected to a remote peer or bound to a local address, it is automatically disconnected and unbound.- Specified by:
close
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
deregister
- Specified by:
deregister
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
flush
Description copied from interface:ChannelGroup
Flush allChannel
s in this group that are matched by the givenChannelMatcher
. If the specifiedmessages
are an instance ofByteBuf
, it is automatically duplicated to avoid a race condition. Please note that this operation is asynchronous asChannelOutboundInvoker.write(Object)
is.- Specified by:
flush
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
flushAndWrite
- Specified by:
flushAndWrite
in interfaceChannelGroup
-
writeAndFlush
Description copied from interface:ChannelGroup
Shortcut for callingChannelGroup.write(Object)
andChannelGroup.flush()
and only act onChannel
s that are matched by theChannelMatcher
.- Specified by:
writeAndFlush
in interfaceChannelGroup
-
writeAndFlush
public ChannelGroupFuture writeAndFlush(Object message, ChannelMatcher matcher, boolean voidPromise) Description copied from interface:ChannelGroup
Shortcut for callingChannelGroup.write(Object, ChannelMatcher, boolean)
andChannelGroup.flush()
and only act onChannel
s that are matched by theChannelMatcher
.- Specified by:
writeAndFlush
in interfaceChannelGroup
-
newCloseFuture
Description copied from interface:ChannelGroup
Returns theChannelGroupFuture
which will be notified when allChannel
s that are part of thisChannelGroup
, at the time of calling, are closed.- Specified by:
newCloseFuture
in interfaceChannelGroup
-
newCloseFuture
Description copied from interface:ChannelGroup
Returns theChannelGroupFuture
which will be notified when allChannel
s that are part of thisChannelGroup
, at the time of calling, are closed.- Specified by:
newCloseFuture
in interfaceChannelGroup
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<Channel>
- Specified by:
hashCode
in interfaceSet<Channel>
- Overrides:
hashCode
in classAbstractSet<Channel>
-
equals
- Specified by:
equals
in interfaceCollection<Channel>
- Specified by:
equals
in interfaceSet<Channel>
- Overrides:
equals
in classAbstractSet<Channel>
-
compareTo
- Specified by:
compareTo
in interfaceComparable<ChannelGroup>
-
toString
- Overrides:
toString
in classAbstractCollection<Channel>
-