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.mixin.Schemable
,org.refcodes.numerical.EndianessAccessor
,AcknowledgeMagicBytesAccessor
,AcknowledgeRetryNumberAccessor
,AcknowledgeSegmentPackagerAccessor
,AcknowledgeTimeoutMillisAccessor
,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:
-
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.AcknowledgeTimeoutMillisAccessor
AcknowledgeTimeoutMillisAccessor.AcknowledgeTimeoutMillisBuilder<B extends AcknowledgeTimeoutMillisAccessor.AcknowledgeTimeoutMillisBuilder<B>>, AcknowledgeTimeoutMillisAccessor.AcknowledgeTimeoutMillisMutator, AcknowledgeTimeoutMillisAccessor.AcknowledgeTimeoutMillisProperty
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
Modifier and TypeFieldDescriptionprotected byte[]
protected int
protected SegmentPackager
protected long
protected int
protected long
protected DECORATEE
protected org.refcodes.numerical.Endianess
protected byte[]
protected int
protected byte[]
protected SegmentPackager
protected int
protected org.refcodes.mixin.ConcatenateMode
protected int
protected int
static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Constructor Summary
ConstructorDescriptionAbstractStopAndWaitPacketStreamTransmissionDecorator
(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
Modifier and TypeMethodDescriptionbyte[]
Retrieves the magic bytes from the acknowledge magic bytes property.int
Retrieves the number of retries from the acknowledge retry number.Retrieves theSegmentPackager
ACK property.long
The acknowledge timeout attribute in milliseconds.int
org.refcodes.mixin.ConcatenateMode
Returns theConcatenateMode
describing the positions of the sequence number, the block data and the CRC checksum within the packet.org.refcodes.numerical.Endianess
int
Determines the overall length of thisTransmission
.int
ATTENTION: The packet size is not available until transmission has been put into effect!int
Retrieves the sequence number initial value from the sequence number initial value property.int
Retrieves the width (in bytes) dedicated for the sequence number.toSchema()
Provides theSequence
representation of thisTransmission
.org.refcodes.struct.SimpleTypeMap
Returns theSimpleTypeMap
representation of thisTransmission
.void
transmitTo
(OutputStream aOutputStream, InputStream aReturnStream) Default implementation harnessing theTransmission.toSequence()
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 Details
-
ENDIANESS
- See Also:
-
SEQUENCE_NUMBER_WIDTH
- See Also:
-
SEQUENCE_NUMBER_INIT_VALUE
- See Also:
-
BLOCK_SIZE
- See Also:
-
ACK_MAGIC_BYTES
- See Also:
-
ACK_TIMEOUT_IN_MS
- See Also:
-
ACK_RETRY_NUMBER
- See Also:
-
_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
-
_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 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(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
- TheEndianess
to use for integer (double) numbers and the like.
-
-
Method Details
-
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
- 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
Retrieves theSegmentPackager
ACK property.- Specified by:
getAcknowledgeSegmentPackager
in interfaceAcknowledgeSegmentPackagerAccessor
- Returns:
- The
SegmentPackager
stored by the ACKSegmentPackager
property.
-
getAcknowledgeTimeoutMillis
public long getAcknowledgeTimeoutMillis()The acknowledge timeout attribute in milliseconds.- Specified by:
getAcknowledgeTimeoutMillis
in interfaceAcknowledgeTimeoutMillisAccessor
- Returns:
- An long integer with the timeout in milliseconds.
-
toSequence
Provides theSequence
representation of thisTransmission
. In case of nestedTransmission
instances, allSequence
representations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nestedTransmission
instances) may be backed by the returnedSequence
.- Specified by:
toSequence
in interfaceTransmission
- Returns:
- The according instance's
Sequence
.
-
transmitTo
Default implementation harnessing theTransmission.toSequence()
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
- Specified by:
toSchema
in interfaceorg.refcodes.mixin.Schemable
- Specified by:
toSchema
in interfaceTransmission
-
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.
-