Class AbstractBytesDestination
java.lang.Object
org.refcodes.component.AbstractConnectable
org.refcodes.io.AbstractBytesDestination
- All Implemented Interfaces:
ByteDestination, BytesDestination
- Direct Known Subclasses:
AbstractBytesReceiver
public abstract class AbstractBytesDestination
extends AbstractConnectable
implements BytesDestination
The
AbstractBytesDestination is a base abstract implementation of the
BytesDestination interface providing common functionality for
concrete real implementations. A blocking queue is used internally to which
received datagrams are put via pushDatagram(byte) and which can be
retrieved via receiveByte(). The pushDatagram(byte) method
is your hook when extending this class. 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(byte) to the queue is
blocked until elements are taken from the queue via receiveByte().
So cautions are taken to prevent a memory leak.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aAbstractBytesDestinationwith a default sized blocking queue enabling a maximum ofDATAGRAM_QUEUE_SIZEdatagrams. ------------------------------------------------------------------------- Make sure your code fetches the datagrams quick enough to prevent filling up of the queue.AbstractBytesDestination(int aCapacity) Constructs aAbstractBytesDestinationwith 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
Modifier and TypeMethodDescriptionprotected voidpushDatagram(byte aDatagram) Pushes a datagram into the receiver and puts it into the blocking queue containing the so far received datagrams.protected voidpushDatagrams(byte[] aDatagrams) Pushes datagrams into the receiver and puts them into the blocking queue containing the so far received datagrams.protected voidpushDatagrams(byte[] aDatagrams, int aOffset, int aLength) Pushes datagrams into the receiver and puts them into the blocking queue containing the so far received datagrams.byte[]Reads (receives) the all currently available data.byteReads (receives) the next byte, in case none byte is available, then this method blocks until one is available.byte[]receiveBytes(int aLength) Similar toBytesDestination.receiveAllBytes()though at maximum the amount of data as of the provided length returned.Methods inherited from class AbstractConnectable
isThrownAsOfAlreadyClosedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BytesDestination
receiveBytes
-
Field Details
-
DATAGRAM_QUEUE_SIZE
public static final int DATAGRAM_QUEUE_SIZE- See Also:
-
_datagramQueue
-
-
Constructor Details
-
AbstractBytesDestination
public AbstractBytesDestination()Constructs aAbstractBytesDestinationwith a default sized blocking queue enabling a maximum ofDATAGRAM_QUEUE_SIZEdatagrams. ------------------------------------------------------------------------- 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(byte)to the queue is blocked until elements are taken from the queue viareceiveByte(). -
AbstractBytesDestination
public AbstractBytesDestination(int aCapacity) Constructs aAbstractBytesDestinationwith 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(byte)to the queue is blocked until elements are taken from the queue viareceiveByte().- Parameters:
aCapacity- The capacity of the queue holding the received datagrams.
-
-
Method Details
-
receiveByte
Reads (receives) the next byte, in case none byte is available, then this method blocks until one is available.- Specified by:
receiveBytein interfaceByteDestination- Specified by:
receiveBytein interfaceBytesDestination- Returns:
- The next byte available .
- Throws:
IOException- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
receiveAllBytes
Reads (receives) the all currently available data.- Specified by:
receiveAllBytesin interfaceBytesDestination- Returns:
- The according data.
- Throws:
IOException- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
receiveBytes
Similar toBytesDestination.receiveAllBytes()though at maximum the amount of data as of the provided length returned.- Specified by:
receiveBytesin interfaceBytesDestination- Parameters:
aLength- 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 methodBytesDestination.receiveAllBytes().- Returns:
- The according data.
- Throws:
IOException- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
pushDatagram
Pushes a datagram into the receiver and puts it into the blocking queue containing the so far received datagrams. Them datagrams can be retrieved viareceiveByte(): UseAbstractBytesReceiverextension'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 thereceiveByte()method.- Throws:
IOException- the open exception
-
pushDatagrams
Pushes datagrams into the receiver and puts them into the blocking queue containing the so far received datagrams. Them datagrams can be retrieved viareceiveByte(): UseAbstractBytesReceiverextension'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 thereceiveByte()method.- Throws:
IOException- the open exception
-
pushDatagrams
Pushes datagrams into the receiver and puts them into the blocking queue containing the so far received datagrams. Them datagrams can be retrieved viareceiveByte(): UseAbstractBytesReceiverextension'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 thereceiveByte()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
-