Module org.refcodes.serial
Package org.refcodes.serial
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.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
AAbstractStopAndWaitPacketStreamTransmissionDecorator
wraps aTransmission
instance and enriches theTransmission
with packet-stream functionality. A packet consists of a sequence number, a block of data and a CRC checksum in the order of theConcatenateMode
being used.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.serial.AcknowledgeMagicBytesAccessor
AcknowledgeMagicBytesAccessor.AcknowledgeMagicBytesBuilder<B extends AcknowledgeMagicBytesAccessor.AcknowledgeMagicBytesBuilder<B>>, AcknowledgeMagicBytesAccessor.AcknowledgeMagicBytesMutator, AcknowledgeMagicBytesAccessor.AcknowledgeMagicBytesProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.AcknowledgeRetryNumberAccessor
AcknowledgeRetryNumberAccessor.AcknowledgeRetryNumberBuilder<B extends AcknowledgeRetryNumberAccessor.AcknowledgeRetryNumberBuilder<B>>, AcknowledgeRetryNumberAccessor.AcknowledgeRetryNumberMutator, AcknowledgeRetryNumberAccessor.AcknowledgeRetryNumberProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.AcknowledgeSegmentPackagerAccessor
AcknowledgeSegmentPackagerAccessor.AcknowledgeSegmentPackagerBuilder<B extends AcknowledgeSegmentPackagerAccessor.AcknowledgeSegmentPackagerBuilder<B>>, AcknowledgeSegmentPackagerAccessor.AcknowledgeSegmentPackagerMutator, AcknowledgeSegmentPackagerAccessor.AcknowledgeSegmentPackagerProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.AcknowledgeTimeoutInMsAccessor
AcknowledgeTimeoutInMsAccessor.AcknowledgeTimeoutInMsBuilder<B extends AcknowledgeTimeoutInMsAccessor.AcknowledgeTimeoutInMsBuilder<B>>, AcknowledgeTimeoutInMsAccessor.AcknowledgeTimeoutInMsMutator, AcknowledgeTimeoutInMsAccessor.AcknowledgeTimeoutInMsProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.BlockSizeAccessor
org.refcodes.mixin.BlockSizeAccessor.BlockSizeBuilder<B extends org.refcodes.mixin.BlockSizeAccessor.BlockSizeBuilder<B>>, org.refcodes.mixin.BlockSizeAccessor.BlockSizeMutator, org.refcodes.mixin.BlockSizeAccessor.BlockSizeProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.DecorateeAccessor
org.refcodes.mixin.DecorateeAccessor.DecorateeBuilder<DECORATEE extends Object,B extends org.refcodes.mixin.DecorateeAccessor.DecorateeBuilder<DECORATEE,B>>, org.refcodes.mixin.DecorateeAccessor.DecorateeMutator<DECORATEE extends Object>, org.refcodes.mixin.DecorateeAccessor.DecorateeProperty<DECORATEE extends Object>
-
Nested classes/interfaces inherited from interface org.refcodes.numerical.EndianessAccessor
org.refcodes.numerical.EndianessAccessor.EndianessBuilder<B extends org.refcodes.numerical.EndianessAccessor.EndianessBuilder<B>>, org.refcodes.numerical.EndianessAccessor.EndianessMutator, org.refcodes.numerical.EndianessAccessor.EndianessProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.LengthAccessor
org.refcodes.mixin.LengthAccessor.LengthBuilder<B extends org.refcodes.mixin.LengthAccessor.LengthBuilder<B>>, org.refcodes.mixin.LengthAccessor.LengthMutator, org.refcodes.mixin.LengthAccessor.LengthProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.PacketSizeAccessor
org.refcodes.mixin.PacketSizeAccessor.PacketSizeBuilder<B extends org.refcodes.mixin.PacketSizeAccessor.PacketSizeBuilder<B>>, org.refcodes.mixin.PacketSizeAccessor.PacketSizeMutator, org.refcodes.mixin.PacketSizeAccessor.PacketSizeProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.SequenceNumberInitValueAccessor
SequenceNumberInitValueAccessor.SequenceNumberInitValueBuilder<B extends SequenceNumberInitValueAccessor.SequenceNumberInitValueBuilder<B>>, SequenceNumberInitValueAccessor.SequenceNumberInitValueMutator, SequenceNumberInitValueAccessor.SequenceNumberInitValueProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
_acknowledgeMagicBytes
protected int
_acknowledgeRetryNumber
protected SegmentPackager
_acknowledgeSegmentPackager
protected long
_acknowledgeTimeoutInMs
protected int
_blockSize
protected long
_crcChecksum
protected DECORATEE
_decoratee
protected org.refcodes.numerical.Endianess
_endianess
protected byte[]
_lastPacketMagicBytes
protected int
_packetLengthWidth
protected byte[]
_packetMagicBytes
protected SegmentPackager
_packetSegmentPackager
protected int
_packetSize
protected org.refcodes.mixin.ConcatenateMode
_sequenceNumberConcatenateMode
protected int
_sequenceNumberInitValue
protected int
_sequenceNumberWidth
static String
ACK_MAGIC_BYTES
static String
ACK_RETRY_NUMBER
static String
ACK_TIMEOUT_IN_MS
static String
BLOCK_SIZE
static String
ENDIANESS
static String
SEQUENCE_NUMBER_INIT_VALUE
static String
SEQUENCE_NUMBER_WIDTH
-
Constructor Summary
Constructors Constructor Description 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 givenOutputStream
.AbstractStopAndWaitPacketStreamTransmissionDecorator(DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
Constructs an according packet-stream decorator instance wrapping the givenOutputStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
getAcknowledgeMagicBytes()
Retrieves the magic bytes from the acknowledge magic bytes property.int
getAcknowledgeRetryNumber()
Retrieves the number of retries from the acknowledge retry number.SegmentPackager
getAcknowledgeSegmentPackager()
Retrieves theSegmentPackager
ACK property.long
getAcknowledgeTimeoutInMs()
The acknowledge timeout attribute in milliseconds.int
getBlockSize()
org.refcodes.mixin.ConcatenateMode
getCrcChecksumConcatenateMode()
Returns theConcatenateMode
describing the positions of the sequence number, the block data and the CRC checksum within the packet.DECORATEE
getDecoratee()
org.refcodes.numerical.Endianess
getEndianess()
int
getLength()
Determines the overall length of thisTransmission
.int
getPacketSize()
ATTENTION: The packet size is not available until transmission has been put into effect!int
getSequenceNumberInitValue()
Retrieves the sequence number initial value from the sequence number initial value property.int
getSequenceNumberWidth()
Retrieves the width (in bytes) dedicated for the sequence number.Schema
toSchema()
Retrieves theSchema
representing theTransmission
.org.refcodes.struct.SimpleTypeMap
toSimpleTypeMap()
Returns theSimpleTypeMap
representation of thisTransmission
.Sequence
toTransmission()
Provides theSequence
representation of thisTransmission
.void
transmitTo(OutputStream aOutputStream, InputStream aReturnStream)
Default implementation harnessing theTransmission.toTransmission()
method.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.serial.Transmission
transmitTo, transmitTo
-
-
-
-
Field Detail
-
ENDIANESS
public static final String ENDIANESS
- See Also:
- Constant Field Values
-
SEQUENCE_NUMBER_WIDTH
public static final String SEQUENCE_NUMBER_WIDTH
- See Also:
- Constant Field Values
-
SEQUENCE_NUMBER_INIT_VALUE
public static final String SEQUENCE_NUMBER_INIT_VALUE
- See Also:
- Constant Field Values
-
BLOCK_SIZE
public static final String BLOCK_SIZE
- See Also:
- Constant Field Values
-
ACK_MAGIC_BYTES
public static final String ACK_MAGIC_BYTES
- See Also:
- Constant Field Values
-
ACK_TIMEOUT_IN_MS
public static final String ACK_TIMEOUT_IN_MS
- See Also:
- Constant Field Values
-
ACK_RETRY_NUMBER
public static final String ACK_RETRY_NUMBER
- See Also:
- Constant Field Values
-
_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 Detail
-
AbstractStopAndWaitPacketStreamTransmissionDecorator
public AbstractStopAndWaitPacketStreamTransmissionDecorator(DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
Constructs an according packet-stream decorator instance wrapping the givenOutputStream
. The configuration attributes are taken from theTransmissionMetrics
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
- TheTransmissionMetrics
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 givenOutputStream
.- 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 aSequence
from thisTransmission
and the decoratedTransmission
.aPacketSegmentPackager
- An (optional)SegmentPackager
used to modify a packet's data e.g. with a CRC checksum.aAcknowledgeMagicBytes
- The ACK character 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
- TheEndianess
to use for integer (double) numbers and the like.
-
-
Method Detail
-
getCrcChecksumConcatenateMode
public org.refcodes.mixin.ConcatenateMode getCrcChecksumConcatenateMode()
Returns theConcatenateMode
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 interfaceorg.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 interfaceorg.refcodes.mixin.PacketSizeAccessor
-
getLength
public int getLength()
Determines the overall length of thisTransmission
. In case of nestedTransmission
instances, all length values from all sub-segments are accumulated to the result as well.- Specified by:
getLength
in interfaceorg.refcodes.mixin.LengthAccessor
- Specified by:
getLength
in interfaceTransmission
- Returns:
- The (overall) length of the
Transmission
(including any sub-segments).
-
getDecoratee
public DECORATEE getDecoratee()
- Specified by:
getDecoratee
in interfaceorg.refcodes.mixin.DecorateeAccessor<DECORATEE extends Transmission>
-
getEndianess
public org.refcodes.numerical.Endianess getEndianess()
- Specified by:
getEndianess
in interfaceorg.refcodes.numerical.EndianessAccessor
-
getSequenceNumberInitValue
public int getSequenceNumberInitValue()
Retrieves the sequence number initial value from the sequence number initial value property.- Specified by:
getSequenceNumberInitValue
in interfaceSequenceNumberInitValueAccessor
- 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 interfaceAcknowledgeRetryNumberAccessor
- 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 interfaceAcknowledgeMagicBytesAccessor
- Returns:
- The magic bytes stored by the acknowledge magic bytes property.
-
getAcknowledgeSegmentPackager
public SegmentPackager getAcknowledgeSegmentPackager()
Retrieves theSegmentPackager
ACK property.- Specified by:
getAcknowledgeSegmentPackager
in interfaceAcknowledgeSegmentPackagerAccessor
- Returns:
- The
SegmentPackager
stored by the ACKSegmentPackager
property.
-
getAcknowledgeTimeoutInMs
public long getAcknowledgeTimeoutInMs()
The acknowledge timeout attribute in milliseconds.- Specified by:
getAcknowledgeTimeoutInMs
in interfaceAcknowledgeTimeoutInMsAccessor
- Returns:
- An integer with the timeout in milliseconds.
-
toTransmission
public Sequence toTransmission()
Provides theSequence
representation of thisTransmission
. In case of nestedTransmission
instances, allSequence
representations from all sub-segments are accumulated to the result as well.- Specified by:
toTransmission
in interfaceTransmission
- Returns:
- The according instance's
Sequence
.
-
transmitTo
public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
Default implementation harnessing theTransmission.toTransmission()
method. Transmits theSequence
representing the implementing type's instance to the givenOutputStream
. Implementations providing error correction methods use the provided feedbackInputStream
to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.- Specified by:
transmitTo
in interfaceTransmission
- Specified by:
transmitTo
in interfaceTransmission.TransmissionMixin
- Parameters:
aOutputStream
- TheOutputStream
where to write this instance'sSequence
to.aReturnStream
- AnInputStream
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 theOutputStream
caused problems.
-
toSchema
public Schema toSchema()
Retrieves theSchema
representing theTransmission
. Retrieving aSchema
is useful when analyzing and debugging data structures such as aAllocSectionDecoratorSegment
instance to help document, learn and verify on the structure (as well as the content) of that veryAllocSectionDecoratorSegment
.- Specified by:
toSchema
in interfaceTransmission
- Returns:
- The
Schema
representation of the implementing type for debugging and verification (or documentation) purposes.
-
toSimpleTypeMap
public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()
Returns theSimpleTypeMap
representation of thisTransmission
. In case this Transmission hasTransmission
children, then the children are queried as well and contained in the resultingSimpleTypeMap
. The aliases of the accordingTransmission
instances represent the resulting path to aTransmission
's final simple type.- Specified by:
toSimpleTypeMap
in interfaceTransmission
- Returns:
- The
SimpleTypeMap
representing thisTransmission
and (if any) its children, with the according aliases forming the paths to theTransmission
's values.
-
-