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
, ByteBlockProvider
, ByteBlockReceiver
, ByteDatagramProvider
, ByteDatagramReceiver
, ByteProvider
, ByteReceiver
, Receivable
, org.refcodes.mixin.Releaseable
public class ByteReceiverDecorator extends AbstractByteReceiver implements ByteReceiver
ByteReceiverDecorator
decorates a ByteProvider
with the
additional methods of a ByteReceiver
making it easy to use a
ByteProvider
wherever a ByteReceiver
is expected.
This is a very plain implementation: hasDatagram()
always returns
true if AbstractByteReceiver.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.AbstractByteReceiver.ConnectableAutomaton
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
_automaton
Constructor | Description |
---|---|
ByteReceiverDecorator(ByteProvider aByteProvider) |
Instantiates a new byte receiver decorator.
|
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
|
boolean |
hasDatagram() |
Determines whether a datagram is available from a
DatagramSender . |
byte |
readDatagram() |
Reads (receives) the next byte passed from a
DatagramSender
counterpart. |
byte[] |
readDatagrams() |
Caution: Reads till an
OpenException (or an
InterruptedException in case of blocking till more data is
available) occurs. |
byte[] |
readDatagrams(int aBlockSize) |
Similar to
ByteBlockProvider.readDatagrams() though at maximum the amount of data
as provided by the block-size is returned. |
pushDatagram, pushDatagrams, pushDatagrams
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, releaseAll, setConnectionStatus
closeIn, closeQuietly, closeUnchecked
getConnectionStatus, isConnectionOpened
public ByteReceiverDecorator(ByteProvider aByteProvider)
aByteProvider
- the byte providerpublic byte readDatagram() throws org.refcodes.component.OpenException, InterruptedException
DatagramSender
counterpart. In case none byte is available, then this method blocks
until one is available.
To prevent blocking, use the ByteDatagramReceiver
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 byte to be read and
Thread.interrupt()
is being called, then the operation is aborted
and an InterruptedException
is thrown.readDatagram
in interface ByteDatagramProvider
readDatagram
in class AbstractByteReceiver
ByteDatagramSender
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 AbstractByteReceiver
org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public byte[] 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 byte block passed from a BlockSender
or
DatagramSender
counterpart. In case none byte block is available,
then this method blocks until one is available.
When a Thread
is waiting for a byte to be read and
Thread.interrupt()
is being called, then the operation is aborted
and an InterruptedException
is thrown.readDatagrams
in interface ByteBlockProvider
readDatagrams
in interface ByteProvider
readDatagrams
in interface ByteReceiver
readDatagrams
in class AbstractByteReceiver
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 byte[] readDatagrams(int aBlockSize) throws org.refcodes.component.OpenException, InterruptedException
ByteBlockProvider.readDatagrams()
though at maximum the amount of data
as provided by the block-size is returned.readDatagrams
in interface ByteBlockProvider
readDatagrams
in interface ByteProvider
readDatagrams
in interface ByteReceiver
readDatagrams
in class AbstractByteReceiver
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 ByteBlockProvider.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 AbstractByteReceiver
org.refcodes.component.CloseException
Copyright © 2018. All rights reserved.