Module org.refcodes.serial
Package org.refcodes.serial
Class AbstractMagicBytesTransmissionMultiplexer<CHILD extends Transmission>
java.lang.Object
org.refcodes.serial.AbstractMagicBytesTransmissionMultiplexer<CHILD>
- Type Parameters:
CHILD- the generic type
- All Implemented Interfaces:
Serializable,Iterable<CHILD>,org.refcodes.mixin.ChildrenAccessor<CHILD[]>,org.refcodes.mixin.LengthAccessor,org.refcodes.mixin.Resetable,org.refcodes.schema.Schemable,Transmission
- Direct Known Subclasses:
MagicBytesSectionMultiplexer,MagicBytesSegmentMultiplexer
public abstract class AbstractMagicBytesTransmissionMultiplexer<CHILD extends Transmission>
extends Object
implements Transmission, Iterable<CHILD>, org.refcodes.mixin.ChildrenAccessor<CHILD[]>
The
AbstractMagicBytesTransmissionMultiplexer dispatches a
transmission to one of the aggregated Transmission instances
depending on the magic number provided by the transmission. A transmission is
passed to each of the aggregated Transmission instances till one
Transmission accepts the transmission, e.g. until a
Transmission does not throw a BadMagicBytesException.
Attention: A Transmission throwing a TransmissionException
other than a BadMagicBytesException is considered to be responsible
for the transmission so that dispatching is *not* continued with the
succeeding Transmission! The last Transmission which was
responsible for a transmission's magic bytes will be the responsible
Transmission till another Transmission claims responsibility
for a transmsision's magic bytes. Initially the first Transmission
passed to this instance is the responsible Transmission.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.mixin.ChildrenAccessor
org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<T extends Object,B extends org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<T, B>>, org.refcodes.mixin.ChildrenAccessor.ChildrenMutator<T extends Object>, org.refcodes.mixin.ChildrenAccessor.ChildrenProperty<T extends Object> 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.LengthPropertyNested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CHILD[]protected intprotected CHILDstatic final intThe responsible (if not specified otherwise) maximum limit of bytes that can be read from a givenInputStreambefore theInputStreamcannot be rolled back. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs an emptyAbstractMagicBytesTransmissionMultiplexerfor sub-classes to use having the responsibility to set the children by themselves.AbstractMagicBytesTransmissionMultiplexer(int aReadLimit, CHILD... aSegments) Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements.AbstractMagicBytesTransmissionMultiplexer(CHILD... aSegments) Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements.AbstractMagicBytesTransmissionMultiplexer(Collection<CHILD> aSegments) Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements.AbstractMagicBytesTransmissionMultiplexer(Collection<CHILD> aSegments, int aReadLimit) Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements. -
Method Summary
Modifier and TypeMethodDescriptionThe lastTransmissionto which the dispatch was transferred, e.g.CHILD[]intReturns the length of the responsibleTransmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes.iterator()voidreset()Resets any dynamic data (e.g. values such as payloads or checksums) and must not(!)toSchema()Returns the responsibleTransmission's transmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes.org.refcodes.struct.SimpleTypeMapReturns the responsibleTransmission'sSimpleTypeMaprepresentation: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes.voidtransmitTo(OutputStream aOutputStream) Transmits to the responsibleTransmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes.voidtransmitTo(OutputStream aOutputStream, InputStream aReturnStream) Transmits to the responsibleTransmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes.voidtransmitTo(SerialTransceiver aSerialTransceiver) Transmits to the responsibleTransmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_READ_LIMIT
public static final int DEFAULT_READ_LIMITThe responsible (if not specified otherwise) maximum limit of bytes that can be read from a givenInputStreambefore theInputStreamcannot be rolled back.- See Also:
-
_children
-
_responsibility
-
_readLimit
protected int _readLimit
-
-
Constructor Details
-
AbstractMagicBytesTransmissionMultiplexer
protected AbstractMagicBytesTransmissionMultiplexer()Constructs an emptyAbstractMagicBytesTransmissionMultiplexerfor sub-classes to use having the responsibility to set the children by themselves. -
AbstractMagicBytesTransmissionMultiplexer
Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements.- Parameters:
aSegments- TheTransmissionelements being contained in this instance.
-
AbstractMagicBytesTransmissionMultiplexer
Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements.- Parameters:
aSegments- TheTransmissionelements being contained in this instance.
-
AbstractMagicBytesTransmissionMultiplexer
Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements.- Parameters:
aReadLimit- the maximum limit of bytes that can be read from a givenInputStreambefore theInputStreamcannot be rolled back.aSegments- TheTransmissionelements being contained in this instance.
-
AbstractMagicBytesTransmissionMultiplexer
Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements.- Parameters:
aSegments- TheTransmissionelements being contained in this instance.aReadLimit- the maximum limit of bytes that can be read from a givenInputStreambefore theInputStreamcannot be rolled back.
-
-
Method Details
-
getLength
public int getLength()Returns the length of the responsibleTransmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes. Initially the firstTransmissionpassed to this instance is the responsibleTransmission. 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).
-
toSequence
Returns the responsibleTransmission's transmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes. Initially the firstTransmissionpassed to this instance is the responsibleTransmission. 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
Transmits to the responsibleTransmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes. Initially the firstTransmissionpassed to this instance is the responsibleTransmission. 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- 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 the responsibleTransmission'sSimpleTypeMaprepresentation: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes. Initially the firstTransmissionpassed to this instance is the responsibleTransmission. 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.
-
transmitTo
Transmits to the responsibleTransmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes. Initially the firstTransmissionpassed to this instance is the responsibleTransmission. Transmits theSequencerepresenting the implementing type's instance to the givenOutputStream. This is a convenience method in case there is no feedbackInputStreamavailable (actually theTransmission.transmitTo(OutputStream, InputStream)method is invoked withnullfor the feedbackInputStream). OverrideTransmission.transmitTo(OutputStream, InputStream)for your custom transmitting functionality.- Specified by:
transmitToin interfaceTransmission- Parameters:
aOutputStream- TheOutputStreamwhere to write this instance'sSequenceto.- Throws:
IOException- thrown in case writing data to theOutputStreamcaused problems.
-
transmitTo
Transmits to the responsibleTransmission: The lastTransmissionwhich was responsible for a transmission's magic bytes will be the responsibleTransmissiontill anotherTransmissionclaims responsibility for a transmsision's magic bytes. Initially the firstTransmissionpassed to this instance is the responsibleTransmission. Transmits theSequencerepresenting the implementing type's instance to the givenSerialTransceiver'sOutputStream. Implementations providing error correction methods use the providedSerialTransceiver's feedbackInputStreamto do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.This is a convenience method (actually theTransmission.transmitTo(OutputStream, InputStream)method is invoked). OverrideTransmission.transmitTo(OutputStream, InputStream)for your custom transmitting functionality.- Specified by:
transmitToin interfaceTransmission- Parameters:
aSerialTransceiver- TheSerialTransceiverproviding theOutputStreamwhere to write this instance'sSequenceto and providing theInputStreambeing the return channel to handle "stop-and-wait ARQ".- Throws:
IOException- thrown in case writing data to theOutputStreamcaused problems.
-
iterator
- Specified by:
iteratorin interfaceIterable<CHILD extends Transmission>
-
getChildren
- Specified by:
getChildrenin interfaceorg.refcodes.mixin.ChildrenAccessor<CHILD extends Transmission>
-
getCallee
The lastTransmissionto which the dispatch was transferred, e.g. which matched the dispatch's magic bytes till anotherTransmissionclaims responsibility for a dispatch's magic bytes..- Returns:
- Returns the
Transmissionto which the dispatch was transferred.
-