Module org.refcodes.serial
Package org.refcodes.serial
Class AbstractMagicBytesTransmissionMultiplexer<CHILD extends Transmission>
- java.lang.Object
-
- org.refcodes.serial.AbstractMagicBytesTransmissionMultiplexer<CHILD>
-
- All Implemented Interfaces:
Serializable,Iterable<CHILD>,org.refcodes.mixin.ChildrenAccessor<CHILD[]>,org.refcodes.mixin.LengthAccessor,Transmission
- Direct Known Subclasses:
MagicBytesSectionMultiplexer,MagicBytesSegmentMultiplexer
public class AbstractMagicBytesTransmissionMultiplexer<CHILD extends Transmission> extends Object implements Transmission, Iterable<CHILD>, org.refcodes.mixin.ChildrenAccessor<CHILD[]>
TheAbstractMagicBytesTransmissionMultiplexerdispatches a transmission to one of the aggregatedTransmissioninstances depending on the magic number provided by the transmission. A transmission is passed to each of the aggregatedTransmissioninstances till oneTransmissionaccepts the transmission, e.g. until aTransmissiondoes not throw aBadMagicBytesException. Attention: ATransmissionthrowing aTransmissionExceptionother than aBadMagicBytesExceptionis considered to be responsible for the transmission so that dispatching is *not* continued with the succeedingTransmission! 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.- See Also:
- Serialized Form
-
-
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.LengthProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
-
Field Summary
Fields Modifier and Type Field Description protected CHILD[]_childrenprotected int_readLimitprotected CHILD_responsibilitystatic intDEFAULT_READ_LIMITThe responsible (if not specified otherwise) maximum limit of bytes that can be read from a givenInputStreambefore theInputStreamcannot be rolled back.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMagicBytesTransmissionMultiplexer()Constructs 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CHILDgetCallee()The lastTransmissionto which the dispatch was transferred, e.g.CHILD[]getChildren()intgetLength()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.Iterator<CHILD>iterator()SchematoSchema()Retrieves theSchemarepresenting theTransmission.SequencetoSequence()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.SimpleTypeMaptoSimpleTypeMap()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.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, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
DEFAULT_READ_LIMIT
public static final int DEFAULT_READ_LIMIT
The responsible (if not specified otherwise) maximum limit of bytes that can be read from a givenInputStreambefore theInputStreamcannot be rolled back.- See Also:
- Constant Field Values
-
_children
protected CHILD extends Transmission[] _children
-
_responsibility
protected CHILD extends Transmission _responsibility
-
_readLimit
protected int _readLimit
-
-
Constructor Detail
-
AbstractMagicBytesTransmissionMultiplexer
protected AbstractMagicBytesTransmissionMultiplexer()
Constructs an emptyAbstractMagicBytesTransmissionMultiplexerfor sub-classes to use having the responsibility to set the children by themselves.
-
AbstractMagicBytesTransmissionMultiplexer
@SafeVarargs public AbstractMagicBytesTransmissionMultiplexer(CHILD... aSegments)
Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements.- Parameters:
aSegments- TheTransmissionelements being contained in this instance.
-
AbstractMagicBytesTransmissionMultiplexer
public AbstractMagicBytesTransmissionMultiplexer(Collection<CHILD> aSegments)
Constructs aAbstractMagicBytesTransmissionMultiplexercontaining the providedTransmissionelements.- Parameters:
aSegments- TheTransmissionelements being contained in this instance.
-
AbstractMagicBytesTransmissionMultiplexer
@SafeVarargs public AbstractMagicBytesTransmissionMultiplexer(int aReadLimit, CHILD... aSegments)
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
public AbstractMagicBytesTransmissionMultiplexer(Collection<CHILD> aSegments, int aReadLimit)
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 Detail
-
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
public Sequence 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
public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
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.
-
toSchema
public Schema toSchema()
Retrieves theSchemarepresenting theTransmission. Retrieving aSchemais useful when analyzing and debugging data structures such as aAllocSectionDecoratorSegmentinstance to help document, learn and verify on the structure (as well as the content) of that veryAllocSectionDecoratorSegment.- Specified by:
toSchemain interfaceTransmission- Returns:
- The
Schemarepresentation of the implementing type for debugging and verification (or documentation) purposes.
-
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
public void transmitTo(OutputStream aOutputStream) throws IOException
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
public void transmitTo(SerialTransceiver aSerialTransceiver) throws IOException
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
public Iterator<CHILD> iterator()
- Specified by:
iteratorin interfaceIterable<CHILD extends Transmission>
-
getChildren
public CHILD[] getChildren()
- Specified by:
getChildrenin interfaceorg.refcodes.mixin.ChildrenAccessor<CHILD extends Transmission>
-
getCallee
public CHILD 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.
-
-