Class AbstractShortsReceiver

java.lang.Object
org.refcodes.io.AbstractShortsDestination
org.refcodes.io.AbstractShortsReceiver
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
Direct Known Subclasses:
LoopbackShortsReceiver, LoopbackShortsTransceiver, ShortArrayReceiver, ShortsReceiverDecorator

public abstract class AbstractShortsReceiver extends AbstractShortsDestination implements ShortsReceiver
The AbstractShortsReceiver is a base abstract implementation of the ShortsReceiver interface providing common functionality for concrete real live implementations.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
    The Class 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.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
    Modifier and Type
    Field
    Description
     

    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

    Constructors
    Constructor
    Description
    Constructs a AbstractShortsReceiver with a default sized blocking queue enabling a maximum of AbstractShortsDestination.DATAGRAM_QUEUE_SIZE datagrams. ------------------------------------------------------------------------- Make sure your code fetches the datagrams quick enough to prevent filling up of the queue.
    AbstractShortsReceiver(int aCapacity)
    Constructs a AbstractShortsReceiver with 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 Type
    Method
    Description
    int
    Determines the number of available datagram from a DatagramTransmitter.
    void
    org.refcodes.component.ConnectionStatus
    boolean
    boolean
    protected boolean
    Checks if is openable.
    boolean
    protected void
    Open.
    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 to ShortsDestination.receiveAllShorts() though at maximum the amount of data as provided returned.
    protected void
    setConnectionStatus(org.refcodes.component.ConnectionStatus aConnectionStatus)
    Sets the connection status.

    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.mixin.Loggable

    alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn

    Methods inherited from interface org.refcodes.io.ShortsDestination

    receiveShorts
  • Field Details

  • Constructor Details

    • AbstractShortsReceiver

      public AbstractShortsReceiver()
      Constructs a AbstractShortsReceiver with a default sized blocking queue enabling a maximum of AbstractShortsDestination.DATAGRAM_QUEUE_SIZE datagrams. ------------------------------------------------------------------------- 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 via AbstractShortsDestination.pushDatagram(short) to the queue is blocked until elements are taken from the queue via receiveShort().
    • AbstractShortsReceiver

      public AbstractShortsReceiver(int aCapacity)
      Constructs a AbstractShortsReceiver with 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 via AbstractShortsDestination.pushDatagram(short) to the queue is blocked until elements are taken from the queue via receiveShort().
      Parameters:
      aCapacity - The capacity of the queue holding the received datagrams.
  • Method Details

    • receiveShort

      public short receiveShort() throws IOException, EOFException
      Reads (receives) the next short available, in case none short is available, then this method blocks until one is available.
      Specified by:
      receiveShort in interface ShortDestination
      Specified by:
      receiveShort in interface ShortsDestination
      Overrides:
      receiveShort in class AbstractShortsDestination
      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.
    • receiveAllShorts

      public short[] receiveAllShorts() throws IOException, EOFException
      Reads (receives) the all currently available data.
      Specified by:
      receiveAllShorts in interface ShortsDestination
      Specified by:
      receiveAllShorts in interface ShortsReceiver
      Overrides:
      receiveAllShorts in class AbstractShortsDestination
      Returns:
      The next short block sent from the DatagramsTransmitter or DatagramReceiver 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

      public short[] receiveShorts(int aMaxLength) throws IOException, EOFException
      Similar to ShortsDestination.receiveAllShorts() though at maximum the amount of data as provided returned.
      Specified by:
      receiveShorts in interface ShortsDestination
      Specified by:
      receiveShorts in interface ShortsReceiver
      Overrides:
      receiveShorts in class AbstractShortsDestination
      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 method ShortsDestination.receiveAllShorts().
      Returns:
      The next short block sent from the DatagramsTransmitter or DatagramReceiver 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

      public int available() throws IOException
      Determines the number of available datagram from a DatagramTransmitter. Use the DatagramDestination extenison's DatagramDestination.receive() method for retrieving available datagrams.
      Specified by:
      available in interface Availability
      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

      public void close() throws IOException
      Specified by:
      close in interface org.refcodes.component.Closable
      Throws:
      IOException
    • isOpened

      public boolean isOpened()
      Specified by:
      isOpened in interface org.refcodes.component.ConnectionStatusAccessor
      Specified by:
      isOpened in interface org.refcodes.component.OpenedAccessor
    • isClosable

      public boolean isClosable()
      Specified by:
      isClosable in interface org.refcodes.component.Closable.CloseAutomaton
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface org.refcodes.component.ClosedAccessor
    • getConnectionStatus

      public org.refcodes.component.ConnectionStatus getConnectionStatus()
      Specified by:
      getConnectionStatus in interface org.refcodes.component.ConnectionStatusAccessor
    • open

      protected void open() throws IOException
      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