Class AbstractPortDecorator<PM extends PortMetrics>

  • Type Parameters:
    PM - The actual PortMetrics type to use.
    All Implemented Interfaces:
    Flushable, 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.ConnectionComponent<PM>, org.refcodes.component.ConnectionComponent.ConnectionAutomaton<PM>, org.refcodes.component.ConnectionOpenable<PM>, org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<PM>, org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<PM,​Port<PM>>, org.refcodes.component.ConnectionStatusAccessor, org.refcodes.component.Flushable, org.refcodes.component.LinkComponent, org.refcodes.component.LinkComponent.LinkAutomaton, org.refcodes.component.Openable, org.refcodes.component.Openable.OpenAutomaton, org.refcodes.component.Openable.OpenBuilder<Port<PM>>, org.refcodes.component.OpenedAccessor, org.refcodes.io.Availability, org.refcodes.io.ByteDestination, org.refcodes.io.ByteReceiver, org.refcodes.io.BytesDestination, org.refcodes.io.ByteSource, org.refcodes.io.BytesReceiver, org.refcodes.io.BytesSource, org.refcodes.io.BytesTransceiver, org.refcodes.io.BytesTransmitter, org.refcodes.io.ByteTransceiver, org.refcodes.io.ByteTransmitter, org.refcodes.io.Receivable, org.refcodes.io.Skippable, org.refcodes.io.TimeoutInputStreamAccessor, org.refcodes.io.Transmittable, org.refcodes.mixin.AliasAccessor, org.refcodes.mixin.InputStreamAccessor, org.refcodes.mixin.OutputStreamAccessor, Port<PM>, PortMetricsAccessor<PM>, SegmentDestination, SegmentReceiver, SegmentSource, SegmentTransceiver, SegmentTransmitter, SerialReceiver, SerialTransceiver, SerialTransmitter

    public class AbstractPortDecorator<PM extends PortMetrics>
    extends Object
    implements Port<PM>
    The AbstractPortDecorator decorates a Port for sub-classes to enrich Port functionality.
    • Constructor Detail

      • AbstractPortDecorator

        public AbstractPortDecorator​(Port<PM> aPort)
        Decorates the given Port with the according functionality.
        Parameters:
        aPort - The Port to be decorated.
    • Method Detail

      • transmitBytes

        public void transmitBytes​(byte[] aBytes,
                                  int aOffset,
                                  int aLength)
                           throws IOException
        Specified by:
        transmitBytes in interface org.refcodes.io.BytesSource
        Specified by:
        transmitBytes in interface org.refcodes.io.BytesTransmitter
        Specified by:
        transmitBytes in interface SerialTransmitter
        Throws:
        IOException
      • getOutputStream

        public OutputStream getOutputStream()
        Specified by:
        getOutputStream in interface org.refcodes.io.BytesTransmitter
        Specified by:
        getOutputStream in interface org.refcodes.mixin.OutputStreamAccessor
      • receiveSequenceWithin

        public Sequence receiveSequenceWithin​(long aTimeoutInMs,
                                              int aLength)
                                       throws IOException
        Receives a Sequence with the number of bytes specified. This method blocks till all bytes are read or the timeout has been reached.
        Specified by:
        receiveSequenceWithin in interface SerialReceiver
        Parameters:
        aTimeoutInMs - The default timeout for read operations not explicitly called with a timeout argument. With a value of -1 timeout handling is disabled (blocking mode) or a technical timeout occurs (implementation depended).
        aLength - The number of bytes to receive.
        Returns:
        A Sequence containing the accordingly received bytes.
        Throws:
        IOException - thrown in case of I/O issues (e.g. a timeout) while receiving.
      • receiveSequence

        public Sequence receiveSequence​(int aLength)
                                 throws IOException
        Receives a Sequence with the number of bytes specified.This method blocks till all bytes are read.
        Specified by:
        receiveSequence in interface SerialReceiver
        Parameters:
        aLength - The number of bytes to receive.
        Returns:
        A Sequence containing the accordingly received bytes.
        Throws:
        IOException - thrown in case of I/O issues (e.g. a timeout) while receiving.
      • closeUnchecked

        public void closeUnchecked()
        Specified by:
        closeUnchecked in interface org.refcodes.component.Closable
      • closeQuietly

        public void closeQuietly()
        Specified by:
        closeQuietly in interface org.refcodes.component.Closable
      • closeIn

        public void closeIn​(int aCloseInMillis)
        Specified by:
        closeIn in interface org.refcodes.component.Closable
      • getAlias

        public String getAlias()
        Specified by:
        getAlias in interface org.refcodes.mixin.AliasAccessor
      • openUnchecked

        public void openUnchecked()
        Specified by:
        openUnchecked in interface org.refcodes.component.Openable
      • skip

        public long skip​(long aLength)
                  throws IOException
        Specified by:
        skip in interface org.refcodes.io.BytesReceiver
        Specified by:
        skip in interface org.refcodes.io.Skippable
        Throws:
        IOException
      • getInputStream

        public InputStream getInputStream()
        Specified by:
        getInputStream in interface org.refcodes.io.BytesReceiver
        Specified by:
        getInputStream in interface org.refcodes.mixin.InputStreamAccessor
      • getInputStream

        public org.refcodes.io.TimeoutInputStream getInputStream​(long aTimeoutInMs)
        Specified by:
        getInputStream in interface org.refcodes.io.BytesReceiver
        Specified by:
        getInputStream in interface org.refcodes.io.TimeoutInputStreamAccessor
      • receiveAllBytes

        public byte[] receiveAllBytes()
                               throws IOException
        Specified by:
        receiveAllBytes in interface org.refcodes.io.BytesDestination
        Specified by:
        receiveAllBytes in interface org.refcodes.io.BytesReceiver
        Throws:
        IOException
      • receiveBytes

        public byte[] receiveBytes​(int aMaxLength)
                            throws IOException
        Specified by:
        receiveBytes in interface org.refcodes.io.BytesDestination
        Specified by:
        receiveBytes in interface org.refcodes.io.BytesReceiver
        Specified by:
        receiveBytes in interface SerialReceiver
        Throws:
        IOException
      • receiveByteWithin

        public byte receiveByteWithin​(long aTimeoutInMs)
                               throws IOException
        Specified by:
        receiveByteWithin in interface org.refcodes.io.BytesReceiver
        Throws:
        IOException
      • receiveBytesWithin

        public byte[] receiveBytesWithin​(long aTimeoutInMs,
                                         int aLength)
                                  throws IOException
        Specified by:
        receiveBytesWithin in interface org.refcodes.io.BytesReceiver
        Throws:
        IOException
      • receiveBytesWithin

        public void receiveBytesWithin​(long aTimeoutInMs,
                                       byte[] aBuffer,
                                       int aOffset,
                                       int aLength)
                                throws IOException
        Specified by:
        receiveBytesWithin in interface org.refcodes.io.BytesReceiver
        Throws:
        IOException
      • isOpened

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

        public int available()
                      throws IOException
        Returns the number of bytes which can be read directly e.g. which are already been stored in an internal buffer. May return (0 or) a value less than 0 (-1) when it is not supported. Similar to InputStream.available(): "Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes. Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream. A subclass' implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method. The available method for class InputStream always returns 0. This method should be overridden by subclasses."
        Specified by:
        available in interface org.refcodes.io.Availability
        Specified by:
        available in interface SerialReceiver
        Specified by:
        available in interface org.refcodes.io.Skippable
        Returns:
        The number of available bytes: An estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream. Throws:
        Throws:
        IOException - - if an I/O error occurs.
      • hasAvailable

        public boolean hasAvailable()
                             throws IOException
        Specified by:
        hasAvailable in interface org.refcodes.io.Availability
        Throws:
        IOException
      • getConnectionStatus

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

        public <SEGMENT extends Segment> void doTransmitSegment​(SEGMENT aSegment,
                                                                SegmentConsumer<SEGMENT> aSegmentConsumer)
                                                         throws IOException
        Asynchronously sends a Segment's Sequence data (does not block this thread).
        Specified by:
        doTransmitSegment in interface SegmentTransmitter
        Type Parameters:
        SEGMENT - The Segment type describing the Segment subclass used.
        Parameters:
        aSegment - The Segment to be sent.
        aSegmentConsumer - The callback asynchronously invoked upon having sent the Segment.
        Throws:
        IOException - thrown in case of I/O issues (e.g. a closed connection upon the time of invocation).
      • transmitSequence

        public void transmitSequence​(Sequence aSequence,
                                     int aOffset,
                                     int aLength)
                              throws IOException
        Transmits a Sequence.
        Specified by:
        transmitSequence in interface SerialTransmitter
        Parameters:
        aSequence - The Sequence containing the data to be send.
        aOffset - The offset from where to take the chunk data.
        aLength - The number of bytes to take, beginning at the provided offset.
        Throws:
        IOException - thrown in case of I/O issues (e.g. a timeout) while sending
      • 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
      • flushUnchecked

        public void flushUnchecked()
        Specified by:
        flushUnchecked in interface org.refcodes.component.Flushable
      • isFlushable

        public boolean isFlushable()
        Specified by:
        isFlushable in interface org.refcodes.component.Flushable
      • skipAvailable

        public void skipAvailable()
                           throws IOException
        Specified by:
        skipAvailable in interface org.refcodes.io.Skippable
        Throws:
        IOException
      • skipAvailableWithin

        public void skipAvailableWithin​(long aSkipTimeSpanInMs)
                                 throws IOException
        Specified by:
        skipAvailableWithin in interface org.refcodes.io.Skippable
        Throws:
        IOException
      • skipAvailableWithin

        public void skipAvailableWithin​(long aSkipTimeSpanInMs,
                                        long aTimeoutInMs)
                                 throws IOException
        Specified by:
        skipAvailableWithin in interface org.refcodes.io.Skippable
        Throws:
        IOException
      • skipAvailableTill

        public void skipAvailableTill​(long aSkipTimeSpanInMs)
                               throws IOException
        Specified by:
        skipAvailableTill in interface org.refcodes.io.Skippable
        Throws:
        IOException
      • skipAvailableTillSilenceFor

        public void skipAvailableTillSilenceFor​(long aSilenceTimeSpanInMs)
                                         throws IOException
        Specified by:
        skipAvailableTillSilenceFor in interface org.refcodes.io.Skippable
        Throws:
        IOException
      • skipAvailableTillSilenceFor

        public void skipAvailableTillSilenceFor​(long aSilenceTimeSpanInMs,
                                                long aTimeoutInMs)
                                         throws IOException,
                                                org.refcodes.exception.TimeoutIOException
        Specified by:
        skipAvailableTillSilenceFor in interface org.refcodes.io.Skippable
        Throws:
        IOException
        org.refcodes.exception.TimeoutIOException
      • skipAvailableExcept

        public void skipAvailableExcept​(int aLength)
                                 throws IOException
        Specified by:
        skipAvailableExcept in interface org.refcodes.io.Skippable
        Throws:
        IOException
      • receiveByte

        public byte receiveByte()
                         throws IOException
        Specified by:
        receiveByte in interface org.refcodes.io.ByteDestination
        Specified by:
        receiveByte in interface org.refcodes.io.BytesDestination
        Specified by:
        receiveByte in interface SerialReceiver
        Throws:
        IOException
      • receiveBytes

        public void receiveBytes​(byte[] aBuffer,
                                 int aOffset,
                                 int aLength)
                          throws IOException
        Specified by:
        receiveBytes in interface org.refcodes.io.BytesDestination
        Throws:
        IOException
      • isOpenable

        public boolean isOpenable()
        Specified by:
        isOpenable in interface org.refcodes.component.Openable.OpenAutomaton
      • withOpenUnchecked

        public Port<PM> withOpenUnchecked()
        Specified by:
        withOpenUnchecked in interface org.refcodes.component.Openable.OpenBuilder<PM extends PortMetrics>
      • withOpenUnchecked

        public Port<PM> withOpenUnchecked​(PM aPortMetrics)
        Specified by:
        withOpenUnchecked in interface org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<PM extends PortMetrics,​Port<PM extends PortMetrics>>
      • open

        public void open​(PM aPortMetrics)
                  throws IOException
        Specified by:
        open in interface org.refcodes.component.ConnectionOpenable<PM extends PortMetrics>
        Throws:
        IOException
      • openUnchecked

        public void openUnchecked​(PM aPortMetrics)
        Specified by:
        openUnchecked in interface org.refcodes.component.ConnectionOpenable<PM extends PortMetrics>
      • isOpenable

        public boolean isOpenable​(PM aPortMetrics)
        Specified by:
        isOpenable in interface org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<PM extends PortMetrics>