java.lang.Object
org.refcodes.component.AbstractConnectable
org.refcodes.io.AbstractBytesDestination
org.refcodes.io.AbstractBytesReceiver
- 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,ByteDestination,ByteReceiver,BytesDestination,BytesReceiver,Receivable,Skippable,TimeoutInputStreamAccessor,org.refcodes.mixin.InputStreamAccessor
- Direct Known Subclasses:
AbstractPrefetchInputStreamByteReceiver,ByteArrayReceiver,BytesReceiverDecorator,LoopbackBytesReceiver,LoopbackBytesTransceiver
public abstract class AbstractBytesReceiver
extends AbstractBytesDestination
implements BytesReceiver
The
AbstractBytesReceiver is a base abstract implementation of the
BytesReceiver interface providing common functionality for concrete
real live implementations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThe Class ConnectableAutomaton.Nested classes/interfaces inherited from interface org.refcodes.io.BytesReceiver
BytesReceiver.ReceiverInputStreamNested 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.ClosedPropertyNested classes/interfaces inherited from interface org.refcodes.component.ConnectionStatusAccessor
org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusPropertyNested classes/interfaces inherited from interface org.refcodes.mixin.InputStreamAccessor
org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<B extends org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<?>>, org.refcodes.mixin.InputStreamAccessor.InputStreamMutator, org.refcodes.mixin.InputStreamAccessor.InputStreamPropertyNested classes/interfaces inherited from interface org.refcodes.component.OpenedAccessor
org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedPropertyNested classes/interfaces inherited from interface org.refcodes.io.TimeoutInputStreamAccessor
TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<B extends TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<?>>, TimeoutInputStreamAccessor.TimeoutInputStreamMutator, TimeoutInputStreamAccessor.TimeoutInputStreamProperty -
Field Summary
FieldsFields inherited from class org.refcodes.io.AbstractBytesDestination
_datagramQueue, DATAGRAM_QUEUE_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aAbstractBytesReceiverwith a default sized blocking queue enabling a maximum ofAbstractBytesDestination.DATAGRAM_QUEUE_SIZEdatagrams. ------------------------------------------------------------------------- Make sure your code fetches the datagrams quick enough to prevent filling up of the queue.AbstractBytesReceiver(int aCapacity) Constructs aAbstractBytesReceiverwith a custom sized blocking queue enabling a maximum of datagrams as specified by the capacity parameter. ------------------------------------------------------------------------- Make sure your code fetches the datagrams quick enough to prevent filling up of the queue. -
Method Summary
Modifier and TypeMethodDescriptionintDetermines the number of available datagram from aDatagramTransmitter.voidclose()org.refcodes.component.ConnectionStatusbooleanbooleanisClosed()protected booleanChecks if is openable.booleanisOpened()protected voidopen()Open.byte[]Reads (receives) the all currently available data.byteReads (receives) the next byte, in case none byte is available, then this method blocks until one is available.byte[]receiveBytes(int aLength) Similar toBytesDestination.receiveAllBytes()though at maximum the amount of data as of the provided length returned.protected voidsetConnectionStatus(org.refcodes.component.ConnectionStatus aConnectionStatus) Sets the connection status.Methods inherited from class org.refcodes.io.AbstractBytesDestination
pushDatagram, pushDatagrams, pushDatagramsMethods inherited from class org.refcodes.component.AbstractConnectable
isThrownAsOfAlreadyClosedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.refcodes.io.Availability
hasAvailableMethods inherited from interface org.refcodes.io.BytesDestination
receiveBytesMethods inherited from interface org.refcodes.io.BytesReceiver
getInputStream, getInputStream, receiveBytesWithin, receiveBytesWithin, receiveByteWithin, skipMethods inherited from interface org.refcodes.component.Closable
closeIn, closeQuietly, closeUncheckedMethods inherited from interface org.refcodes.io.Skippable
skipAvailable, skipAvailableExcept, skipAvailableTill, skipAvailableTillSilenceFor, skipAvailableTillSilenceFor, skipAvailableWithin, skipAvailableWithin, skipAvailableWithin
-
Field Details
-
_automaton
-
-
Constructor Details
-
AbstractBytesReceiver
public AbstractBytesReceiver()Constructs aAbstractBytesReceiverwith a default sized blocking queue enabling a maximum ofAbstractBytesDestination.DATAGRAM_QUEUE_SIZEdatagrams. ------------------------------------------------------------------------- Make sure your code fetches the datagrams quick enough to prevent filling up of the queue. In case the queue is filled up, adding elements viaAbstractBytesDestination.pushDatagram(byte)to the queue is blocked until elements are taken from the queue viareceiveByte(). -
AbstractBytesReceiver
public AbstractBytesReceiver(int aCapacity) Constructs aAbstractBytesReceiverwith a custom sized blocking queue enabling a maximum of datagrams as specified by the capacity parameter. ------------------------------------------------------------------------- Make sure your code fetches the datagrams quick enough to prevent filling up of the queue. In case the queue is filled up, adding elements viaAbstractBytesDestination.pushDatagram(byte)to the queue is blocked until elements are taken from the queue viareceiveByte().- Parameters:
aCapacity- The capacity of the queue holding the received datagrams.
-
-
Method Details
-
receiveByte
Reads (receives) the next byte, in case none byte is available, then this method blocks until one is available.- Specified by:
receiveBytein interfaceByteDestination- Specified by:
receiveBytein interfaceBytesDestination- Overrides:
receiveBytein classAbstractBytesDestination- Returns:
- The next byte available .
- 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.
-
receiveAllBytes
Reads (receives) the all currently available data.- Specified by:
receiveAllBytesin interfaceBytesDestination- Specified by:
receiveAllBytesin interfaceBytesReceiver- Overrides:
receiveAllBytesin classAbstractBytesDestination- Returns:
- The according data.
- 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.
-
receiveBytes
Similar toBytesDestination.receiveAllBytes()though at maximum the amount of data as of the provided length returned.- Specified by:
receiveBytesin interfaceBytesDestination- Specified by:
receiveBytesin interfaceBytesReceiver- Overrides:
receiveBytesin classAbstractBytesDestination- Parameters:
aLength- 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 methodBytesDestination.receiveAllBytes().- Returns:
- The according data.
- 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 theDatagramDestinationextenison'sDatagramDestination.receive()method for retrieving available datagrams.- Specified by:
availablein interfaceAvailability- Specified by:
availablein interfaceSkippable- 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.
-
close
- Specified by:
closein interfaceorg.refcodes.component.Closable- Throws:
IOException
-
isOpened
public boolean isOpened()- Specified by:
isOpenedin interfaceorg.refcodes.component.ConnectionStatusAccessor- Specified by:
isOpenedin interfaceorg.refcodes.component.OpenedAccessor
-
isClosable
public boolean isClosable()- Specified by:
isClosablein interfaceorg.refcodes.component.Closable.CloseAutomaton
-
isClosed
public boolean isClosed()- Specified by:
isClosedin interfaceorg.refcodes.component.ClosedAccessor
-
getConnectionStatus
public org.refcodes.component.ConnectionStatus getConnectionStatus()- Specified by:
getConnectionStatusin interfaceorg.refcodes.component.ConnectionStatusAccessor
-
open
Open.- Throws:
IOException- the open exception
-
setConnectionStatus
protected void setConnectionStatus(org.refcodes.component.ConnectionStatus aConnectionStatus) Sets the connection status.- Parameters:
aConnectionStatus- the new connection status
-
isOpenable
protected boolean isOpenable()Checks if is openable.- Returns:
- true, if is openable
-