- java.lang.Object
-
- org.refcodes.io.AbstractShortsDestination
-
- All Implemented Interfaces:
ShortDestination
,ShortsDestination
,org.refcodes.mixin.Loggable
- Direct Known Subclasses:
AbstractShortsReceiver
public abstract class AbstractShortsDestination extends Object implements ShortsDestination, org.refcodes.mixin.Loggable
TheAbstractShortsDestination
is a base abstract implementation of theShortsDestination
interface providing common functionality for concrete real live implementations.
-
-
Field Summary
Fields Modifier and Type Field Description protected LinkedBlockingQueue<Short>
_datagramQueue
static int
DATAGRAM_QUEUE_SIZE
-
Constructor Summary
Constructors Constructor Description AbstractShortsDestination()
Constructs aAbstractShortsDestination
with a default sized blocking queue enabling a maximum ofDATAGRAM_QUEUE_SIZE
datagrams. ------------------------------------------------------------------------- Make sure your code fetches the datagrams quick enough to prevent filling up of the queue.AbstractShortsDestination(int aCapacity)
Constructs aAbstractShortsDestination
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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
pushDatagram(short aDatagram)
Pushes a datagram into the receiver and puts it into the blocking queue containing the so far received datagrams.protected void
pushDatagrams(short[] aDatagrams)
Pushes datagrams into the receiver and puts them into the blocking queue containing the so far received datagrams.protected void
pushDatagrams(short[] aDatagrams, int aOffset, int aLength)
Pushes datagrams into the receiver and puts them into the blocking queue containing the so far received datagrams.short[]
receiveAllShorts()
Reads (receives) the all currently available data.short
receiveShort()
Reads (receives) the next short available, in case none short is available, then this method blocks until one is available.short[]
receiveShorts(int aMaxLength)
Similar toShortsDestination.receiveAllShorts()
though at maximum the amount of data as provided returned.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.mixin.Loggable
alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn
-
Methods inherited from interface org.refcodes.io.ShortsDestination
receiveShorts
-
-
-
-
Field Detail
-
DATAGRAM_QUEUE_SIZE
public static final int DATAGRAM_QUEUE_SIZE
- See Also:
- Constant Field Values
-
_datagramQueue
protected LinkedBlockingQueue<Short> _datagramQueue
-
-
Constructor Detail
-
AbstractShortsDestination
public AbstractShortsDestination()
Constructs aAbstractShortsDestination
with a default sized blocking queue enabling a maximum ofDATAGRAM_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 viapushDatagram(short)
to the queue is blocked until elements are taken from the queue viareceiveShort()
.
-
AbstractShortsDestination
public AbstractShortsDestination(int aCapacity)
Constructs aAbstractShortsDestination
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 viapushDatagram(short)
to the queue is blocked until elements are taken from the queue viareceiveShort()
.- Parameters:
aCapacity
- The capacity of the queue holding the received datagrams.
-
-
Method Detail
-
receiveShort
public short receiveShort() throws IOException, EOFException
Reads (receives) the next short available, in case none short is available, then this method blocks until one is available.- Specified by:
receiveShort
in interfaceShortDestination
- Specified by:
receiveShort
in interfaceShortsDestination
- Returns:
- The next short sent from the
ShortsTransmitter
counterpart. - Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
- Signals that an end of file or end of stream has been reached unexpectedly during input.
-
receiveAllShorts
public short[] receiveAllShorts() throws IOException
Reads (receives) the all currently available data.- Specified by:
receiveAllShorts
in interfaceShortsDestination
- Returns:
- The next short block sent from the
DatagramsTransmitter
orDatagramReceiver
counterpart. - Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
- Signals that an end of file or end of stream has been reached unexpectedly during input.
-
receiveShorts
public short[] receiveShorts(int aMaxLength) throws IOException
Similar toShortsDestination.receiveAllShorts()
though at maximum the amount of data as provided returned.- Specified by:
receiveShorts
in interfaceShortsDestination
- Parameters:
aMaxLength
- The block-size which is not to exceeded by the returned data. A value of -1 specifies to retrieve all available datagrams (same behavior as methodShortsDestination.receiveAllShorts()
.- Returns:
- The next short block sent from the
DatagramsTransmitter
orDatagramReceiver
counterpart. - Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
- Signals that an end of file or end of stream has been reached unexpectedly during input.
-
pushDatagram
protected void pushDatagram(short aDatagram) throws IOException
Pushes a datagram into the receiver and puts it into the blocking queue containing the so far received datagrams. Them datagrams can be retrieved viareceiveShort()
: UseAbstractBytesReceiver
extension'sAbstractBytesReceiver.available()
to test beforehand whether there is a datagram available.- Parameters:
aDatagram
- The datagram to be pushed at the end of the blocking queue; to be retrieved with thereceiveShort()
method.- Throws:
IOException
- the open exception
-
pushDatagrams
protected void pushDatagrams(short[] aDatagrams) throws IOException
Pushes datagrams into the receiver and puts them into the blocking queue containing the so far received datagrams. Them datagrams can be retrieved viareceiveShort()
: UseAbstractBytesReceiver
extension'sAbstractBytesReceiver.available()
to test beforehand whether there is a datagram available.- Parameters:
aDatagrams
- The datagrams to be pushed at the end of the blocking queue; to be retrieved with thereceiveShort()
method.- Throws:
IOException
- the open exception
-
pushDatagrams
protected void pushDatagrams(short[] aDatagrams, int aOffset, int aLength) throws IOException
Pushes datagrams into the receiver and puts them into the blocking queue containing the so far received datagrams. Them datagrams can be retrieved viareceiveShort()
: UseAbstractBytesReceiver
extension'sAbstractBytesReceiver.available()
to test beforehand whether there is a datagram available.- Parameters:
aDatagrams
- The datagrams to be pushed at the end of the blocking queue; to be retrieved with thereceiveShort()
method.aOffset
- The offset to start taking data from to be pushed.aLength
- The number of elements to be pushed from the offset onwards.- Throws:
IOException
- the open exception
-
-