abstract class MultiplexingXXXSocketSupport<MultiplexedXXXSocketT extends MultiplexedXXXSocket> extends Object
DatagramPacket
-based views of the packets they receive in the forms
of pseudo sockets.Modifier and Type | Field and Description |
---|---|
private boolean |
inReceive
The indicator which determines whether this DatagramSocket is
currently reading from the network using
DatagramSocket.receive(DatagramPacket) . |
private static Logger |
logger
The
Logger used by the MultiplexingXXXSocketSupport class
and its instances for logging output. |
private int |
receiveBufferSize
The value with which
DatagramSocket.setReceiveBufferSize(int) is
to be invoked if setReceiveBufferSize is true. |
private Object |
receiveSyncRoot
The Object which synchronizes the access to
inReceive . |
private boolean |
setReceiveBufferSize
The indicator which determines whether
DatagramSocket.setReceiveBufferSize(int) is to be invoked with
the value of receiveBufferSize . |
private List<MultiplexedXXXSocketT> |
sockets
The IP sockets filtering
DatagramPacket s away from this IP
socket. |
Modifier | Constructor and Description |
---|---|
protected |
MultiplexingXXXSocketSupport()
Initializes a new
MultiplexingXXXSocketSupport instance. |
Modifier and Type | Method and Description |
---|---|
private void |
acceptBySocketsOrThis(DatagramPacket p)
Accepts a
DatagramPacket received by this socket and queues it
for receipt through either this multiplexing socket or its multiplexed
sockets whose DatagramPacketFilter s accept p . |
static DatagramPacket |
clone(DatagramPacket p)
Initializes a new DatagramPacket instance which is a clone of a
specific DatagramPacket i.e.
|
private static DatagramPacket |
clone(DatagramPacket p,
boolean arraycopy)
Initializes a new DatagramPacket instance which is a clone of a
specific DatagramPacket i.e.
|
(package private) boolean |
close(MultiplexedXXXSocketT multiplexed)
Closes a specific MultiplexedDatagramSocket which filters
DatagramPackets away from this DatagramSocket.
|
static void |
copy(DatagramPacket src,
DatagramPacket dest)
Copies the properties of a specific DatagramPacket to another
DatagramPacket.
|
protected abstract MultiplexedXXXSocketT |
createSocket(DatagramPacketFilter filter)
Initializes a new multiplexed socket instance which is to be associated
with a specific
DatagramPacketFilter . |
protected abstract void |
doReceive(DatagramPacket p)
Receives a
DatagramPacket from this socket. |
protected abstract void |
doSetReceiveBufferSize(int receiveBufferSize)
Sets the
SO_RCVBUF option to the specified value for this
DatagramSocket . |
protected DatagramPacketFilter |
getFilter(MultiplexedXXXSocketT socket)
Gets the
DatagramPacketFilter associated with a specific
multiplexed socket. |
protected abstract List<DatagramPacket> |
getReceived()
Gets the list of
DatagramPacket s received by this socket and not
accepted by any (existing) DatagramPacketFilter at the time of
receipt. |
protected abstract List<DatagramPacket> |
getReceived(MultiplexedXXXSocketT socket)
Gets the list of
DatagramPacket s received by this multiplexing
socket and accepted by the DatagramPacketFilter of a specific
multiplexed socket at the time of receipt. |
MultiplexedXXXSocketT |
getSocket(DatagramPacketFilter filter)
Gets a MultiplexedDatagramSocket which filters
DatagramPackets away from this DatagramSocket using a
specific DatagramPacketFilter.
|
MultiplexedXXXSocketT |
getSocket(DatagramPacketFilter filter,
boolean create)
Gets a MultiplexedDatagramSocket which filters
DatagramPackets away from this DatagramSocket using a
specific DatagramPacketFilter.
|
private void |
moveReceivedFromThisToSocket(MultiplexedXXXSocketT socket)
Moves packets which have been received from this multiplexing socket to
a specific multiplexed socket if they are accepted by the
DatagramPacketFilter of the latter. |
(package private) void |
receive(List<DatagramPacket> received,
DatagramPacket p,
int timeout)
Receives a DatagramPacket from a specific list of
DatagramPackets if it is not empty or from the network if the
specified list is empty.
|
void |
setReceiveBufferSize(int receiveBufferSize)
Sets the
SO_RCVBUF option to the specified value for this socket. |
private static final Logger logger
Logger
used by the MultiplexingXXXSocketSupport
class
and its instances for logging output.private boolean inReceive
DatagramSocket.receive(DatagramPacket)
. When true,
subsequent requests to read from the network will be blocked until the
current read is finished.private int receiveBufferSize
DatagramSocket.setReceiveBufferSize(int)
is
to be invoked if setReceiveBufferSize
is true.private final Object receiveSyncRoot
inReceive
.private boolean setReceiveBufferSize
DatagramSocket.setReceiveBufferSize(int)
is to be invoked with
the value of receiveBufferSize
.private final List<MultiplexedXXXSocketT extends MultiplexedXXXSocket> sockets
DatagramPacket
s away from this IP
socket.protected MultiplexingXXXSocketSupport()
MultiplexingXXXSocketSupport
instance.public static DatagramPacket clone(DatagramPacket p)
p
- the DatagramPacket to cloneprivate static DatagramPacket clone(DatagramPacket p, boolean arraycopy)
p
- the DatagramPacket to clonearraycopy
- true if the actual bytes of the data of
p are to be copied into the clone or false if only the
capacity of the data of p is to be cloned without copying the
actual bytes of the data of ppublic static void copy(DatagramPacket src, DatagramPacket dest)
src
- the DatagramPacket which is to have its properties
copied to destdest
- the DatagramPacket which is to have its properties
set to the value of the respective properties of srcprivate void acceptBySocketsOrThis(DatagramPacket p)
DatagramPacket
received by this socket and queues it
for receipt through either this multiplexing socket or its multiplexed
sockets whose DatagramPacketFilter
s accept p
.p
- the DatagramPacket
to be accepted by either this
multiplexing socket or its multiplexed sockets whose
DatagramPacketFilter
s accept p
boolean close(MultiplexedXXXSocketT multiplexed)
multiplexed
- the MultiplexedDatagramSocket to closetrue
if there are remaining filtered sockets.protected abstract MultiplexedXXXSocketT createSocket(DatagramPacketFilter filter) throws SocketException
DatagramPacketFilter
.filter
- the DatagramPacketFilter
to associate with the new
instancefilter
SocketException
- if there is an error in the underlying protocol,
such as a TCP or UDP errorprotected abstract void doReceive(DatagramPacket p) throws IOException
DatagramPacket
from this socket.p
- the DatagramPacket
into which to place the incoming dataIOException
- if an I/O error occursprotected abstract void doSetReceiveBufferSize(int receiveBufferSize) throws SocketException
SO_RCVBUF
option to the specified value for this
DatagramSocket
. The SO_RCVBUF
option is used by the
network implementation as a hint to size the underlying network I/O
buffers. The SO_RCVBUF
setting may also be used by the network
implementation to determine the maximum size of the packet that can be
received on this socket.receiveBufferSize
- the size to which to set the receive buffer sizeSocketException
- if there is an error in the underlying protocol,
such as a UDP errorprotected DatagramPacketFilter getFilter(MultiplexedXXXSocketT socket)
DatagramPacketFilter
associated with a specific
multiplexed socket.socket
- the multiplexed socket whose associated
DatagramPacketFilter
is to be retrievedDatagramPacketFilter
associated with socket
protected abstract List<DatagramPacket> getReceived()
DatagramPacket
s received by this socket and not
accepted by any (existing) DatagramPacketFilter
at the time of
receipt.DatagramPacket
s received by this socket and
not accepted by any (existing) DatagramPacketFilter
at the time of
receiptprotected abstract List<DatagramPacket> getReceived(MultiplexedXXXSocketT socket)
DatagramPacket
s received by this multiplexing
socket and accepted by the DatagramPacketFilter
of a specific
multiplexed socket at the time of receipt.socket
- the multiplexed socket whose list of accepted received
DatagramPacket
s is to be returnedDatagramPacket
s received by this multiplexing
socket and accepted by the DatagramPacketFilter
of the
multiplexed socket
at the time of receiptpublic MultiplexedXXXSocketT getSocket(DatagramPacketFilter filter) throws SocketException
filter
- the DatagramPacketFilter to get a
MultiplexedDatagramSocket forSocketException
- if creating the
MultiplexedDatagramSocket for the specified filter
failspublic MultiplexedXXXSocketT getSocket(DatagramPacketFilter filter, boolean create) throws SocketException
filter
- the DatagramPacketFilter to get a
MultiplexedDatagramSocket forcreate
- whether or not to create a
MultiplexedDatagramSocket if this instance does not already have
a socket for the given filter.SocketException
- if creating the
MultiplexedDatagramSocket for the specified filter
fails.private void moveReceivedFromThisToSocket(MultiplexedXXXSocketT socket)
DatagramPacketFilter
of the latter.socket
- the multiplexed socket into which received packets are to
be moved from this multiplexing socket if they are accepted by the
DatagramPacketFilter
of the formervoid receive(List<DatagramPacket> received, DatagramPacket p, int timeout) throws IOException
received
- the list of previously received DatagramPacket
from which the first is to be removed and returned if availablep
- the DatagramPacket into which to place the incoming
datatimeout
- the maximum time in milliseconds to wait for a
packet. A timeout of zero is interpreted as an infinite
timeoutIOException
- if an I/O error occursSocketTimeoutException
- if timeout is positive and has
expiredpublic void setReceiveBufferSize(int receiveBufferSize) throws SocketException
SO_RCVBUF
option to the specified value for this socket.
The SO_RCVBUF
option is used by the network implementation as a
hint to size the underlying network I/O buffers. The SO_RCVBUF
setting may also be used by the network implementation to determine the
maximum size of the packet that can be received on this socket.receiveBufferSize
- the size to which to set the receive buffer sizeSocketException
- if there is an error in the underlying protocol,
such as a TCP or UDP errorCopyright © 2018. All rights reserved.