- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<Channel>
-
- io.netty5.channel.group.DefaultChannelGroup
-
- All Implemented Interfaces:
ChannelGroup
,Comparable<ChannelGroup>
,Iterable<Channel>
,Collection<Channel>
,Set<Channel>
public class DefaultChannelGroup extends AbstractSet<Channel> implements ChannelGroup
The defaultChannelGroup
implementation.
-
-
Constructor Summary
Constructors Constructor Description DefaultChannelGroup(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Channel channel)
void
clear()
ChannelGroupFuture
close()
Closes allChannel
s in this group.ChannelGroupFuture
close(ChannelMatcher matcher)
Closes allChannel
s in this group that are matched by the givenChannelMatcher
.int
compareTo(ChannelGroup o)
boolean
contains(Object o)
ChannelGroupFuture
deregister()
ChannelGroupFuture
deregister(ChannelMatcher matcher)
ChannelGroupFuture
disconnect()
Disconnects allChannel
s in this group from their remote peers.ChannelGroupFuture
disconnect(ChannelMatcher matcher)
Disconnects allChannel
s in this group from their remote peers, that are matched by the givenChannelMatcher
.boolean
equals(Object o)
Channel
find(ChannelId id)
ChannelGroup
flush()
Flush allChannel
s in this group.ChannelGroup
flush(ChannelMatcher matcher)
Flush allChannel
s in this group that are matched by the givenChannelMatcher
.ChannelGroupFuture
flushAndWrite(Object message)
ChannelGroupFuture
flushAndWrite(Object message, ChannelMatcher matcher)
int
hashCode()
boolean
isEmpty()
Iterator<Channel>
iterator()
String
name()
Returns the name of this group.ChannelGroupFuture
newCloseFuture()
Returns theChannelGroupFuture
which will be notified when allChannel
s that are part of thisChannelGroup
, at the time of calling, are closed.ChannelGroupFuture
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
remove(Object o)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] a)
String
toString()
ChannelGroupFuture
write(Object message)
Writes the specifiedmessage
to allChannel
s in this group.ChannelGroupFuture
write(Object message, ChannelMatcher matcher)
Writes the specifiedmessage
to allChannel
s in this group that are matched by the givenChannelMatcher
.ChannelGroupFuture
writeAndFlush(Object message)
Shortcut for callingChannelGroup.write(Object)
andChannelGroup.flush()
.ChannelGroupFuture
writeAndFlush(Object message, ChannelMatcher matcher)
Shortcut for callingChannelGroup.write(Object)
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
-
-
-
-
Constructor Detail
-
DefaultChannelGroup
public DefaultChannelGroup(EventExecutor executor)
Creates a new group with a generated name and the providedEventExecutor
to notify theChannelGroupFuture
s.
-
DefaultChannelGroup
public DefaultChannelGroup(String name, EventExecutor executor)
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
public DefaultChannelGroup(EventExecutor executor, boolean stayClosed)
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
public DefaultChannelGroup(String name, EventExecutor executor, boolean stayClosed)
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 Detail
-
name
public String 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
public Channel find(ChannelId id)
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
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<Channel>
- Specified by:
contains
in interfaceSet<Channel>
- Overrides:
contains
in classAbstractCollection<Channel>
-
add
public boolean add(Channel channel)
- Specified by:
add
in interfaceCollection<Channel>
- Specified by:
add
in interfaceSet<Channel>
- Overrides:
add
in classAbstractCollection<Channel>
-
remove
public boolean remove(Object o)
- 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>
-
toArray
public Object[] 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
public ChannelGroupFuture 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
public ChannelGroupFuture 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
public ChannelGroupFuture deregister()
- Specified by:
deregister
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
write
public ChannelGroupFuture write(Object message)
Description copied from interface:ChannelGroup
Writes the specifiedmessage
to allChannel
s in this group. If the specifiedmessage
is an instance ofBuffer
, it is automatically copied to avoid a race condition. Please note that this operation is asynchronous asChannel.write(Object)
is.- Specified by:
write
in interfaceChannelGroup
- Returns:
- itself
-
write
public ChannelGroupFuture write(Object message, ChannelMatcher matcher)
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 ofBuffer
, it is automatically copied to avoid a race condition. Please note that this operation is asynchronous asChannel.write(Object)
is.- Specified by:
write
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
flush
public ChannelGroup flush()
Description copied from interface:ChannelGroup
Flush allChannel
s in this group. If the specifiedmessage
is an instance ofBuffer
, it is automatically copied to avoid a race condition. Please note that this operation is asynchronous asChannel.flush()
is.- Specified by:
flush
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
flushAndWrite
public ChannelGroupFuture flushAndWrite(Object message)
- Specified by:
flushAndWrite
in interfaceChannelGroup
-
writeAndFlush
public ChannelGroupFuture writeAndFlush(Object message)
Description copied from interface:ChannelGroup
Shortcut for callingChannelGroup.write(Object)
andChannelGroup.flush()
.- Specified by:
writeAndFlush
in interfaceChannelGroup
-
disconnect
public ChannelGroupFuture disconnect(ChannelMatcher matcher)
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
public ChannelGroupFuture close(ChannelMatcher matcher)
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
public ChannelGroupFuture deregister(ChannelMatcher matcher)
- Specified by:
deregister
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
flush
public ChannelGroup flush(ChannelMatcher matcher)
Description copied from interface:ChannelGroup
Flush allChannel
s in this group that are matched by the givenChannelMatcher
. If the specifiedmessage
is an instance ofBuffer
, it is automatically copied to avoid a race condition. Please note that this operation is asynchronous asChannel.flush()
is.- Specified by:
flush
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
flushAndWrite
public ChannelGroupFuture flushAndWrite(Object message, ChannelMatcher matcher)
- Specified by:
flushAndWrite
in interfaceChannelGroup
-
writeAndFlush
public ChannelGroupFuture writeAndFlush(Object message, ChannelMatcher matcher)
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
-
newCloseFuture
public ChannelGroupFuture 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
public ChannelGroupFuture newCloseFuture(ChannelMatcher matcher)
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
public boolean equals(Object o)
- Specified by:
equals
in interfaceCollection<Channel>
- Specified by:
equals
in interfaceSet<Channel>
- Overrides:
equals
in classAbstractSet<Channel>
-
compareTo
public int compareTo(ChannelGroup o)
- Specified by:
compareTo
in interfaceComparable<ChannelGroup>
-
toString
public String toString()
- Overrides:
toString
in classAbstractCollection<Channel>
-
-