DATA
- The type of the datagram to be operated with.org.refcodes.component.Closable
, org.refcodes.component.Closable.CloseAutomaton
, org.refcodes.component.ClosedAccessor
, org.refcodes.component.ConnectableComponent
, org.refcodes.component.ConnectableComponent.ConnectableAutomaton
, org.refcodes.component.ConnectionStatusAccessor
, org.refcodes.component.OpenedAccessor
, Availability
, DatagramDestination<DATA>
, DatagramReceiver<DATA>
, DatagramsDestination<DATA>
, DatagramsReceiver<DATA>
, Receivable
, org.refcodes.mixin.Loggable
AbstractPrefetchInputStreamReceiver
, DatagramsReceiverDecorator
, LoopbackDatagramsReceiver
, LoopbackDatagramsTransceiver
public abstract class AbstractDatagramsReceiver<DATA extends Serializable> extends org.refcodes.component.AbstractConnectableAutomaton implements DatagramsReceiver<DATA>, org.refcodes.mixin.Loggable
AbstractDatagramsReceiver
is a base abstract implementation of
the DatagramsReceiver
interface providing common functionality for
concrete real live implementations.org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
org.refcodes.component.ClosedAccessor.ClosedMutator, org.refcodes.component.ClosedAccessor.ClosedProperty
org.refcodes.component.ConnectableComponent.ConnectableAutomaton
Modifier and Type | Field | Description |
---|---|---|
static int |
DATAGRAM_QUEUE_SIZE |
Constructor | Description |
---|---|
AbstractDatagramsReceiver() |
Constructs a
AbstractDatagramsReceiver with a default sized
blocking queue enabling a maximum of DATAGRAM_QUEUE_SIZE
datagrams. |
AbstractDatagramsReceiver(int aCapacity) |
Constructs a
AbstractDatagramsReceiver with a custom sized
blocking queue enabling a maximum of datagrams as specified by the
capacity parameter. |
Modifier and Type | Method | Description |
---|---|---|
int |
available() |
Determines the number of available datagram from a
DatagramTransmitter . |
void |
close() |
|
protected void |
pushDatagram(DATA aDatagram) |
Pushes a datagram into the receiver and puts it into the blocking queue
containing the so far received datagrams.
|
protected void |
pushDatagrams(DATA[] aDatagrams) |
Pushes datagrams into the receiver and puts them into the blocking queue
containing the so far received datagrams.
|
protected void |
pushDatagrams(DATA[] aDatagrams,
int aOffset,
int aLength) |
Pushes datagrams into the receiver and puts them into the blocking queue
containing the so far received datagrams.
|
DATA |
receive() |
Reads (receives) the next datagram passed from a
DatagramTransmitter counterpart. |
DATA[] |
receiveAll() |
Reads (receives) the all currently available data.
|
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatus
hasAvailable
closeIn, closeQuietly, closeUnchecked
getConnectionStatus, isOpened
receive
receive
public static final int DATAGRAM_QUEUE_SIZE
public AbstractDatagramsReceiver()
AbstractDatagramsReceiver
with a default sized
blocking queue enabling a maximum of DATAGRAM_QUEUE_SIZE
datagrams. Make sure your code fetches the datagrams quick enough to
prevent filling up of the queue. In case the queue is filled up, adding
elements via pushDatagram(Serializable)
to the queue is blocked
until elements are taken from the queue via receive()
.public AbstractDatagramsReceiver(int aCapacity)
AbstractDatagramsReceiver
with a custom sized
blocking queue enabling a maximum of datagrams as specified by the
capacity parameter. Make sure your code fetches the datagrams quick
enough to prevent filling up of the queue. In case the queue is filled
up, adding elements via pushDatagram(Serializable)
to the queue
is blocked until elements are taken from the queue via
receive()
.aCapacity
- The capacity of the queue holding the received
datagrams.public DATA receive() throws IOException
DatagramTransmitter
counterpart. In case none datagram is
available, then this method blocks until one is available. To prevent
blocking, use the DatagramReceiver
extension's
Availability.available()
method to test beforehand whether a
byte is available (in a multi-threaded usage scenario,
Availability.available()
is not a reliable indicator whether
this method will block or not). When a Thread
is waiting for a
datagram to be read and Thread.interrupt()
is being called, then
the operation is aborted and an InterruptedException
is thrown.receive
in interface DatagramDestination<DATA extends Serializable>
receive
in interface DatagramsDestination<DATA extends Serializable>
DatagramTransmitter
counterpart.IOException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public DATA[] receiveAll() throws IOException
receiveAll
in interface DatagramsDestination<DATA extends Serializable>
receiveAll
in interface DatagramsReceiver<DATA extends Serializable>
DatagramsTransmitter
or DatagramReceiver
counterpart.IOException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public int available() throws IOException
DatagramTransmitter
. Use the DatagramDestination
extenison's DatagramDestination.receive()
method for retrieving
available datagrams.available
in interface Availability
IOException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public void close() throws IOException
close
in interface org.refcodes.component.Closable
close
in class org.refcodes.component.AbstractConnectableAutomaton
IOException
protected void pushDatagram(DATA aDatagram) throws IOException
receive()
: use available()
to test beforehand
whether there is a datagram available.aDatagram
- The datagram to be pushed at the end of the blocking
queue; to be retrieved with the receive()
method.IOException
- the open exceptionprotected void pushDatagrams(DATA[] aDatagrams) throws IOException
receive()
: use available()
to test beforehand
whether there is a datagram available.aDatagrams
- The datagrams to be pushed at the end of the blocking
queue; to be retrieved with the receive()
method.IOException
- the open exceptionprotected void pushDatagrams(DATA[] aDatagrams, int aOffset, int aLength) throws IOException
receive()
: use available()
to test beforehand
whether there is a datagram available.aDatagrams
- The datagrams to be pushed at the end of the blocking
queue; to be retrieved with the receive()
method.aOffset
- The offset to start taking data from to be pushed.aLength
- The number of elements to be pushed from the offset
onwards.IOException
- the open exceptionCopyright © 2021. All rights reserved.