Class Segment
java.lang.Object
org.axonframework.messaging.eventhandling.processing.streaming.segmenting.Segment
- All Implemented Interfaces:
Comparable<Segment>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Context.ResourceKey<Segment> The Context.ResourceKey used whenever a Context would contain a segment id.static final SegmentRepresents the Segment that matches against all input, but can be split to start processing elements in parallel. -
Constructor Summary
ConstructorsConstructorDescriptionSegment(int segmentId, int mask) Construct a new Segment instance with givensegmentIdandmask -
Method Summary
Modifier and TypeMethodDescriptionstatic ContextaddToContext(Context context, Segment segment) intbooleanfromContext(Context context) Returns anOptionalofSegment, returning the resource keyed under theRESOURCE_KEYin the givencontext.intgetMask()Getter for the segment mask.intGetter for the segment identifier.inthashCode()booleanisMergeableWith(Segment other) Indicates whether this segment can be merged with the givenothersegment.booleanmatches(int value) Returnstruewhen the mask applied to the given value, matches the segment id.booleanIndicates whether the givenvaluematches this segment.intReturns thesegmentIdof the segment this one can be merged withmergedWith(Segment other) Calculates the Segment that represents the merger of this segment with the givenothersegment.Segment[]split()Returns an array with twosegments with a corresponding mask.
The first entry contains the originalsegmentId, with the newly calculated mask.splitBalanced(Segment segment, int numberOfTimes) Split a givenSegmentn-times in round robin fashion.intReturns the segmentId of the counterpart of this segment, if this segment were to be split.toString()
-
Field Details
-
RESOURCE_KEY
The Context.ResourceKey used whenever a Context would contain a segment id. -
ROOT_SEGMENT
Represents the Segment that matches against all input, but can be split to start processing elements in parallel.
-
-
Constructor Details
-
Segment
Construct a new Segment instance with givensegmentIdandmask- Parameters:
segmentId- The id of the segmentmask- The mask of the segment
-
-
Method Details
-
addToContext
- Parameters:
context- TheContextto add the giventokento.segment- TheSegmentto add to the givencontextusing theRESOURCE_KEY.
-
fromContext
Returns anOptionalofSegment, returning the resource keyed under theRESOURCE_KEYin the givencontext.- Parameters:
context- TheContextto retrieve theSegmentfrom, if present.- Returns:
- An
OptionalofSegment, returning the resource keyed under theRESOURCE_KEYin the givencontext.
-
splitBalanced
Split a givenSegmentn-times in round robin fashion. -
mergedWith
Calculates the Segment that represents the merger of this segment with the givenothersegment.- Parameters:
other- the segment to merge this one with- Returns:
- The Segment representing the merged segments
-
mergeableSegmentId
public int mergeableSegmentId()Returns thesegmentIdof the segment this one can be merged with- Returns:
- the
segmentIdof the segment this one can be merged with
-
isMergeableWith
Indicates whether this segment can be merged with the givenothersegment.Two segments can be merged when their mask is identical, and the only difference in SegmentID is in the first 1-bit of their mask.
- Parameters:
other- the Segment to verify mergeability for- Returns:
trueif the segments can be merged, otherwisefalse
-
getSegmentId
public int getSegmentId()Getter for the segment identifier.- Returns:
- the Segment identifier.
-
getMask
public int getMask()Getter for the segment mask.- Returns:
- the Segment mask.
-
matches
public boolean matches(int value) Returnstruewhen the mask applied to the given value, matches the segment id.- Parameters:
value- The value to be tested.- Returns:
truewhen matching this segment.
-
matches
Indicates whether the givenvaluematches this segment. A value matches when the hashCode of a value, after applying this segments mask, equals to this segment ID.- Parameters:
value- The value to verify against.- Returns:
trueif the given value matches this segment, otherwisefalse
-
split
Returns an array with twosegments with a corresponding mask.
The first entry contains the originalsegmentId, with the newly calculated mask. (Simple left shift, adding a '1' as LSB). The 2nd entry is a newsegmentIdwith the same derived mask.Callers must ensure that either the two returned Segments are used, or the instance from which they are derived, but not both.
- Returns:
- an array of two
Segment's.
-
splitSegmentId
public int splitSegmentId()Returns the segmentId of the counterpart of this segment, if this segment were to be split.- Returns:
- the segmentId of the counterpart of this segment
-
equals
-
toString
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<Segment>
-