Module org.refcodes.serial
Package org.refcodes.serial
Class SectionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>,CHILD extends Section>
java.lang.Object
org.refcodes.serial.SectionComposite<ALLOC,CHILD>
- Type Parameters:
ALLOC- The type of theAllocSectionDecoratorSegmentdescribing the length of eachSectionelement in the composite.CHILD- The type of theSectionelements to be contained in theSectionComposite.
- All Implemented Interfaces:
Serializable,org.refcodes.mixin.ChildrenAccessor<CHILD[]>,org.refcodes.mixin.LengthAccessor,org.refcodes.mixin.Resetable,org.refcodes.schema.Schemable,Section,Section.SectionMixin,Transmission,Transmission.TransmissionMixin,TransmissionComposite<CHILD>
public class SectionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>,CHILD extends Section>
extends Object
implements Section, Section.SectionMixin, TransmissionComposite<CHILD>
A
SectionComposite is a Section consisting of Section
elements of a variable length each: Each Section element in the
composite need not be of the same size. This is achieved by wrapping each
Section inside a dedicated AllocSectionDecoratorSegment being
a Segment providing the resulting Section's length (with all
the composite's Section instances).- 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.LengthPropertyNested classes/interfaces inherited from interface org.refcodes.serial.Section
Section.SectionMixinNested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin -
Constructor Summary
ConstructorsConstructorDescriptionSectionComposite(Class<ALLOC> aAllocSegmentClass, Class<CHILD> aSegmentClass) Constructs aSectionComposite.SectionComposite(Class<ALLOC> aAllocSegmentClass, Class<CHILD> aSegmentClass, CHILD... aSegmentArray) Constructs aSectionCompositecontaining the providedAllocSectionDecoratorSegmentelements.SectionComposite(org.refcodes.factory.TypeFactory<ALLOC> aAllocSegmentFactory, org.refcodes.factory.TypeFactory<CHILD> aSegmentFactory) Constructs aSectionCompositecontaining the providedAllocSectionDecoratorSegmentelements and using the provided factories for creatingSegmentandSectioninstances.SectionComposite(org.refcodes.factory.TypeFactory<ALLOC> aAllocSegmentFactory, org.refcodes.factory.TypeFactory<CHILD> aSegmentFactory, CHILD... aSegmentArray) Constructs aSectionCompositecontaining the providedAllocSectionDecoratorSegmentelements and using the provided factories for creatingSegmentandSectioninstances. -
Method Summary
Modifier and TypeMethodDescriptionvoidfromTransmission(Sequence aSequence, int aOffset, int aLength) (Re-)initializes this instance with the the givenSequencedata.CHILD[]intDetermines the overall length of thisTransmission.voidreceiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream) (Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream.voidreset()Resets any dynamic data (e.g. values such as payloads or checksums) and must not(!)protected voidsetChildren(CHILD[] aChildren) Hook for easily setting the children.toSchema()Provides theSequencerepresentation of thisTransmission.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.refcodes.serial.Section
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFromMethods inherited from interface org.refcodes.serial.Transmission
transmitTo, transmitToMethods inherited from interface org.refcodes.serial.Transmission.TransmissionMixin
transmitToMethods inherited from interface org.refcodes.serial.TransmissionComposite
toSimpleTypeMap
-
Constructor Details
-
SectionComposite
public SectionComposite(org.refcodes.factory.TypeFactory<ALLOC> aAllocSegmentFactory, org.refcodes.factory.TypeFactory<CHILD> aSegmentFactory) Constructs aSectionCompositecontaining the providedAllocSectionDecoratorSegmentelements and using the provided factories for creatingSegmentandSectioninstances. -
SectionComposite
@SafeVarargs public SectionComposite(org.refcodes.factory.TypeFactory<ALLOC> aAllocSegmentFactory, org.refcodes.factory.TypeFactory<CHILD> aSegmentFactory, CHILD... aSegmentArray) Constructs aSectionCompositecontaining the providedAllocSectionDecoratorSegmentelements and using the provided factories for creatingSegmentandSectioninstances. -
SectionComposite
Constructs aSectionComposite. Instances for theSegmentandSectionelements are created using the providedClassinstances. -
SectionComposite
@SafeVarargs public SectionComposite(Class<ALLOC> aAllocSegmentClass, Class<CHILD> aSegmentClass, CHILD... aSegmentArray) Constructs aSectionCompositecontaining the providedAllocSectionDecoratorSegmentelements. Instances for theSegmentandSectionelements are created using the providedClassinstances.
-
-
Method Details
-
toSequence
Provides theSequencerepresentation of thisTransmission. In case of nestedTransmissioninstances, allSequencerepresentations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nestedTransmissioninstances) may be backed by the returnedSequence.- Specified by:
toSequencein interfaceTransmission- Specified by:
toSequencein interfaceTransmissionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>>- Returns:
- The according instance's
Sequence.
-
reset
public void reset()Resets any dynamic data (e.g. values such as payloads or checksums) and must not(!) reset any configurations or settings required to produce the dynamic data (e.g. theTransmissionMetrics).- Specified by:
resetin interfaceorg.refcodes.mixin.Resetable- Specified by:
resetin interfaceTransmission
-
toSchema
- Specified by:
toSchemain interfaceorg.refcodes.schema.Schemable- Specified by:
toSchemain interfaceTransmission- Specified by:
toSchemain interfaceTransmissionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>>
-
getLength
public int getLength()Determines the overall length of thisTransmission. In case of nestedTransmissioninstances, all length values from all sub-segments are accumulated to the result as well.- Specified by:
getLengthin interfaceorg.refcodes.mixin.LengthAccessor- Specified by:
getLengthin interfaceTransmission- Specified by:
getLengthin interfaceTransmissionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>>- Returns:
- The (overall) length of the
Transmission(including any sub-segments).
-
getChildren
- Specified by:
getChildrenin interfaceorg.refcodes.mixin.ChildrenAccessor<ALLOC extends AllocSectionDecoratorSegment<CHILD>>
-
fromTransmission
public void fromTransmission(Sequence aSequence, int aOffset, int aLength) throws TransmissionException (Re-)initializes this instance with the the givenSequencedata.- Specified by:
fromTransmissionin interfaceSection- Parameters:
aSequence- TheSequencedata 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 givenSequencecannot be processed.
-
receiveFrom
public void receiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream) throws IOException (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 interfaceSection- Specified by:
receiveFromin interfaceSection.SectionMixin- Parameters:
aInputStream- TheInputStreamfrom which to read the instance's (re-)initializationSequencefrom.aLength- The length of data assigned by the byte array.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 givenInputStreambytes cannot be processed.
-
setChildren
Hook for easily setting the children.- Parameters:
aChildren- The children to be set.
-