java.lang.Object
java.io.OutputStream
org.refcodes.serial.PacketOutputStream
org.refcodes.serial.StopAndWaitPacketOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,org.refcodes.mixin.BlockSizeAccessor
,org.refcodes.mixin.PacketSizeAccessor
,org.refcodes.numerical.EndianessAccessor
,AcknowledgeMagicBytesAccessor
,AcknowledgeRetryNumberAccessor
,AcknowledgeSegmentPackagerAccessor
,AcknowledgeTimeoutMillisAccessor
,PacketLengthWidthAccessor
,PacketMagicBytesAccessor
,PacketSegmentPackagerAccessor
,SequenceNumberAccessor
,SequenceNumberConcatenateModeAccessor
,SequenceNumberInitValueAccessor
,SequenceNumberWidthAccessor
public class StopAndWaitPacketOutputStream
extends PacketOutputStream
implements AcknowledgeRetryNumberAccessor, AcknowledgeTimeoutMillisAccessor, AcknowledgeMagicBytesAccessor, AcknowledgeSegmentPackagerAccessor
The
StopAndWaitPacketOutputStream
wraps an OutputStream
and
chunks any data to be written into packets with a sequence number, a block of
data and a CRC checksum. An according StopAndWaitPacketInputStream
then reverts the packetised data stream while performing CRC checksum
validation as well as sequence number validation.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Builder to buildStopAndWaitPacketInputStream
instances.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.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.serial.PacketLengthWidthAccessor
PacketLengthWidthAccessor.PacketLengthWidthBuilder<B extends PacketLengthWidthAccessor.PacketLengthWidthBuilder<B>>, PacketLengthWidthAccessor.PacketLengthWidthMutator, PacketLengthWidthAccessor.PacketLengthWidthProperty
Nested classes/interfaces inherited from interface org.refcodes.serial.PacketMagicBytesAccessor
PacketMagicBytesAccessor.PacketMagicBytesBuilder<B extends PacketMagicBytesAccessor.PacketMagicBytesBuilder<B>>, PacketMagicBytesAccessor.PacketMagicBytesMutator, PacketMagicBytesAccessor.PacketMagicBytesProperty
Nested classes/interfaces inherited from interface org.refcodes.serial.PacketSegmentPackagerAccessor
PacketSegmentPackagerAccessor.PacketSegmentPackagerBuilder<B extends PacketSegmentPackagerAccessor.PacketSegmentPackagerBuilder<B>>, PacketSegmentPackagerAccessor.PacketSegmentPackagerMutator, PacketSegmentPackagerAccessor.PacketSegmentPackagerProperty
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.SequenceNumberAccessor
SequenceNumberAccessor.SequenceNumberBuilder<B extends SequenceNumberAccessor.SequenceNumberBuilder<B>>, SequenceNumberAccessor.SequenceNumberMutator, SequenceNumberAccessor.SequenceNumberProperty
Nested classes/interfaces inherited from interface org.refcodes.serial.SequenceNumberConcatenateModeAccessor
SequenceNumberConcatenateModeAccessor.SequenceNumberConcatenateModeBuilder<B extends SequenceNumberConcatenateModeAccessor.SequenceNumberConcatenateModeBuilder<B>>, SequenceNumberConcatenateModeAccessor.SequenceNumberConcatenateModeMutator, SequenceNumberConcatenateModeAccessor.SequenceNumberConcatenateModeProperty
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.SequenceNumberWidthAccessor
SequenceNumberWidthAccessor.SequenceNumberWidthBuilder<B extends SequenceNumberWidthAccessor.SequenceNumberWidthBuilder<B>>, SequenceNumberWidthAccessor.SequenceNumberWidthMutator, SequenceNumberWidthAccessor.SequenceNumberWidthProperty
-
Field Summary
Fields inherited from class org.refcodes.serial.PacketOutputStream
_allocSegment, _blockOffset, _blockSequence, _boundedSequence, _endianess, _outputStream, _packetSegment, _sequenceNumber, _sequenceNumberSegment, _sequenceNumberWidth
-
Constructor Summary
ConstructorDescriptionStopAndWaitPacketOutputStream
(OutputStream aOutputStream, int aBlockSize, int aPacketLengthWidth, byte[] aPacketMagicBytes, int aSequenceNumberInitValue, int aSequenceNumberWidth, org.refcodes.mixin.ConcatenateMode aSequenceNumberConcatenateMode, SegmentPackager aPacketSegmentPackager, InputStream aReturnStream, byte[] aAcknowledgeMagicBytes, int aAckRetryNumber, long aAckTimeoutInMs, SegmentPackager aAckSegmentPackager, org.refcodes.numerical.Endianess aEndianess) Constructs an accordingStopAndWaitPacketOutputStream
instance wrapping the givenOutputStream
.StopAndWaitPacketOutputStream
(OutputStream aOutputStream, InputStream aReturnStream, TransmissionMetrics aTransmissionMetrics) Constructs an accordingStopAndWaitPacketOutputStream
instance wrapping the givenOutputStream
. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Creates builder to buildStopAndWaitPacketOutputStream
.protected void
Do transmit packet.byte[]
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.Methods inherited from class org.refcodes.serial.PacketOutputStream
close, flush, getBlockSize, getEndianess, getPacketLengthWidth, getPacketMagicBytes, getPacketSegmentPackager, getPacketSize, getSequenceNumber, getSequenceNumberConcatenateMode, getSequenceNumberInitValue, getSequenceNumberWidth, write
Methods inherited from class java.io.OutputStream
nullOutputStream, write, write
-
Constructor Details
-
StopAndWaitPacketOutputStream
public StopAndWaitPacketOutputStream(OutputStream aOutputStream, InputStream aReturnStream, TransmissionMetrics aTransmissionMetrics) Constructs an accordingStopAndWaitPacketOutputStream
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:
aOutputStream
- TheOutputStream
to be wrapped.aReturnStream
- TheInputStream
for establishing a return channel (handshake with the communication partner).aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
StopAndWaitPacketOutputStream
public StopAndWaitPacketOutputStream(OutputStream aOutputStream, int aBlockSize, int aPacketLengthWidth, byte[] aPacketMagicBytes, int aSequenceNumberInitValue, int aSequenceNumberWidth, org.refcodes.mixin.ConcatenateMode aSequenceNumberConcatenateMode, SegmentPackager aPacketSegmentPackager, InputStream aReturnStream, byte[] aAcknowledgeMagicBytes, int aAckRetryNumber, long aAckTimeoutInMs, SegmentPackager aAckSegmentPackager, org.refcodes.numerical.Endianess aEndianess) Constructs an accordingStopAndWaitPacketOutputStream
instance wrapping the givenOutputStream
.- Parameters:
aOutputStream
- TheOutputStream
to be wrapped.aBlockSize
- The block size of a data block for each packet.aPacketLengthWidth
- The width (bytes) for the number of bytes to be truncated from the last block.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.aReturnStream
- TheInputStream
for establishing a return channel (handshake with the communication partner).aAcknowledgeMagicBytes
- The ACK character(s) to be used by the return channel to transmit an ACK (acknowledge) response after successful receiving a transmission.aAckRetryNumber
- The number of retries waiting for an ACK from the return channel.aAckTimeoutInMs
- 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
-
builder
Creates builder to buildStopAndWaitPacketOutputStream
.- Returns:
- created builder
-
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.
-
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.
-
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.
-
doTransmitPacket
Description copied from class:PacketOutputStream
Do transmit packet.- Overrides:
doTransmitPacket
in classPacketOutputStream
- Throws:
IOException
- Signals that an I/O exception has occurred.TransmissionSequenceException
- the transmission sequence exception
-