java.lang.Object
org.refcodes.io.AbstractShortsDestination
org.refcodes.io.AbstractShortsReceiver
org.refcodes.io.ShortsReceiverDecorator
- All Implemented Interfaces:
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
,Availability
,Receivable
,ShortDestination
,ShortReceiver
,ShortsDestination
,ShortsReceiver
,org.refcodes.mixin.Loggable
The
ShortsReceiverDecorator
decorates a ShortsDestination
with the additional methods of a ShortsReceiver
making it easy to use
a ShortsDestination
wherever a ShortsReceiver
is expected.
This is a very plain implementation: available()
always returns true
if AbstractShortsReceiver.isOpened()
is true and as long as none of the
receiveShort()
, receiveAllShorts()
or
receiveShorts(int)
methods threw an IOException
(
InterruptedException
). This implementation actually behaves as if
close()
has been called after verifying available()
and
before any of the read methods have been called.-
Nested Class Summary
Nested classes/interfaces inherited from class org.refcodes.io.AbstractShortsReceiver
AbstractShortsReceiver.ConnectableAutomaton
Nested classes/interfaces inherited from interface org.refcodes.component.Closable
org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
Nested classes/interfaces inherited from interface org.refcodes.component.ClosedAccessor
org.refcodes.component.ClosedAccessor.ClosedMutator, org.refcodes.component.ClosedAccessor.ClosedProperty
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectableComponent
org.refcodes.component.ConnectableComponent.ConnectableAutomaton
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectionStatusAccessor
org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusProperty
Nested classes/interfaces inherited from interface org.refcodes.component.OpenedAccessor
org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedProperty
-
Field Summary
Fields inherited from class org.refcodes.io.AbstractShortsReceiver
_automaton
Fields inherited from class org.refcodes.io.AbstractShortsDestination
_datagramQueue, DATAGRAM_QUEUE_SIZE
Fields inherited from interface org.refcodes.mixin.Loggable
RUNTIME_LOGGER_CLASS, RUNTIME_LOGGER_FACTORY_CLASS, RUNTIME_LOGGER_FACTORY_METHOD
-
Constructor Summary
ConstructorDescriptionShortsReceiverDecorator
(ShortsDestination aShortProvider) Instantiates a new short receiver decorator. -
Method Summary
Modifier and TypeMethodDescriptionint
Determines the number of available datagram from aDatagramTransmitter
.void
close()
short[]
Reads (receives) the all currently available data.short
Reads (receives) the next short available, in case none short is available, then this method blocks until one is available.short[]
receiveShorts
(int aMaxLength) Similar toShortsDestination.receiveAllShorts()
though at maximum the amount of data as provided returned.Methods inherited from class org.refcodes.io.AbstractShortsReceiver
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatus
Methods inherited from class org.refcodes.io.AbstractShortsDestination
pushDatagram, pushDatagrams, pushDatagrams
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.refcodes.io.Availability
hasAvailable
Methods inherited from interface org.refcodes.component.Closable
closeIn, closeQuietly, closeUnchecked
Methods inherited from interface org.refcodes.component.Closable.CloseAutomaton
isClosable
Methods inherited from interface org.refcodes.component.ClosedAccessor
isClosed
Methods inherited from interface org.refcodes.component.ConnectionStatusAccessor
getConnectionStatus, isOpened
Methods inherited from interface org.refcodes.mixin.Loggable
alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn
Methods inherited from interface org.refcodes.io.ShortsDestination
receiveShorts
-
Constructor Details
-
ShortsReceiverDecorator
Instantiates a new short receiver decorator.- Parameters:
aShortProvider
- the short provider
-
-
Method Details
-
receiveShort
Reads (receives) the next short available, in case none short is available, then this method blocks until one is available.- Specified by:
receiveShort
in interfaceShortDestination
- Specified by:
receiveShort
in interfaceShortsDestination
- Overrides:
receiveShort
in classAbstractShortsReceiver
- Returns:
- The next short sent from the
ShortsTransmitter
counterpart. - Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
- Signals that an end of file or end of stream has been reached unexpectedly during input.
-
available
Determines the number of available datagram from aDatagramTransmitter
. Use theDatagramDestination
extenison'sDatagramDestination.receive()
method for retrieving available datagrams.- Specified by:
available
in interfaceAvailability
- Overrides:
available
in classAbstractShortsReceiver
- Returns:
- The number of datagrams ready to be retrieved .
- Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
-
receiveAllShorts
Reads (receives) the all currently available data.- Specified by:
receiveAllShorts
in interfaceShortsDestination
- Specified by:
receiveAllShorts
in interfaceShortsReceiver
- Overrides:
receiveAllShorts
in classAbstractShortsReceiver
- Returns:
- The next short block sent from the
DatagramsTransmitter
orDatagramReceiver
counterpart. - Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
- Signals that an end of file or end of stream has been reached unexpectedly during input.
-
receiveShorts
Similar toShortsDestination.receiveAllShorts()
though at maximum the amount of data as provided returned.- Specified by:
receiveShorts
in interfaceShortsDestination
- Specified by:
receiveShorts
in interfaceShortsReceiver
- Overrides:
receiveShorts
in classAbstractShortsReceiver
- Parameters:
aMaxLength
- 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 methodShortsDestination.receiveAllShorts()
.- Returns:
- The next short block sent from the
DatagramsTransmitter
orDatagramReceiver
counterpart. - Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
- Signals that an end of file or end of stream has been reached unexpectedly during input.
-
close
- Specified by:
close
in interfaceorg.refcodes.component.Closable
- Overrides:
close
in classAbstractShortsReceiver
- Throws:
IOException
-