- java.lang.Object
-
- org.refcodes.serial.AbstractMagicBytesTransmissionMultiplexer<Section>
-
- org.refcodes.serial.MagicBytesSectionMultiplexer
-
- All Implemented Interfaces:
Serializable
,Iterable<Section>
,org.refcodes.mixin.ChildrenAccessor<Section[]>
,org.refcodes.mixin.LengthAccessor
,Section
,Transmission
public class MagicBytesSectionMultiplexer extends AbstractMagicBytesTransmissionMultiplexer<Section> implements Section, Iterable<Section>, org.refcodes.mixin.ChildrenAccessor<Section[]>
THeMagicBytesSectionMultiplexer
dispatches a transmission to one of the aggregatedSection
instances depending on the magic number provided by the transmission. A transmission is passed to each of the aggregatedSection
instances till oneSection
accepts the transmission, e.g. until aSection
does not throw aBadMagicBytesException
. To enforce throwing aBadMagicBytesException
use a magic bytesSegment
orSection
which enforces the magic bytes to of a transmission to match its own magic bytes, e.e. use one of the following:AssertMagicBytesSectionDecorator
,AssertMagicBytesSegment
,AssertMagicBytesSegmentDecorator
Attention: ASection
throwing aTransmissionException
other than aBadMagicBytesException
is considered to be responsible for the transmission so that dispatching is *not* continued with the succeedingSection
! The lastSection
which was responsible for a transmission's magic bytes will be the responsibleSection
till anotherSection
claims responsibility for a transmsision's magic bytes. Initially the firstSection
passed to this instance is the responsibleSection
.- 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.Section
Section.SectionMixin
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
-
Field Summary
-
Fields inherited from class org.refcodes.serial.AbstractMagicBytesTransmissionMultiplexer
_children, _readLimit, _responsibility, DEFAULT_READ_LIMIT
-
-
Constructor Summary
Constructors Constructor Description MagicBytesSectionMultiplexer()
MagicBytesSectionMultiplexer(int aReadLimit, Section... aSections)
MagicBytesSectionMultiplexer(Collection<Section> aSections)
MagicBytesSectionMultiplexer(Collection<Section> aSections, int aReadLimit)
MagicBytesSectionMultiplexer(Section... aSections)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fromTransmission(byte[] aChunk, int aLength)
(Re-)initializes this instance with the the given byte array data.void
fromTransmission(byte[] aChunk, int aOffset, int aLength)
(Re-)initializes this instance with the the given byte array data.void
fromTransmission(Sequence aSequence, int aLength)
(Re-)initializes this instance with the the givenSequence
data.void
fromTransmission(Sequence aSequence, int aOffset, int aLength)
(Re-)initializes this instance with the the givenSequence
data.void
receiveFrom(InputStream aInputStream, int aLength)
(Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
.void
receiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream)
(Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
.void
receiveFrom(SerialTransceiver aSerialTransceiver, int aLength)
(Re-)initializes this instance by receiving the accordingSequence
from the givenSerialTransceiver
'sInputStream
.-
Methods inherited from class org.refcodes.serial.AbstractMagicBytesTransmissionMultiplexer
getCallee, getChildren, getLength, iterator, toSchema, toSequence, toSimpleTypeMap, transmitTo, transmitTo, transmitTo
-
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, iterator, spliterator
-
Methods inherited from interface org.refcodes.serial.Transmission
getLength, toSchema, toSequence, toSimpleTypeMap, transmitTo, transmitTo, transmitTo
-
-
-
-
Constructor Detail
-
MagicBytesSectionMultiplexer
public MagicBytesSectionMultiplexer()
-
MagicBytesSectionMultiplexer
public MagicBytesSectionMultiplexer(Collection<Section> aSections, int aReadLimit)
-
MagicBytesSectionMultiplexer
public MagicBytesSectionMultiplexer(Collection<Section> aSections)
-
MagicBytesSectionMultiplexer
public MagicBytesSectionMultiplexer(int aReadLimit, Section... aSections)
-
MagicBytesSectionMultiplexer
public MagicBytesSectionMultiplexer(Section... aSections)
-
-
Method Detail
-
fromTransmission
public void fromTransmission(byte[] aChunk, int aLength) throws TransmissionException
(Re-)initializes this instance with the the given byte array data.- Specified by:
fromTransmission
in interfaceSection
- Parameters:
aChunk
- The byte array data from which to (re-)initialize this instance.aLength
- The length of data assigned by the byte array.- Throws:
TransmissionException
- thrown in case a givenSequence
cannot be processed.
-
fromTransmission
public void fromTransmission(Sequence aSequence, int aLength) throws TransmissionException
(Re-)initializes this instance with the the givenSequence
data.- Specified by:
fromTransmission
in interfaceSection
- Parameters:
aSequence
- TheSequence
data from which to (re-)initialize this instance.aLength
- The length of data assigned by theSequence
.- Throws:
TransmissionException
- thrown in case a givenSequence
cannot be processed.
-
fromTransmission
public void fromTransmission(byte[] aChunk, int aOffset, int aLength) throws TransmissionException
(Re-)initializes this instance with the the given byte array data.- Specified by:
fromTransmission
in interfaceSection
- Parameters:
aChunk
- The byte array data from which to (re-)initialize this instance.aOffset
- The offset where to start processing the provided byte array.aLength
- The length of data assigned by the byte array.- Throws:
TransmissionException
- thrown in case a givenSequence
cannot be processed.
-
receiveFrom
public void receiveFrom(InputStream aInputStream, int aLength) throws IOException, TransmissionException
(Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
. This is a convenience method in case there is no feedbackOutputStream
available (actually theSection.receiveFrom(InputStream, int, OutputStream )
method is invoked withnull
for the feedbackOutputStream
). OverrideSection.receiveFrom(InputStream, int, OutputStream)
for your custom receiving functionality.- Specified by:
receiveFrom
in interfaceSection
- Parameters:
aInputStream
- TheInputStream
from which to read the instance's (re-)initializationSequence
from.aLength
- The length of data assigned by the byte array.- Throws:
IOException
- thrown in case reading data from theInputStream
caused problems.TransmissionException
- thrown in case a givenInputStream
bytes cannot be processed.
-
receiveFrom
public void receiveFrom(SerialTransceiver aSerialTransceiver, int aLength) throws IOException, TransmissionException
(Re-)initializes this instance by receiving the accordingSequence
from the givenSerialTransceiver
'sInputStream
. Implementations providing error correction methods use the providedSerialTransceiver
's feedbackOutputStream
to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data. This is a convenience method (actually theSection.receiveFrom(InputStream, int, OutputStream )
method is invoked). OverrideSection.receiveFrom(InputStream, int, OutputStream)
for your custom receiving functionality.- Specified by:
receiveFrom
in interfaceSection
- Parameters:
aSerialTransceiver
- TheSerialTransceiver
providing theInputStream
where to read this instance'sSequence
from and providing theOutputStream
being the feedback channel to handle "stop-and-wait ARQ".aLength
- The length of data assigned by the byte array.- Throws:
IOException
- thrown in case reading data from theInputStream
caused problems.TransmissionException
- thrown in case a givenInputStream
bytes cannot be processed.
-
fromTransmission
public void fromTransmission(Sequence aSequence, int aOffset, int aLength) throws TransmissionException
(Re-)initializes this instance with the the givenSequence
data.- Specified by:
fromTransmission
in interfaceSection
- Parameters:
aSequence
- TheSequence
data from which to (re-)initialize this instance.aOffset
- The offset where to start processing the providedSequence
.aLength
- The length of data assigned by theSequence
.- Throws:
TransmissionException
- thrown in case a givenSequence
cannot be processed.
-
receiveFrom
public void receiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream) throws IOException, TransmissionException
(Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
. Implementations providing error correction methods use the provided feedbackOutputStream
to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.- Specified by:
receiveFrom
in interfaceSection
- Parameters:
aInputStream
- TheInputStream
from which to read the instance's (re-)initializationSequence
from.aLength
- The length of data assigned by the byte array.aReturnStream
- AnOutputStream
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 reading data from theInputStream
caused problems.TransmissionException
- thrown in case a givenInputStream
bytes cannot be processed.
-
-