public class ShortReceiverDecorator extends AbstractShortReceiver implements ShortReceiver
ShortReceiverDecorator
decorates a ShortProvider
with the
additional methods of a ShortReceiver
making it easy to use a
ShortProvider
wherever a ShortReceiver
is expected.
This is a very plain implementation: hasDatagram()
always returns
true if AbstractConnectableAutomaton.isOpened()
is true and as long as none of the
readDatagram()
, readDatagrams()
or
readDatagrams(int)
methods threw an OpenException
(
InterruptedException
).
This implementation actually behaves as if close()
has been called
after verifying hasDatagram()
and before any of the read methods
have been called.org.refcodes.component.ConnectableComponent.ConnectableAutomaton
org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedProperty
org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
_datagramQueue, DATAGRAM_QUEUE_SIZE
Constructor and Description |
---|
ShortReceiverDecorator(ShortProvider aShortProvider) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
boolean |
hasDatagram()
Determines whether a datagram is available from a
DatagramSender
and can be retrieved via the #readDatagram() method. |
short |
readDatagram()
Reads (receives) the next short passed from a
DatagramSender
counterpart. |
short[] |
readDatagrams()
Caution: Reads till an
OpenException (or an
InterruptedException in case of blocking till more data is
available) occurs. |
short[] |
readDatagrams(int aBlockSize)
Similar to
ShortBlockProvider.readDatagrams() though at maximum the amount of data
as provided by the block-size is returned. |
pushDatagram, pushDatagrams, pushDatagrams, releaseAll
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatus
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public ShortReceiverDecorator(ShortProvider aShortProvider)
public short readDatagram() throws org.refcodes.component.OpenException, InterruptedException
ShortDatagramProvider
DatagramSender
counterpart. In case none short is available, then this method blocks
until one is available. To prevent blocking, use the
#hasDatagram()
method to test beforehand whether a short is
available (in a multi-threaded usage scenario, #hasDatagram()
is
not a reliable indicator whether this method will block or not).
When a Thread
is waiting for a short to be read and
Thread.interrupt()
is being called, then the operation is aborted
and an InterruptedException
is thrown.readDatagram
in interface ShortDatagramProvider
readDatagram
in class AbstractShortReceiver
ShortDatagramSender
counterpart.org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.InterruptedException
- Thrown when a Thread
is waiting,
sleeping, or otherwise occupied, and the Thread
is
interrupted, either before or during the activity.public boolean hasDatagram() throws org.refcodes.component.OpenException
Receivable
DatagramSender
and can be retrieved via the #readDatagram()
method.hasDatagram
in interface Receivable
hasDatagram
in class AbstractShortReceiver
#readDatagram()
method.org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public short[] readDatagrams() throws org.refcodes.component.OpenException, InterruptedException
ShortProvider
OpenException
(or an
InterruptedException
in case of blocking till more data is
available) occurs.readDatagrams
in interface ShortBlockProvider
readDatagrams
in interface ShortProvider
readDatagrams
in interface ShortReceiver
readDatagrams
in class AbstractShortReceiver
BlockSender
or
DatagramReceiver
counterpart.org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.InterruptedException
- Thrown when a Thread
is waiting,
sleeping, or otherwise occupied, and the Thread
is
interrupted, either before or during the activity.public short[] readDatagrams(int aBlockSize) throws org.refcodes.component.OpenException, InterruptedException
ShortBlockProvider
ShortBlockProvider.readDatagrams()
though at maximum the amount of data
as provided by the block-size is returned.readDatagrams
in interface ShortBlockProvider
readDatagrams
in interface ShortProvider
readDatagrams
in interface ShortReceiver
readDatagrams
in class AbstractShortReceiver
aBlockSize
- 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 method ShortBlockProvider.readDatagrams()
.BlockSender
or
DatagramReceiver
counterpart.org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.InterruptedException
- Thrown when a Thread
is waiting,
sleeping, or otherwise occupied, and the Thread
is
interrupted, either before or during the activity.public void close() throws org.refcodes.component.CloseException
close
in interface org.refcodes.component.Closable
close
in class AbstractShortReceiver
org.refcodes.component.CloseException
Copyright © 2017. All rights reserved.