Package org.axonframework.eventhandling
Class Segment
java.lang.Object
org.axonframework.eventhandling.Segment
- All Implemented Interfaces:
Comparable<Segment>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SegmentRepresents the Segment that matches against all input, but can be split to start processing elements in parallel. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSegment(int segmentId, int mask) Construct a new Segment instance with givensegmentIdandmask -
Method Summary
Modifier and TypeMethodDescriptionintstatic SegmentcomputeSegment(int segmentId, int... availableSegmentIds) Creates a Segment instance for the givensegmentIdbased on the givenavailableSegmentsIds.static Segment[]computeSegments(int... segments) Compute theSegment's from a given list of segmentId's.booleanintgetMask()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
-
ROOT_SEGMENT
Represents the Segment that matches against all input, but can be split to start processing elements in parallel.
-
-
Constructor Details
-
Segment
protected Segment(int segmentId, int mask) Construct a new Segment instance with givensegmentIdandmask- Parameters:
segmentId- The id of the segmentmask- The mask of the segment
-
-
Method Details
-
computeSegments
Compute theSegment's from a given list of segmentId's.- Parameters:
segments- The segment id's for which to compute Segments.- Returns:
- an array of computed
Segment
-
computeSegment
Creates a Segment instance for the givensegmentIdbased on the givenavailableSegmentsIds.- Parameters:
segmentId- The Id of the segment to returnavailableSegmentIds- The available segment Ids, to base the mask of the segment on- Returns:
- the Segment instance representing for the given id
-
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>
-