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.Schemable
,Transmission
- Direct Known Subclasses:
MagicBytesSectionMultiplexer
,MagicBytesSegmentMultiplexer
public 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.LengthProperty
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CHILD[]
protected int
protected CHILD
static final int
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
ConstructorsModifierConstructorDescriptionprotected
Constructs an emptyAbstractMagicBytesTransmissionMultiplexer
for sub-classes to use having the responsibility to set the children by themselves.AbstractMagicBytesTransmissionMultiplexer
(int aReadLimit, CHILD... aSegments) Constructs aAbstractMagicBytesTransmissionMultiplexer
containing the providedTransmission
elements.AbstractMagicBytesTransmissionMultiplexer
(CHILD... aSegments) Constructs aAbstractMagicBytesTransmissionMultiplexer
containing the providedTransmission
elements.AbstractMagicBytesTransmissionMultiplexer
(Collection<CHILD> aSegments) Constructs aAbstractMagicBytesTransmissionMultiplexer
containing the providedTransmission
elements.AbstractMagicBytesTransmissionMultiplexer
(Collection<CHILD> aSegments, int aReadLimit) Constructs aAbstractMagicBytesTransmissionMultiplexer
containing the providedTransmission
elements. -
Method Summary
Modifier and TypeMethodDescriptionThe lastTransmission
to which the dispatch was transferred, e.g.CHILD[]
int
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.iterator()
toSchema()
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.org.refcodes.struct.SimpleTypeMap
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.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 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 givenInputStream
before theInputStream
cannot be rolled back.- See Also:
-
_children
-
_responsibility
-
_readLimit
protected int _readLimit
-
-
Constructor Details
-
AbstractMagicBytesTransmissionMultiplexer
protected AbstractMagicBytesTransmissionMultiplexer()Constructs an emptyAbstractMagicBytesTransmissionMultiplexer
for sub-classes to use having the responsibility to set the children by themselves. -
AbstractMagicBytesTransmissionMultiplexer
Constructs aAbstractMagicBytesTransmissionMultiplexer
containing the providedTransmission
elements.- Parameters:
aSegments
- TheTransmission
elements being contained in this instance.
-
AbstractMagicBytesTransmissionMultiplexer
Constructs aAbstractMagicBytesTransmissionMultiplexer
containing the providedTransmission
elements.- Parameters:
aSegments
- TheTransmission
elements being contained in this instance.
-
AbstractMagicBytesTransmissionMultiplexer
Constructs aAbstractMagicBytesTransmissionMultiplexer
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.
-
AbstractMagicBytesTransmissionMultiplexer
Constructs aAbstractMagicBytesTransmissionMultiplexer
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 Details
-
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).
-
toSequence
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. Caution, the Transmission (or its nestedTransmission
instances) may be backed by the returnedSequence
.- Specified by:
toSequence
in interfaceTransmission
- Returns:
- The according instance's
Sequence
.
-
transmitTo
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
- Specified by:
toSchema
in interfaceorg.refcodes.mixin.Schemable
- Specified by:
toSchema
in interfaceTransmission
-
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
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
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
- Specified by:
iterator
in interfaceIterable<CHILD extends Transmission>
-
getChildren
- Specified by:
getChildren
in interfaceorg.refcodes.mixin.ChildrenAccessor<CHILD extends Transmission>
-
getCallee
The lastTransmission
to which the dispatch was transferred, e.g. which matched the dispatch's magic bytes till anotherTransmission
claims responsibility for a dispatch's magic bytes..- Returns:
- Returns the
Transmission
to which the dispatch was transferred.
-