public class SocketContainer
extends java.lang.Object
SelectableChannel
, SocketIF
pairs. This container is used by
the AbstractSelector
to keep track of valid
sockets. While it is used from a client implementation, it is most useful to
a server implementation that deals with multiple connected sockets (clients).
This implementation is synchronized and thread-safe.
Constructor and Description |
---|
SocketContainer() |
Modifier and Type | Method and Description |
---|---|
void |
addSocket(java.nio.channels.SelectableChannel key,
SocketIF socket)
Associates the specified
SocketIF with the specified
SelectableChannel in this map. |
void |
clear()
Removes all
SelectableChannel , SocketIF mappings from
this map. |
boolean |
containsKey(java.nio.channels.SelectableChannel key)
Returns true if this map contains a mapping for the specified
SelectableChannel key. |
SocketIF |
getSocket(java.nio.channels.SelectableChannel key)
Get the
SocketIF that is paired to the given
SelectableChannel key. |
SocketIF |
removeSocket(java.nio.channels.SelectableChannel key)
Remove the
SocketIF that is paired to the given
SelectableChannel key. |
int |
size()
Returns the number of
SelectableChannel , SocketIF
mappings in this map. |
public SocketIF getSocket(java.nio.channels.SelectableChannel key)
SocketIF
that is paired to the given
SelectableChannel
key.key
- the SelectableChannel
key whose associated value is to
be returnedSocketIF
to which the specified
SelectableChannel
is mapped, or null if this map contains no
mapping for the SelectableChannel
.public boolean containsKey(java.nio.channels.SelectableChannel key)
SelectableChannel
key.key
- SelectableChannel
key whose presence in this map is to
be testedSocketIF
mapping for the
specified SelectableChannel
keypublic void addSocket(java.nio.channels.SelectableChannel key, SocketIF socket)
SocketIF
with the specified
SelectableChannel
in this map. If the map previously contained a
mapping for the SelectableChannel
, the old SocketIF
is
replaced by the specified SocketIF
.key
- the SelectableChannel
key with which the specified
value is to be associatedsocket
- SocketIF
to be associated with the specified keypublic SocketIF removeSocket(java.nio.channels.SelectableChannel key)
SocketIF
that is paired to the given
SelectableChannel
key.key
- the SelectableChannel
key whose associated value is to
be removed from the mapSocketIF
associated with
SelectableChannel
is mapped, or null if there was no mapping for
SelectableChannel
.public void clear()
SelectableChannel
, SocketIF
mappings from
this map. The map will be empty after this call returns.