Class StopAndWaitPacketStreamSegmentDecorator<DECORATEE extends Segment>

java.lang.Object
org.refcodes.serial.AbstractStopAndWaitPacketStreamTransmissionDecorator<DECORATEE>
org.refcodes.serial.StopAndWaitPacketStreamSegmentDecorator<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, DecoratorSegment<DECORATEE>, Segment, SequenceNumberInitValueAccessor, StopAndWaitPacketStreamTransmission, Transmission, Transmission.TransmissionMixin

public class StopAndWaitPacketStreamSegmentDecorator<DECORATEE extends Segment> extends AbstractStopAndWaitPacketStreamTransmissionDecorator<DECORATEE> implements Segment, DecoratorSegment<DECORATEE>
A StopAndWaitPacketStreamSegmentDecorator chunks any outgoing stream (OutputStream) into blocks of definite length and reassembles any incoming streams (InputStream) from blocks of definite size into a contiguous stream. Each block is enriched by a sequence number as well as a CRC checksum for error detection and error correction means. To do error correction, upon a bad CRC checksum, a feedback stream is used to request the same block (as of the sequence number) again. A "window" of blocks not been acknowledged may be buffered for out of order recovery as well as other recovery strategies.
See Also:
  • Constructor Details

    • StopAndWaitPacketStreamSegmentDecorator

      public StopAndWaitPacketStreamSegmentDecorator(DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
    • StopAndWaitPacketStreamSegmentDecorator

      public StopAndWaitPacketStreamSegmentDecorator(DECORATEE aDecoratee, int aBlockSize, int aPacketLengthWidth, byte[] aPacketMagicBytes, int aSequenceNumberInitValue, int aSequenceNumberWidth, org.refcodes.mixin.ConcatenateMode aSequenceNumberConcatenateMode, SegmentPackager aPacketSegmentPackager, byte[] aAcknowledgeMagicBytes, int aAckRetryNumber, long aAckTimeoutInMs, SegmentPackager aAckSegmentPackager, org.refcodes.numerical.Endianess aEndianess)
  • Method Details

    • fromTransmission

      public int fromTransmission(Sequence aSequence, int aOffset) throws TransmissionException
      (Re-)initializes this instance with the the given Sequence data. This method merely delegates to the decoratee and does not do any packaging as we do not have a stream which we can packetize, we have a Sequence provided.
      Specified by:
      fromTransmission in interface Segment
      Parameters:
      aSequence - The Sequence data from which to (re-)initialize this instance.
      aOffset - The offset where to start processing the provided Sequence.
      Returns:
      The index after the last offset into the given Sequence processed by this method.
      Throws:
      TransmissionException - thrown in case a given Sequence cannot be processed.
    • receiveFrom

      public void receiveFrom(InputStream aInputStream, OutputStream aReturnStream) throws IOException, TransmissionException
      (Re-)initializes this instance by receiving the according Sequence from the given InputStream. Implementations providing error correction methods use the provided feedback OutputStream to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.
      Specified by:
      receiveFrom in interface Segment
      Parameters:
      aInputStream - The InputStream from which to read the instance's (re-)initialization Sequence from.
      aReturnStream - An OutputStream 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 reading data from the InputStream caused problems.
      TransmissionException - thrown in case a given transmission cannot be processed.
    • builder

      public static <DECORATEE extends Segment> StopAndWaitPacketStreamSegmentDecorator.Builder<DECORATEE> builder()
      Creates builder to build StopAndWaitPacketStreamSegmentDecorator.
      Type Parameters:
      DECORATEE - The decoratee type describing the according subclass to be enriched.
      Returns:
      The created builder.