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
, Receivable
, ShortBlockProvider
, ShortBlockReceiver
, ShortDatagramProvider
, ShortDatagramReceiver
, ShortProvider
, ShortReceiver
, org.refcodes.mixin.Loggable
, org.refcodes.mixin.Releaseable
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.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
_datagramQueue, DATAGRAM_QUEUE_SIZE
Constructor | Description |
---|---|
ShortReceiverDecorator(ShortProvider aShortProvider) |
Instantiates a new short receiver decorator.
|
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
|
boolean |
hasDatagram() |
Determines whether a datagram is available from a
DatagramSender . |
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. |
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatus
pushDatagram, pushDatagrams, pushDatagrams, releaseAll
closeIn, closeQuietly, closeUnchecked
getConnectionStatus, isConnectionOpened
alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn
public ShortReceiverDecorator(ShortProvider aShortProvider)
aShortProvider
- the short providerpublic short readDatagram() throws org.refcodes.component.OpenException, InterruptedException
DatagramSender
counterpart. In case none short is available, then this method blocks
until one is available.
To prevent blocking, use the ShortDatagramReceiver
extension's
Receivable.hasDatagram()
method to test beforehand
whether a byte is available (in a multi-threaded usage scenario,
Receivable.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
DatagramSender
.
Use the DatagramProvider
extenison's
DatagramProvider.readDatagram()
method for retrieving the
available datagram.hasDatagram
in interface Receivable
hasDatagram
in class AbstractShortReceiver
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
OpenException
(or an
InterruptedException
in case of blocking till more data is
available) occurs.
Reads (receives) the next short block passed from a BlockSender
or DatagramSender
counterpart. In case none short block is
available, then this method blocks until one is available.
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.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.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 © 2018. All rights reserved.