Serializable
, Iterable<CHILD>
, org.refcodes.mixin.ChildrenAccessor<CHILD[]>
, org.refcodes.mixin.LengthAccessor
, Transmission
MagicBytesSectionDispatcher
, MagicBytesSegmentDispatcher
public class AbstractMagicBytesTransmissionDispatcher<CHILD extends Transmission> extends Object implements Transmission, Iterable<CHILD>, org.refcodes.mixin.ChildrenAccessor<CHILD[]>
AbstractMagicBytesTransmissionDispatcher
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
.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>
org.refcodes.mixin.LengthAccessor.LengthBuilder<B extends org.refcodes.mixin.LengthAccessor.LengthBuilder<B>>, org.refcodes.mixin.LengthAccessor.LengthMutator, org.refcodes.mixin.LengthAccessor.LengthProperty
Transmission.TransmissionMixin
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 given
InputStream before the
InputStream cannot be rolled back. |
Modifier | Constructor | Description |
---|---|---|
protected |
AbstractMagicBytesTransmissionDispatcher() |
Constructs an empty
AbstractMagicBytesTransmissionDispatcher for
sub-classes to use having the responsibility to set the children by
themselves. |
|
AbstractMagicBytesTransmissionDispatcher(int aReadLimit,
CHILD... aSegments) |
Constructs a
AbstractMagicBytesTransmissionDispatcher containing
the provided Transmission elements. |
|
AbstractMagicBytesTransmissionDispatcher(CHILD... aSegments) |
Constructs a
AbstractMagicBytesTransmissionDispatcher containing
the provided Transmission elements. |
|
AbstractMagicBytesTransmissionDispatcher(Collection<CHILD> aSegments) |
Constructs a
AbstractMagicBytesTransmissionDispatcher containing
the provided Transmission elements. |
|
AbstractMagicBytesTransmissionDispatcher(Collection<CHILD> aSegments,
int aReadLimit) |
Constructs a
AbstractMagicBytesTransmissionDispatcher containing
the provided Transmission elements. |
Modifier and Type | Method | Description |
---|---|---|
CHILD[] |
getChildren() |
|
int |
getLength() |
Returns the length of the responsible
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. |
CHILD |
getResponsibility() |
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. |
Iterator<CHILD> |
iterator() |
|
Schema |
toSchema() |
Retrieves the
Schema representing the Transmission . |
org.refcodes.struct.SimpleTypeMap |
toSimpleTypeMap() |
Returns the responsible
Transmission 's SimpleTypeMap
representation: 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. |
Sequence |
toTransmission() |
Returns the responsible
Transmission 's 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. |
void |
transmitTo(OutputStream aOutputStream) |
Transmits to the responsible
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. |
void |
transmitTo(OutputStream aOutputStream,
InputStream aReturnStream) |
Transmits to the responsible
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. |
void |
transmitTo(SerialTransceiver aSerialTransceiver) |
Transmits to the responsible
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. |
forEach, spliterator
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
fromInputStream
public static final int DEFAULT_READ_LIMIT
InputStream
before the
InputStream
cannot be rolled back.protected CHILD extends Transmission[] _children
protected CHILD extends Transmission _responsibility
protected int _readLimit
protected AbstractMagicBytesTransmissionDispatcher()
AbstractMagicBytesTransmissionDispatcher
for
sub-classes to use having the responsibility to set the children by
themselves.@SafeVarargs public AbstractMagicBytesTransmissionDispatcher(CHILD... aSegments)
AbstractMagicBytesTransmissionDispatcher
containing
the provided Transmission
elements.aSegments
- The Transmission
elements being contained in
this instance.public AbstractMagicBytesTransmissionDispatcher(Collection<CHILD> aSegments)
AbstractMagicBytesTransmissionDispatcher
containing
the provided Transmission
elements.aSegments
- The Transmission
elements being contained in
this instance.@SafeVarargs public AbstractMagicBytesTransmissionDispatcher(int aReadLimit, CHILD... aSegments)
AbstractMagicBytesTransmissionDispatcher
containing
the provided Transmission
elements.aReadLimit
- the maximum limit of bytes that can be read from a
given InputStream
before the InputStream
cannot be
rolled back.aSegments
- The Transmission
elements being contained in
this instance.public AbstractMagicBytesTransmissionDispatcher(Collection<CHILD> aSegments, int aReadLimit)
AbstractMagicBytesTransmissionDispatcher
containing
the provided Transmission
elements.aSegments
- The Transmission
elements being contained in
this instance.aReadLimit
- the maximum limit of bytes that can be read from a
given InputStream
before the InputStream
cannot be
rolled back.public int getLength()
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
. Determines the overall length of this Transmission
. In case of
nested Transmission
instances, all length values from all
sub-segments are accumulated to the result as well.getLength
in interface org.refcodes.mixin.LengthAccessor
getLength
in interface Transmission
Transmission
(including any
sub-segments).public Sequence toTransmission()
Transmission
's 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
. Provides the Sequence
representation of this
Transmission
. In case of nested Transmission
instances,
all Sequence
representations from all sub-segments are
accumulated to the result as well.toTransmission
in interface Transmission
Sequence
.public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
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
. Transmits the Sequence
representing the implementing type's
instance to the given OutputStream
. Implementations providing
error correction methods use the provided feedback InputStream
to
do some sort of "stop-and-wait ARQ" or apply similar methods to ensure
correctness of the transmitted data.transmitTo
in interface Transmission
aOutputStream
- The OutputStream
where to write this
instance's Sequence
to.aReturnStream
- An InputStream
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.IOException
- thrown in case writing data to the
OutputStream
caused problems.public Schema toSchema()
Schema
representing the Transmission
.
Retrieving a Schema
is useful when analyzing and debugging data
structures such as a AllocSectionDecoratorSegment
instance to help
document, learn and verify on the structure (as well as the content) of
that very AllocSectionDecoratorSegment
.toSchema
in interface Transmission
Schema
representation of the implementing type for
debugging and verification (or documentation) purposes.public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()
Transmission
's SimpleTypeMap
representation: 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
.
Returns the SimpleTypeMap
representation of this
Transmission
. In case this Transmission has Transmission
children, then the children are queried as well and contained in the
resulting SimpleTypeMap
. The aliases of the according
Transmission
instances represent the resulting path to a
Transmission
's final simple type.toSimpleTypeMap
in interface Transmission
SimpleTypeMap
representing this Transmission
and (if any) its children, with the according aliases forming the
paths to the Transmission
's values.public void transmitTo(OutputStream aOutputStream) throws IOException
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
. Transmits the Sequence
representing the implementing type's
instance to the given OutputStream
. This is a convenience method
in case there is no feedback InputStream
available (actually the
Transmission.transmitTo(OutputStream, InputStream)
method is invoked with
null
for the feedback InputStream
). Override
Transmission.transmitTo(OutputStream, InputStream)
for your custom
transmitting functionality.transmitTo
in interface Transmission
aOutputStream
- The OutputStream
where to write this
instance's Sequence
to.IOException
- thrown in case writing data to the
OutputStream
caused problems.public void transmitTo(SerialTransceiver aSerialTransceiver) throws IOException
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
. Transmits the Sequence
representing the implementing type's
instance to the given SerialTransceiver
's OutputStream
.
Implementations providing error correction methods use the provided
SerialTransceiver
's feedback InputStream
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 the
Transmission.transmitTo(OutputStream, InputStream)
method is invoked).
Override Transmission.transmitTo(OutputStream, InputStream)
for your custom
transmitting functionality.transmitTo
in interface Transmission
aSerialTransceiver
- The SerialTransceiver
providing the
OutputStream
where to write this instance's
Sequence
to and providing the InputStream
being
the return channel to handle "stop-and-wait ARQ".IOException
- thrown in case writing data to the
OutputStream
caused problems.public Iterator<CHILD> iterator()
iterator
in interface Iterable<CHILD extends Transmission>
public CHILD[] getChildren()
getChildren
in interface org.refcodes.mixin.ChildrenAccessor<CHILD extends Transmission>
public CHILD getResponsibility()
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
.Transmission
.Copyright © 2021. All rights reserved.