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.Resetable,org.refcodes.numerical.EndianessAccessor,org.refcodes.schema.Schemable,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.AcknowledgeMagicBytesPropertyNested classes/interfaces inherited from interface org.refcodes.serial.AcknowledgeRetryNumberAccessor
AcknowledgeRetryNumberAccessor.AcknowledgeRetryNumberBuilder<B extends AcknowledgeRetryNumberAccessor.AcknowledgeRetryNumberBuilder<B>>, AcknowledgeRetryNumberAccessor.AcknowledgeRetryNumberMutator, AcknowledgeRetryNumberAccessor.AcknowledgeRetryNumberPropertyNested classes/interfaces inherited from interface org.refcodes.serial.AcknowledgeSegmentPackagerAccessor
AcknowledgeSegmentPackagerAccessor.AcknowledgeSegmentPackagerBuilder<B extends AcknowledgeSegmentPackagerAccessor.AcknowledgeSegmentPackagerBuilder<B>>, AcknowledgeSegmentPackagerAccessor.AcknowledgeSegmentPackagerMutator, AcknowledgeSegmentPackagerAccessor.AcknowledgeSegmentPackagerPropertyNested classes/interfaces inherited from interface org.refcodes.serial.AcknowledgeTimeoutMillisAccessor
AcknowledgeTimeoutMillisAccessor.AcknowledgeTimeoutMillisBuilder<B extends AcknowledgeTimeoutMillisAccessor.AcknowledgeTimeoutMillisBuilder<B>>, AcknowledgeTimeoutMillisAccessor.AcknowledgeTimeoutMillisMutator, AcknowledgeTimeoutMillisAccessor.AcknowledgeTimeoutMillisPropertyNested 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.BlockSizePropertyNested 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.EndianessPropertyNested 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.LengthPropertyNested 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.PacketSizePropertyNested classes/interfaces inherited from interface org.refcodes.serial.SequenceNumberInitValueAccessor
SequenceNumberInitValueAccessor.SequenceNumberInitValueBuilder<B extends SequenceNumberInitValueAccessor.SequenceNumberInitValueBuilder<B>>, SequenceNumberInitValueAccessor.SequenceNumberInitValueMutator, SequenceNumberInitValueAccessor.SequenceNumberInitValuePropertyNested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]protected intprotected SegmentPackagerprotected longprotected intprotected longprotected DECORATEEprotected org.refcodes.numerical.Endianessprotected byte[]protected intprotected byte[]protected SegmentPackagerprotected intprotected org.refcodes.mixin.ConcatenateModeprotected intprotected intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionAbstractStopAndWaitPacketStreamTransmissionDecorator(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.intRetrieves the number of retries from the acknowledge retry number.Retrieves theSegmentPackagerACK property.longThe acknowledge timeout attribute in milliseconds.intorg.refcodes.mixin.ConcatenateModeReturns theConcatenateModedescribing the positions of the sequence number, the block data and the CRC checksum within the packet.org.refcodes.numerical.EndianessintDetermines the overall length of thisTransmission.intATTENTION: The packet size is not available until transmission has been put into effect!intRetrieves the sequence number initial value from the sequence number initial value property.intRetrieves the width (in bytes) dedicated for the sequence number.voidreset()Resets any dynamic data (e.g. values such as payloads or checksums) and must not(!)toSchema()Provides theSequencerepresentation of thisTransmission.org.refcodes.struct.SimpleTypeMapReturns theSimpleTypeMaprepresentation of thisTransmission.voidtransmitTo(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, waitMethods 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 theTransmissionMetricsconfiguration 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- TheTransmissionMetricsto 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 aSequencefrom thisTransmissionand the decoratedTransmission.aPacketSegmentPackager- An (optional)SegmentPackagerused 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)SegmentPackagerused to modify a ACK response data e.g. with a CRC checksum.aEndianess- TheEndianessto use for integer (double) numbers and the like.
-
-
Method Details
-
getCrcChecksumConcatenateMode
public org.refcodes.mixin.ConcatenateMode getCrcChecksumConcatenateMode()Returns theConcatenateModedescribing 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:
getBlockSizein interfaceorg.refcodes.mixin.BlockSizeAccessor
-
getPacketSize
public int getPacketSize()ATTENTION: The packet size is not available until transmission has been put into effect!- Specified by:
getPacketSizein interfaceorg.refcodes.mixin.PacketSizeAccessor
-
getLength
public int getLength()Determines the overall length of thisTransmission. In case of nestedTransmissioninstances, all length values from all sub-segments are accumulated to the result as well.- Specified by:
getLengthin interfaceorg.refcodes.mixin.LengthAccessor- Specified by:
getLengthin interfaceTransmission- Returns:
- The (overall) length of the
Transmission(including any sub-segments).
-
getDecoratee
- Specified by:
getDecorateein interfaceorg.refcodes.mixin.DecorateeAccessor<DECORATEE extends Transmission>
-
getEndianess
public org.refcodes.numerical.Endianess getEndianess()- Specified by:
getEndianessin interfaceorg.refcodes.numerical.EndianessAccessor
-
getSequenceNumberInitValue
public int getSequenceNumberInitValue()Retrieves the sequence number initial value from the sequence number initial value property.- Specified by:
getSequenceNumberInitValuein 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:
getAcknowledgeRetryNumberin 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:
getAcknowledgeMagicBytesin interfaceAcknowledgeMagicBytesAccessor- Returns:
- The magic bytes stored by the acknowledge magic bytes property.
-
getAcknowledgeSegmentPackager
Retrieves theSegmentPackagerACK property.- Specified by:
getAcknowledgeSegmentPackagerin interfaceAcknowledgeSegmentPackagerAccessor- Returns:
- The
SegmentPackagerstored by the ACKSegmentPackagerproperty.
-
getAcknowledgeTimeoutMillis
public long getAcknowledgeTimeoutMillis()The acknowledge timeout attribute in milliseconds.- Specified by:
getAcknowledgeTimeoutMillisin interfaceAcknowledgeTimeoutMillisAccessor- Returns:
- An long integer with the timeout in milliseconds.
-
toSequence
Provides theSequencerepresentation of thisTransmission. In case of nestedTransmissioninstances, allSequencerepresentations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nestedTransmissioninstances) may be backed by the returnedSequence.- Specified by:
toSequencein interfaceTransmission- Returns:
- The according instance's
Sequence.
-
transmitTo
Default implementation harnessing theTransmission.toSequence()method. Transmits theSequencerepresenting the implementing type's instance to the givenOutputStream. Implementations providing error correction methods use the provided feedbackInputStreamto do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.- Specified by:
transmitToin interfaceTransmission- Specified by:
transmitToin interfaceTransmission.TransmissionMixin- Parameters:
aOutputStream- TheOutputStreamwhere to write this instance'sSequenceto.aReturnStream- AnInputStreambeing 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 theOutputStreamcaused problems.
-
reset
public void reset()Resets any dynamic data (e.g. values such as payloads or checksums) and must not(!) reset any configurations or settings required to produce the dynamic data (e.g. theTransmissionMetrics).- Specified by:
resetin interfaceorg.refcodes.mixin.Resetable- Specified by:
resetin interfaceTransmission
-
toSchema
- Specified by:
toSchemain interfaceorg.refcodes.schema.Schemable- Specified by:
toSchemain interfaceTransmission
-
toSimpleTypeMap
public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()Returns theSimpleTypeMaprepresentation of thisTransmission. In case this Transmission hasTransmissionchildren, then the children are queried as well and contained in the resultingSimpleTypeMap. The aliases of the accordingTransmissioninstances represent the resulting path to aTransmission's final simple type.- Specified by:
toSimpleTypeMapin interfaceTransmission- Returns:
- The
SimpleTypeMaprepresenting thisTransmissionand (if any) its children, with the according aliases forming the paths to theTransmission's values.
-