- java.lang.Object
-
- org.refcodes.serial.AbstractMagicBytesTransmissionMultiplexer<Segment>
-
- org.refcodes.serial.MagicBytesSegmentMultiplexer
-
- All Implemented Interfaces:
Serializable,Iterable<Segment>,org.refcodes.mixin.ChildrenAccessor<Segment[]>,org.refcodes.mixin.LengthAccessor,Segment,Transmission
public class MagicBytesSegmentMultiplexer extends AbstractMagicBytesTransmissionMultiplexer<Segment> implements Segment, Iterable<Segment>, org.refcodes.mixin.ChildrenAccessor<Segment[]>
THeMagicBytesSegmentMultiplexerdispatches a transmission to one of the aggregatedSegmentinstances depending on the magic number provided by the transmission. A transmission is passed to each of the aggregatedSegmentinstances till oneSegmentaccepts the transmission, e.g. until aSegmentdoes not throw aBadMagicBytesException. To enforce throwing aBadMagicBytesExceptionuse a magic bytesSegmentorSectionwhich enforces the magic bytes to of a transmission to match its own magic bytes, e.e. use one of the following:AssertMagicBytesSectionDecorator,AssertMagicBytesSegment,AssertMagicBytesSegmentDecoratorAttention: ASegmentthrowing aTransmissionExceptionother than aBadMagicBytesExceptionis considered to be responsible for the transmission so that dispatching is *not* continued with the succeedingSegment! The lastSegmentwhich was responsible for a transmission's magic bytes will be the responsibleSegmenttill anotherSegmentclaims responsibility for a transmsision's magic bytes. Initially the firstSegmentpassed to this instance is the responsibleSegment.- 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.Segment
Segment.SegmentMixin
-
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 MagicBytesSegmentMultiplexer()MagicBytesSegmentMultiplexer(int aReadLimit, Segment... aSegments)MagicBytesSegmentMultiplexer(Collection<Segment> aSegments)MagicBytesSegmentMultiplexer(Collection<Segment> aSegments, int aReadLimit)MagicBytesSegmentMultiplexer(Segment... aSegments)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intfromTransmission(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 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
-
MagicBytesSegmentMultiplexer
public MagicBytesSegmentMultiplexer()
-
MagicBytesSegmentMultiplexer
public MagicBytesSegmentMultiplexer(Collection<Segment> aSegments, int aReadLimit)
-
MagicBytesSegmentMultiplexer
public MagicBytesSegmentMultiplexer(Collection<Segment> aSegments)
-
MagicBytesSegmentMultiplexer
public MagicBytesSegmentMultiplexer(int aReadLimit, Segment... aSegments)
-
MagicBytesSegmentMultiplexer
public MagicBytesSegmentMultiplexer(Segment... aSegments)
-
-
Method Detail
-
fromTransmission
public int fromTransmission(byte[] aChunk) throws TransmissionException(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
public int fromTransmission(Sequence aSequence) throws TransmissionException
(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
public int fromTransmission(byte[] aChunk, int aOffset) throws TransmissionException(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
public void receiveFrom(InputStream aInputStream) throws IOException, TransmissionException
(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.TransmissionException- thrown in case a given transmission cannot be processed.
-
receiveFrom
public void receiveFrom(SerialTransceiver aSerialTransceiver) throws IOException, TransmissionException
(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.TransmissionException- thrown in case a given transmission cannot be processed.
-
fromTransmission
public int fromTransmission(Sequence aSequence, int aOffset) throws TransmissionException
(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
public void receiveFrom(InputStream aInputStream, OutputStream aReturnStream) throws IOException, TransmissionException
(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.TransmissionException- thrown in case a given transmission cannot be processed.
-
-