Package org.jboss.netty.channel.group
Class DefaultChannelGroup
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<Channel>
-
- org.jboss.netty.channel.group.DefaultChannelGroup
-
- All Implemented Interfaces:
java.lang.Comparable<ChannelGroup>,java.lang.Iterable<Channel>,java.util.Collection<Channel>,java.util.Set<Channel>,ChannelGroup
public class DefaultChannelGroup extends java.util.AbstractSet<Channel> implements ChannelGroup
The defaultChannelGroupimplementation.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringnameprivate static java.util.concurrent.atomic.AtomicIntegernextIdprivate java.util.concurrent.ConcurrentMap<java.lang.Integer,Channel>nonServerChannelsprivate ChannelFutureListenerremoverprivate java.util.concurrent.ConcurrentMap<java.lang.Integer,Channel>serverChannels
-
Constructor Summary
Constructors Constructor Description DefaultChannelGroup()Creates a new group with a generated name.DefaultChannelGroup(java.lang.String name)Creates a new group with the specifiedname.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Channel channel)voidclear()ChannelGroupFutureclose()Closes allChannels in this group.intcompareTo(ChannelGroup o)booleancontains(java.lang.Object o)ChannelGroupFuturedisconnect()Disconnects allChannels in this group from their remote peers.booleanequals(java.lang.Object o)Channelfind(java.lang.Integer id)Returns theChannelwhose ID matches the specified integer.java.lang.StringgetName()Returns the name of this group.inthashCode()booleanisEmpty()java.util.Iterator<Channel>iterator()booleanremove(java.lang.Object o)ChannelGroupFuturesetInterestOps(int interestOps)ChannelGroupFuturesetReadable(boolean readable)CallsChannel.setReadable(boolean)for allChannels in this group with the specified boolean flag.intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()ChannelGroupFutureunbind()Unbinds allChannels in this group from their local address.ChannelGroupFuturewrite(java.lang.Object message)Writes the specifiedmessageto allChannels in this group.ChannelGroupFuturewrite(java.lang.Object message, java.net.SocketAddress remoteAddress)
-
-
-
Field Detail
-
nextId
private static final java.util.concurrent.atomic.AtomicInteger nextId
-
name
private final java.lang.String name
-
serverChannels
private final java.util.concurrent.ConcurrentMap<java.lang.Integer,Channel> serverChannels
-
nonServerChannels
private final java.util.concurrent.ConcurrentMap<java.lang.Integer,Channel> nonServerChannels
-
remover
private final ChannelFutureListener remover
-
-
Constructor Detail
-
DefaultChannelGroup
public DefaultChannelGroup()
Creates a new group with a generated name.
-
DefaultChannelGroup
public DefaultChannelGroup(java.lang.String name)
Creates a new group with the specifiedname. Please note that different groups can have the same name, which means no duplicate check is done against group names.
-
-
Method Detail
-
getName
public java.lang.String getName()
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:
getNamein interfaceChannelGroup
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
find
public Channel find(java.lang.Integer id)
Description copied from interface:ChannelGroupReturns theChannelwhose ID matches the specified integer.- Specified by:
findin interfaceChannelGroup- Returns:
- the matching
Channelif found.nullotherwise.
-
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
-
setInterestOps
public ChannelGroupFuture setInterestOps(int interestOps)
Description copied from interface:ChannelGroupCallsChannel.setInterestOps(int)for allChannels in this group with the specifiedinterestOps. Please note that this operation is asynchronous asChannel.setInterestOps(int)is.- Specified by:
setInterestOpsin interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
setReadable
public ChannelGroupFuture setReadable(boolean readable)
Description copied from interface:ChannelGroupCallsChannel.setReadable(boolean)for allChannels in this group with the specified boolean flag. Please note that this operation is asynchronous asChannel.setReadable(boolean)is.- Specified by:
setReadablein interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
unbind
public ChannelGroupFuture unbind()
Description copied from interface:ChannelGroupUnbinds allChannels in this group from their local address.- Specified by:
unbindin 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 ofChannelBuffer, it is automatically duplicated to avoid a race condition. 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, java.net.SocketAddress remoteAddress)
Description copied from interface:ChannelGroupWrites the specifiedmessagewith the specifiedremoteAddressto allChannels in this group. If the specifiedmessageis an instance ofChannelBuffer, it is automatically duplicated to avoid a race condition. Please note that this operation is asynchronous asChannel.write(Object, SocketAddress)is.- Specified by:
writein interfaceChannelGroup- Returns:
- the
ChannelGroupFutureinstance that notifies when the operation is done for all channels
-
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>
-
-