Class AbstractStopAndWaitPacketStreamTransmissionDecorator<DECORATEE extends Transmission>

java.lang.Object
org.refcodes.serial.AbstractStopAndWaitPacketStreamTransmissionDecorator<DECORATEE>
Type Parameters:
DECORATEE - The decoratee type describing the according subclass to be chunked into blocks and enriched with a CRC checksum and a sequence number.
All Implemented Interfaces:
Serializable, org.refcodes.mixin.BlockSizeAccessor, org.refcodes.mixin.DecorateeAccessor<DECORATEE>, org.refcodes.mixin.LengthAccessor, org.refcodes.mixin.PacketSizeAccessor, org.refcodes.mixin.Schemable<SerialSchema>, org.refcodes.numerical.EndianessAccessor, AcknowledgeMagicBytesAccessor, AcknowledgeRetryNumberAccessor, AcknowledgeSegmentPackagerAccessor, AcknowledgeTimeoutInMsAccessor, SequenceNumberInitValueAccessor, StopAndWaitPacketStreamTransmission, Transmission, Transmission.TransmissionMixin
Direct Known Subclasses:
StopAndWaitPacketStreamSectionDecorator, StopAndWaitPacketStreamSegmentDecorator

public abstract class AbstractStopAndWaitPacketStreamTransmissionDecorator<DECORATEE extends Transmission> extends Object implements Transmission.TransmissionMixin, StopAndWaitPacketStreamTransmission, org.refcodes.mixin.DecorateeAccessor<DECORATEE>, org.refcodes.mixin.PacketSizeAccessor
A AbstractStopAndWaitPacketStreamTransmissionDecorator wraps a Transmission instance and enriches the Transmission with packet-stream functionality. A packet consists of a sequence number, a block of data and a CRC checksum in the order of the ConcatenateMode being used.
See Also:
  • Field Details

    • ENDIANESS

      public static final String ENDIANESS
      See Also:
    • SEQUENCE_NUMBER_WIDTH

      public static final String SEQUENCE_NUMBER_WIDTH
      See Also:
    • SEQUENCE_NUMBER_INIT_VALUE

      public static final String SEQUENCE_NUMBER_INIT_VALUE
      See Also:
    • BLOCK_SIZE

      public static final String BLOCK_SIZE
      See Also:
    • ACK_MAGIC_BYTES

      public static final String ACK_MAGIC_BYTES
      See Also:
    • ACK_TIMEOUT_IN_MS

      public static final String ACK_TIMEOUT_IN_MS
      See Also:
    • ACK_RETRY_NUMBER

      public static final String ACK_RETRY_NUMBER
      See Also:
    • _decoratee

      protected DECORATEE extends Transmission _decoratee
    • _blockSize

      protected int _blockSize
    • _acknowledgeMagicBytes

      protected byte[] _acknowledgeMagicBytes
    • _acknowledgeRetryNumber

      protected int _acknowledgeRetryNumber
    • _acknowledgeTimeoutInMs

      protected long _acknowledgeTimeoutInMs
    • _crcChecksum

      protected long _crcChecksum
    • _endianess

      protected org.refcodes.numerical.Endianess _endianess
    • _sequenceNumberWidth

      protected int _sequenceNumberWidth
    • _sequenceNumberInitValue

      protected int _sequenceNumberInitValue
    • _sequenceNumberConcatenateMode

      protected org.refcodes.mixin.ConcatenateMode _sequenceNumberConcatenateMode
    • _acknowledgeSegmentPackager

      protected SegmentPackager _acknowledgeSegmentPackager
    • _packetSegmentPackager

      protected SegmentPackager _packetSegmentPackager
    • _packetSize

      protected int _packetSize
    • _lastPacketMagicBytes

      protected byte[] _lastPacketMagicBytes
    • _packetMagicBytes

      protected byte[] _packetMagicBytes
    • _packetLengthWidth

      protected int _packetLengthWidth
  • Constructor Details

    • AbstractStopAndWaitPacketStreamTransmissionDecorator

      public AbstractStopAndWaitPacketStreamTransmissionDecorator(DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
      Constructs an according packet-stream decorator instance wrapping the given OutputStream. The configuration attributes are taken from the TransmissionMetrics configuration object, though only those attributes are supported which are also supported by the other constructors!
      Parameters:
      aDecoratee - The decoratee to be wrapped by the packet-stream decorator.
      aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
    • AbstractStopAndWaitPacketStreamTransmissionDecorator

      public AbstractStopAndWaitPacketStreamTransmissionDecorator(DECORATEE aDecoratee, int aBlockSize, int aPacketLengthWidth, byte[] aPacketMagicBytes, int aSequenceNumberInitValue, int aSequenceNumberWidth, org.refcodes.mixin.ConcatenateMode aSequenceNumberConcatenateMode, SegmentPackager aPacketSegmentPackager, byte[] aAcknowledgeMagicBytes, int aAcknowledgeRetryNumber, long aAcknowledgeTimeoutInMs, SegmentPackager aAckSegmentPackager, org.refcodes.numerical.Endianess aEndianess)
      Constructs an according packet-stream decorator instance wrapping the given OutputStream.
      Parameters:
      aDecoratee - The decoratee to be wrapped by the packet-stream decorator.
      aBlockSize - The block size of a data block for each packet.
      aPacketLengthWidth - The width (bytes) for declaring the (max) length of a package.
      aPacketMagicBytes - The magic bytes identifying a packet and distinguishing a packet from a last package.
      aSequenceNumberInitValue - The initial sequence number from where to start counting the blocks.
      aSequenceNumberWidth - The width (in bytes) to be used for sequence number values.
      aSequenceNumberConcatenateMode - The mode of concatenation to use when creating a Sequence from this Transmission and the decorated Transmission.
      aPacketSegmentPackager - An (optional) SegmentPackager used to modify a packet's data e.g. with a CRC checksum.
      aAcknowledgeMagicBytes - The ACK character(s) to be used by the return channel to transmit an ACK (acknowledge) response after successful receiving a transmission.
      aAcknowledgeRetryNumber - The number of retries waiting for an ACK from the return channel.
      aAcknowledgeTimeoutInMs - The timeout in milliseconds to pend till the next retry.
      aAckSegmentPackager - An (optional) SegmentPackager used to modify a ACK response data e.g. with a CRC checksum.
      aEndianess - The Endianess to use for integer (double) numbers and the like.
  • Method Details

    • getCrcChecksumConcatenateMode

      public org.refcodes.mixin.ConcatenateMode getCrcChecksumConcatenateMode()
      Returns the ConcatenateMode describing the positions of the sequence number, the block data and the CRC checksum within the packet.
      Returns:
      The according ConcatenateMode.
    • getSequenceNumberWidth

      public int getSequenceNumberWidth()
      Retrieves the width (in bytes) dedicated for the sequence number.
      Returns:
      The according length of the sequence number.
    • getBlockSize

      public int getBlockSize()
      Specified by:
      getBlockSize in interface org.refcodes.mixin.BlockSizeAccessor
    • getPacketSize

      public int getPacketSize()
      ATTENTION: The packet size is not available until transmission has been put into effect!
      Specified by:
      getPacketSize in interface org.refcodes.mixin.PacketSizeAccessor
    • getLength

      public int getLength()
      Determines the overall length of this Transmission. In case of nested Transmission instances, all length values from all sub-segments are accumulated to the result as well.
      Specified by:
      getLength in interface org.refcodes.mixin.LengthAccessor
      Specified by:
      getLength in interface Transmission
      Returns:
      The (overall) length of the Transmission (including any sub-segments).
    • getDecoratee

      public DECORATEE getDecoratee()
      Specified by:
      getDecoratee in interface org.refcodes.mixin.DecorateeAccessor<DECORATEE extends Transmission>
    • getEndianess

      public org.refcodes.numerical.Endianess getEndianess()
      Specified by:
      getEndianess in interface org.refcodes.numerical.EndianessAccessor
    • getSequenceNumberInitValue

      public int getSequenceNumberInitValue()
      Retrieves the sequence number initial value from the sequence number initial value property.
      Specified by:
      getSequenceNumberInitValue in interface SequenceNumberInitValueAccessor
      Returns:
      The sequence number initial value stored by the sequence number initial value property.
    • getAcknowledgeRetryNumber

      public int getAcknowledgeRetryNumber()
      Retrieves the number of retries from the acknowledge retry number. A acknowledge retry number is the overall number of retries to use when counting retries.
      Specified by:
      getAcknowledgeRetryNumber in interface AcknowledgeRetryNumberAccessor
      Returns:
      The number of retries stored by the acknowledge retry number.
    • getAcknowledgeMagicBytes

      public byte[] getAcknowledgeMagicBytes()
      Retrieves the magic bytes from the acknowledge magic bytes property.
      Specified by:
      getAcknowledgeMagicBytes in interface AcknowledgeMagicBytesAccessor
      Returns:
      The magic bytes stored by the acknowledge magic bytes property.
    • getAcknowledgeSegmentPackager

      public SegmentPackager getAcknowledgeSegmentPackager()
      Retrieves the SegmentPackager ACK property.
      Specified by:
      getAcknowledgeSegmentPackager in interface AcknowledgeSegmentPackagerAccessor
      Returns:
      The SegmentPackager stored by the ACK SegmentPackager property.
    • getAcknowledgeTimeoutInMs

      public long getAcknowledgeTimeoutInMs()
      The acknowledge timeout attribute in milliseconds.
      Specified by:
      getAcknowledgeTimeoutInMs in interface AcknowledgeTimeoutInMsAccessor
      Returns:
      An long integer with the timeout in milliseconds.
    • toSequence

      public Sequence toSequence()
      Provides the Sequence representation of this Transmission. In case of nested Transmission instances, all Sequence representations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nested Transmission instances) may be backed by the returned Sequence.
      Specified by:
      toSequence in interface Transmission
      Returns:
      The according instance's Sequence.
    • transmitTo

      public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
      Default implementation harnessing the Transmission.toSequence() method. Transmits the Sequence representing the implementing type's instance to the given OutputStream. Implementations providing error correction methods use the provided feedback InputStream to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.
      Specified by:
      transmitTo in interface Transmission
      Specified by:
      transmitTo in interface Transmission.TransmissionMixin
      Parameters:
      aOutputStream - The OutputStream where to write this instance's Sequence to.
      aReturnStream - An InputStream being the return channel to handle "stop-and-wait ARQ" or the like in case of a bidirectional connection. Can be null in case we have a unidirectional connection.
      Throws:
      IOException - thrown in case writing data to the OutputStream caused problems.
    • toSchema

      public SerialSchema toSchema()
      Retrieves the SerialSchema representing the Transmission. Retrieving a SerialSchema is useful when analyzing and debugging data structures such as a AllocSectionDecoratorSegment instance to help document, learn and verify on the structure (as well as the content) of that very AllocSectionDecoratorSegment.
      Specified by:
      toSchema in interface org.refcodes.mixin.Schemable<DECORATEE extends Transmission>
      Specified by:
      toSchema in interface Transmission
      Returns:
      The SerialSchema representation of the implementing type for debugging and verification (or documentation) purposes.
    • toSimpleTypeMap

      public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()
      Returns the SimpleTypeMap representation of this Transmission. In case this Transmission has Transmission children, then the children are queried as well and contained in the resulting SimpleTypeMap. The aliases of the according Transmission instances represent the resulting path to a Transmission's final simple type.
      Specified by:
      toSimpleTypeMap in interface Transmission
      Returns:
      The SimpleTypeMap representing this Transmission and (if any) its children, with the according aliases forming the paths to the Transmission's values.