Module org.refcodes.serial
Package org.refcodes.serial
Class AbstractMagicBytesTransmissionDispatcher<CHILD extends Transmission>
- java.lang.Object
-
- org.refcodes.serial.AbstractMagicBytesTransmissionDispatcher<CHILD>
-
- All Implemented Interfaces:
Serializable
,Iterable<CHILD>
,org.refcodes.mixin.ChildrenAccessor<CHILD[]>
,org.refcodes.mixin.LengthAccessor
,Transmission
- Direct Known Subclasses:
MagicBytesSectionDispatcher
,MagicBytesSegmentDispatcher
public class AbstractMagicBytesTransmissionDispatcher<CHILD extends Transmission> extends Object implements Transmission, Iterable<CHILD>, org.refcodes.mixin.ChildrenAccessor<CHILD[]>
TheAbstractMagicBytesTransmissionDispatcher
dispatches a transmission to one of the aggregatedTransmission
instances depending on the magic number provided by the transmission. A transmission is passed to each of the aggregatedTransmission
instances till oneTransmission
accepts the transmission, e.g. until aTransmission
does not throw aBadMagicBytesException
. Attention: ATransmission
throwing aTransmissionException
other than aBadMagicBytesException
is considered to be responsible for the transmission so that dispatching is *not* continued with the succeedingTransmission
! The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes. Initially the firstTransmission
passed 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[]
_children
protected int
_readLimit
protected CHILD
_responsibility
static int
DEFAULT_READ_LIMIT
The responsible (if not specified otherwise) maximum limit of bytes that can be read from a givenInputStream
before theInputStream
cannot be rolled back.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractMagicBytesTransmissionDispatcher()
Constructs an emptyAbstractMagicBytesTransmissionDispatcher
for sub-classes to use having the responsibility to set the children by themselves.AbstractMagicBytesTransmissionDispatcher(int aReadLimit, CHILD... aSegments)
Constructs aAbstractMagicBytesTransmissionDispatcher
containing the providedTransmission
elements.AbstractMagicBytesTransmissionDispatcher(CHILD... aSegments)
Constructs aAbstractMagicBytesTransmissionDispatcher
containing the providedTransmission
elements.AbstractMagicBytesTransmissionDispatcher(Collection<CHILD> aSegments)
Constructs aAbstractMagicBytesTransmissionDispatcher
containing the providedTransmission
elements.AbstractMagicBytesTransmissionDispatcher(Collection<CHILD> aSegments, int aReadLimit)
Constructs aAbstractMagicBytesTransmissionDispatcher
containing the providedTransmission
elements.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CHILD[]
getChildren()
int
getLength()
Returns the length of the responsibleTransmission
: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes.CHILD
getResponsibility()
The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes.Iterator<CHILD>
iterator()
Schema
toSchema()
Retrieves theSchema
representing theTransmission
.org.refcodes.struct.SimpleTypeMap
toSimpleTypeMap()
Returns the responsibleTransmission
'sSimpleTypeMap
representation: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes.Sequence
toTransmission()
Returns the responsibleTransmission
's transmission: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes.void
transmitTo(OutputStream aOutputStream)
Transmits to the responsibleTransmission
: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes.void
transmitTo(OutputStream aOutputStream, InputStream aReturnStream)
Transmits to the responsibleTransmission
: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes.void
transmitTo(SerialTransceiver aSerialTransceiver)
Transmits to the responsibleTransmission
: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims 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 givenInputStream
before theInputStream
cannot 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
-
AbstractMagicBytesTransmissionDispatcher
protected AbstractMagicBytesTransmissionDispatcher()
Constructs an emptyAbstractMagicBytesTransmissionDispatcher
for sub-classes to use having the responsibility to set the children by themselves.
-
AbstractMagicBytesTransmissionDispatcher
@SafeVarargs public AbstractMagicBytesTransmissionDispatcher(CHILD... aSegments)
Constructs aAbstractMagicBytesTransmissionDispatcher
containing the providedTransmission
elements.- Parameters:
aSegments
- TheTransmission
elements being contained in this instance.
-
AbstractMagicBytesTransmissionDispatcher
public AbstractMagicBytesTransmissionDispatcher(Collection<CHILD> aSegments)
Constructs aAbstractMagicBytesTransmissionDispatcher
containing the providedTransmission
elements.- Parameters:
aSegments
- TheTransmission
elements being contained in this instance.
-
AbstractMagicBytesTransmissionDispatcher
@SafeVarargs public AbstractMagicBytesTransmissionDispatcher(int aReadLimit, CHILD... aSegments)
Constructs aAbstractMagicBytesTransmissionDispatcher
containing the providedTransmission
elements.- Parameters:
aReadLimit
- the maximum limit of bytes that can be read from a givenInputStream
before theInputStream
cannot be rolled back.aSegments
- TheTransmission
elements being contained in this instance.
-
AbstractMagicBytesTransmissionDispatcher
public AbstractMagicBytesTransmissionDispatcher(Collection<CHILD> aSegments, int aReadLimit)
Constructs aAbstractMagicBytesTransmissionDispatcher
containing the providedTransmission
elements.- Parameters:
aSegments
- TheTransmission
elements being contained in this instance.aReadLimit
- the maximum limit of bytes that can be read from a givenInputStream
before theInputStream
cannot be rolled back.
-
-
Method Detail
-
getLength
public int getLength()
Returns the length of the responsibleTransmission
: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes. Initially the firstTransmission
passed to this instance is the responsibleTransmission
. 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).
-
toTransmission
public Sequence toTransmission()
Returns the responsibleTransmission
's transmission: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes. Initially the firstTransmission
passed to this instance is the responsibleTransmission
. Provides theSequence
representation of thisTransmission
. In case of nestedTransmission
instances, allSequence
representations from all sub-segments are accumulated to the result as well.- Specified by:
toTransmission
in interfaceTransmission
- Returns:
- The according instance's
Sequence
.
-
transmitTo
public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
Transmits to the responsibleTransmission
: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes. Initially the firstTransmission
passed to this instance is the responsibleTransmission
. 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
- 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
public Schema toSchema()
Retrieves theSchema
representing theTransmission
. Retrieving aSchema
is useful when analyzing and debugging data structures such as aAllocSectionDecoratorSegment
instance to help document, learn and verify on the structure (as well as the content) of that veryAllocSectionDecoratorSegment
.- Specified by:
toSchema
in interfaceTransmission
- Returns:
- The
Schema
representation of the implementing type for debugging and verification (or documentation) purposes.
-
toSimpleTypeMap
public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()
Returns the responsibleTransmission
'sSimpleTypeMap
representation: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes. Initially the firstTransmission
passed to this instance is the responsibleTransmission
. 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.
-
transmitTo
public void transmitTo(OutputStream aOutputStream) throws IOException
Transmits to the responsibleTransmission
: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes. Initially the firstTransmission
passed to this instance is the responsibleTransmission
. Transmits theSequence
representing the implementing type's instance to the givenOutputStream
. This is a convenience method in case there is no feedbackInputStream
available (actually theTransmission.transmitTo(OutputStream, InputStream)
method is invoked withnull
for the feedbackInputStream
). OverrideTransmission.transmitTo(OutputStream, InputStream)
for your custom transmitting functionality.- Specified by:
transmitTo
in interfaceTransmission
- Parameters:
aOutputStream
- TheOutputStream
where to write this instance'sSequence
to.- Throws:
IOException
- thrown in case writing data to theOutputStream
caused problems.
-
transmitTo
public void transmitTo(SerialTransceiver aSerialTransceiver) throws IOException
Transmits to the responsibleTransmission
: The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes. Initially the firstTransmission
passed to this instance is the responsibleTransmission
. Transmits theSequence
representing the implementing type's instance to the givenSerialTransceiver
'sOutputStream
. Implementations providing error correction methods use the providedSerialTransceiver
's feedbackInputStream
to 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:
transmitTo
in interfaceTransmission
- Parameters:
aSerialTransceiver
- TheSerialTransceiver
providing theOutputStream
where to write this instance'sSequence
to and providing theInputStream
being the return channel to handle "stop-and-wait ARQ".- Throws:
IOException
- thrown in case writing data to theOutputStream
caused problems.
-
iterator
public Iterator<CHILD> iterator()
- Specified by:
iterator
in interfaceIterable<CHILD extends Transmission>
-
getChildren
public CHILD[] getChildren()
- Specified by:
getChildren
in interfaceorg.refcodes.mixin.ChildrenAccessor<CHILD extends Transmission>
-
getResponsibility
public CHILD getResponsibility()
The lastTransmission
which was responsible for a transmission's magic bytes will be the responsibleTransmission
till anotherTransmission
claims responsibility for a transmsision's magic bytes. Initially the firstTransmission
passed to this instance is the responsibleTransmission
.- Returns:
- Returns the responsible
Transmission
.
-
-