Class MagicBytesSegmentMultiplexer
java.lang.Object
org.refcodes.serial.AbstractMagicBytesTransmissionMultiplexer<Segment>
org.refcodes.serial.MagicBytesSegmentMultiplexer
- All Implemented Interfaces:
Serializable, Iterable<Segment>, ChildrenAccessor<Segment[]>, LengthAccessor, Resetable, Diagnosable, Schemable<DiagnosticOptions>, Segment, Transmission
public class MagicBytesSegmentMultiplexer
extends AbstractMagicBytesTransmissionMultiplexer<Segment>
implements Segment
THe
MagicBytesSegmentMultiplexer dispatches a transmission to one of
the aggregated Segment instances depending on the magic number
provided by the transmission. A transmission is passed to each of the
aggregated Segment instances till one Segment accepts the
transmission, e.g. until a Segment does not throw a
BadMagicBytesException. To enforce throwing a
BadMagicBytesException use a magic bytes Segment or
Section 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: A Segment
throwing a TransmissionException other than a
BadMagicBytesException is considered to be responsible for the
transmission so that dispatching is *not* continued with the succeeding
Segment! The last Segment which was responsible for a
transmission's magic bytes will be the responsible Segment till
another Segment claims responsibility for a transmsision's magic
bytes. Initially the first Segment passed to this instance is the
responsible Segment.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChildrenAccessor
ChildrenAccessor.ChildrenBuilder<T,B>, ChildrenAccessor.ChildrenMutator<T>, ChildrenAccessor.ChildrenProperty<T> Nested classes/interfaces inherited from interface LengthAccessor
LengthAccessor.LengthBuilder<B>, LengthAccessor.LengthMutator, LengthAccessor.LengthPropertyNested classes/interfaces inherited from interface Segment
Segment.SegmentMixinNested classes/interfaces inherited from interface Transmission
Transmission.TransmissionMixin -
Field Summary
Fields inherited from class AbstractMagicBytesTransmissionMultiplexer
_children, _readLimit, _responsibility, DEFAULT_READ_LIMIT -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates the classMagicBytesSegmentMultiplexer.MagicBytesSegmentMultiplexer(int aReadLimit, Segment... aSegments) Instantiates the classMagicBytesSegmentMultiplexer.MagicBytesSegmentMultiplexer(Collection<Segment> aSegments) Instantiates the classMagicBytesSegmentMultiplexer.MagicBytesSegmentMultiplexer(Collection<Segment> aSegments, int aReadLimit) Instantiates the classMagicBytesSegmentMultiplexer.MagicBytesSegmentMultiplexer(Segment... aSegments) Instantiates the classMagicBytesSegmentMultiplexer. -
Method Summary
Modifier and TypeMethodDescriptionintfromTransmission(byte[] aChunk) (Re-)initializes this instance with the the given byte array data.intfromTransmission(byte[] aChunk, int aOffset) (Re-)initializes this instance with the the given byte array data.intfromTransmission(Sequence aSequence) (Re-)initializes this instance with the the givenSequencedata.intfromTransmission(Sequence aSequence, int aOffset) (Re-)initializes this instance with the the givenSequencedata.voidreceiveFrom(InputStream aInputStream) (Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream.voidreceiveFrom(InputStream aInputStream, OutputStream aReturnStream) (Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream.voidreceiveFrom(SerialTransceiver aSerialTransceiver) (Re-)initializes this instance by receiving the accordingSequencefrom the givenSerialTransceiver'sInputStream.Methods inherited from class AbstractMagicBytesTransmissionMultiplexer
getCallee, getChildren, getLength, iterator, reset, toSchema, toSequence, toSimpleTypeTable, transmitTo, transmitTo, transmitToMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface Transmission
getLength, reset, toSequence, toSimpleTypeTable, transmitTo, transmitTo, transmitTo
-
Constructor Details
-
MagicBytesSegmentMultiplexer
public MagicBytesSegmentMultiplexer()Instantiates the classMagicBytesSegmentMultiplexer.- See Also:
-
MagicBytesSegmentMultiplexer
Instantiates the classMagicBytesSegmentMultiplexer.- Parameters:
aSegments- the segmentsaReadLimit- the read limit- See Also:
-
MagicBytesSegmentMultiplexer
Instantiates the classMagicBytesSegmentMultiplexer.- Parameters:
aSegments- the segments- See Also:
-
MagicBytesSegmentMultiplexer
Instantiates the classMagicBytesSegmentMultiplexer.- Parameters:
aReadLimit- the read limitaSegments- the segments- See Also:
-
MagicBytesSegmentMultiplexer
Instantiates the classMagicBytesSegmentMultiplexer.- Parameters:
aSegments- the segments- See Also:
-
-
Method Details
-
fromTransmission
(Re-)initializes this instance with the the given byte array data.- Specified by:
fromTransmissionin interfaceSegment- Parameters:
aChunk- The byte array data from which to (re-)initialize this instance.- Returns:
- The index after the last offset into the given byte array processed by this method.
- Throws:
TransmissionException- thrown in case a givenSequencecannot be processed.
-
fromTransmission
(Re-)initializes this instance with the the givenSequencedata.- Specified by:
fromTransmissionin interfaceSegment- Parameters:
aSequence- TheSequencedata from which to (re-)initialize this instance.- Returns:
- The index after the last offset into the given
Sequenceprocessed by this method. - Throws:
TransmissionException- thrown in case a givenSequencecannot be processed.
-
fromTransmission
(Re-)initializes this instance with the the given byte array data.- Specified by:
fromTransmissionin interfaceSegment- Parameters:
aChunk- The byte array data from which to (re-)initialize this instance.aOffset- The offset where to start processing the provided byte array.- Returns:
- The index after the last offset into the given byte array processed by this method.
- Throws:
TransmissionException- thrown in case a givenSequencecannot be processed.
-
receiveFrom
(Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream. This is a convenience method in case there is no feedbackOutputStreamavailable (actually theSegment.receiveFrom(InputStream, OutputStream)method is invoked withnullfor the feedbackOutputStream). OverrideSegment.receiveFrom(InputStream, OutputStream)for your custom receiving functionality.- Specified by:
receiveFromin interfaceSegment- Parameters:
aInputStream- TheInputStreamfrom which to read the instance's (re-)initializationSequencefrom.- Throws:
IOException- thrown in case reading data from theInputStreamcaused problems.
-
receiveFrom
(Re-)initializes this instance by receiving the accordingSequencefrom the givenSerialTransceiver'sInputStream. Implementations providing error correction methods use the providedSerialTransceiver's feedbackOutputStreamto 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 theSegment.receiveFrom(InputStream, OutputStream)method is invoked). OverrideSegment.receiveFrom(InputStream, OutputStream)for your custom receiving functionality.- Specified by:
receiveFromin interfaceSegment- Parameters:
aSerialTransceiver- TheSerialTransceiverproviding theInputStreamwhere to read this instance'sSequencefrom and providing theOutputStreambeing the feedback channel to handle "stop-and-wait ARQ".- Throws:
IOException- thrown in case reading data from theInputStreamcaused problems.
-
fromTransmission
(Re-)initializes this instance with the the givenSequencedata.- Specified by:
fromTransmissionin interfaceSegment- Parameters:
aSequence- TheSequencedata from which to (re-)initialize this instance.aOffset- The offset where to start processing the providedSequence.- Returns:
- The index after the last offset into the given
Sequenceprocessed by this method. - Throws:
TransmissionException- thrown in case a givenSequencecannot be processed.
-
receiveFrom
(Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream. Implementations providing error correction methods use the provided feedbackOutputStreamto do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.- Specified by:
receiveFromin interfaceSegment- Parameters:
aInputStream- TheInputStreamfrom which to read the instance's (re-)initializationSequencefrom.aReturnStream- AnOutputStreambeing 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 theInputStreamcaused problems.
-