public class ReceiverDecorator<DATA extends Serializable> extends AbstractReceiver<DATA> implements Receiver<DATA>
ReceiverDecorator
decorates a Provider
with the
additional methods of a Receiver
making it easy to use a
Provider
wherever a Receiver
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>>
DATAGRAM_QUEUE_SIZE
Constructor and Description |
---|
ReceiverDecorator(Provider<DATA> aProvider) |
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. |
DATA |
readDatagram()
Reads (receives) the next datagram passed from a
DatagramSender
counterpart. |
DATA[] |
readDatagrams()
Caution: Reads till an
OpenException (or an
InterruptedException in case of blocking till more data is
available) occurs. |
DATA[] |
readDatagrams(int aBlockSize)
Similar to
BlockProvider.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 DATA readDatagram() throws org.refcodes.component.OpenException, InterruptedException
DatagramProvider
DatagramSender
counterpart. In case none datagram is available, then this method blocks
until one is available. To prevent blocking, use the
#hasDatagram()
method to test beforehand whether a datagram 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 datagram to be read and
Thread.interrupt()
is being called, then the operation is aborted
and an InterruptedException
is thrown.readDatagram
in interface DatagramProvider<DATA extends Serializable>
readDatagram
in class AbstractReceiver<DATA extends Serializable>
DatagramSender
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 AbstractReceiver<DATA extends Serializable>
#readDatagram()
method.org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public DATA[] readDatagrams() throws org.refcodes.component.OpenException, InterruptedException
Provider
OpenException
(or an
InterruptedException
in case of blocking till more data is
available) occurs.readDatagrams
in interface BlockProvider<DATA extends Serializable>
readDatagrams
in interface Provider<DATA extends Serializable>
readDatagrams
in interface Receiver<DATA extends Serializable>
readDatagrams
in class AbstractReceiver<DATA extends Serializable>
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 DATA[] readDatagrams(int aBlockSize) throws org.refcodes.component.OpenException, InterruptedException
BlockProvider
BlockProvider.readDatagrams()
though at maximum the amount of data
as provided by the block-size is returned.readDatagrams
in interface BlockProvider<DATA extends Serializable>
readDatagrams
in interface Provider<DATA extends Serializable>
readDatagrams
in interface Receiver<DATA extends Serializable>
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 BlockProvider.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 AbstractReceiver<DATA extends Serializable>
org.refcodes.component.CloseException
Copyright © 2017. All rights reserved.