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 defaultChannelGroup
implementation.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
name
private static java.util.concurrent.atomic.AtomicInteger
nextId
private java.util.concurrent.ConcurrentMap<java.lang.Integer,Channel>
nonServerChannels
private ChannelFutureListener
remover
private 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 boolean
add(Channel channel)
void
clear()
ChannelGroupFuture
close()
Closes allChannel
s in this group.int
compareTo(ChannelGroup o)
boolean
contains(java.lang.Object o)
ChannelGroupFuture
disconnect()
Disconnects allChannel
s in this group from their remote peers.boolean
equals(java.lang.Object o)
Channel
find(java.lang.Integer id)
Returns theChannel
whose ID matches the specified integer.java.lang.String
getName()
Returns the name of this group.int
hashCode()
boolean
isEmpty()
java.util.Iterator<Channel>
iterator()
boolean
remove(java.lang.Object o)
ChannelGroupFuture
setInterestOps(int interestOps)
ChannelGroupFuture
setReadable(boolean readable)
CallsChannel.setReadable(boolean)
for allChannel
s in this group with the specified boolean flag.int
size()
java.lang.Object[]
toArray()
<T> T[]
toArray(T[] a)
java.lang.String
toString()
ChannelGroupFuture
unbind()
Unbinds allChannel
s in this group from their local address.ChannelGroupFuture
write(java.lang.Object message)
Writes the specifiedmessage
to allChannel
s in this group.ChannelGroupFuture
write(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:ChannelGroup
Returns the name of this group. A group name is purely for helping you to distinguish one group from others.- Specified by:
getName
in interfaceChannelGroup
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
find
public Channel find(java.lang.Integer id)
Description copied from interface:ChannelGroup
Returns theChannel
whose ID matches the specified integer.- Specified by:
find
in interfaceChannelGroup
- Returns:
- the matching
Channel
if found.null
otherwise.
-
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: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
-
setInterestOps
public ChannelGroupFuture setInterestOps(int interestOps)
Description copied from interface:ChannelGroup
CallsChannel.setInterestOps(int)
for allChannel
s in this group with the specifiedinterestOps
. Please note that this operation is asynchronous asChannel.setInterestOps(int)
is.- Specified by:
setInterestOps
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
setReadable
public ChannelGroupFuture setReadable(boolean readable)
Description copied from interface:ChannelGroup
CallsChannel.setReadable(boolean)
for allChannel
s in this group with the specified boolean flag. Please note that this operation is asynchronous asChannel.setReadable(boolean)
is.- Specified by:
setReadable
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
unbind
public ChannelGroupFuture unbind()
Description copied from interface:ChannelGroup
Unbinds allChannel
s in this group from their local address.- Specified by:
unbind
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance that notifies when the operation is done for all channels
-
write
public ChannelGroupFuture write(java.lang.Object message)
Description copied from interface:ChannelGroup
Writes the specifiedmessage
to allChannel
s in this group. If the specifiedmessage
is 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:
write
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance 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:ChannelGroup
Writes the specifiedmessage
with the specifiedremoteAddress
to allChannel
s in this group. If the specifiedmessage
is 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:
write
in interfaceChannelGroup
- Returns:
- the
ChannelGroupFuture
instance 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:
compareTo
in interfacejava.lang.Comparable<ChannelGroup>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractCollection<Channel>
-
-