Class MergedTrackingToken
java.lang.Object
org.axonframework.messaging.eventhandling.processing.streaming.token.MergedTrackingToken
- All Implemented Interfaces:
TrackingToken,WrappedToken
Special Wrapped Token implementation that keeps track of two separate tokens, of which the streams have been merged
into a single one. This token keeps track of the progress of the two original "halves", by advancing each
individually, until both halves represent the same position.
- Since:
- 4.1
- Author:
- Allard Buijze
-
Field Summary
Fields inherited from interface org.axonframework.messaging.eventhandling.processing.streaming.token.TrackingToken
FIRST, LATEST, RESOURCE_KEY -
Constructor Summary
ConstructorsModifierConstructorDescriptionMergedTrackingToken(TrackingToken lowerSegmentToken, TrackingToken upperSegmentToken) Initialize a Merged Token, with thelowerSegmentTokenrepresenting the progress of the segment with the lower segmentId, andupperSegmentTokenrepresenting the progress of the segment with the higher segmentId.protectedMergedTrackingToken(TrackingToken lowerSegmentToken, TrackingToken upperSegmentToken, boolean lowerSegmentAdvanced, boolean upperSegmentAdvanced) Initialize a Merged Token, with thelowerSegmentTokenrepresenting the progress of the segment with the lower segmentId, andupperSegmentTokenrepresenting the progress of the segment with the higher segmentId, additionally indicating if either of these segments were advanced by the latest call toadvancedTo(TrackingToken) -
Method Summary
Modifier and TypeMethodDescriptionadvancedTo(TrackingToken newToken) Advance this token to the givennewToken.booleancovers(TrackingToken other) Indicates whether this token covers theothertoken completely.booleaninthashCode()booleanIndicates whether the last call toadvancedTo(TrackingToken)caused the lower segment to advancestatic booleanisMergeInProgress(TrackingToken trackingToken) Indicates whether the giventrackingTokenrepresents a token that is part of a merge.booleanIndicates whether the last call toadvancedTo(TrackingToken)caused the upper segment to advanceReturns the token representing the current position in the stream.lowerBound(TrackingToken other) Returns a token that represents the lower bound between this and theothertoken.Returns the token indicating the progress of the lower half (the half with the lower segmentId) of the merged segment represented by this tokenstatic TrackingTokenmerged(TrackingToken lowerSegmentToken, TrackingToken upperSegmentToken) Create a merged token using the givenlowerSegmentTokenandupperSegmentToken.static OptionalLongmergePosition(TrackingToken trackingToken) Return the estimated relative token position this Segment will have after a merge operation is complete.position()Return the estimated relative position this token represents.booleansamePositionAs(TrackingToken other) Indicates whetherthistoken is at the exact same spot in the event stream as theothertoken.toString()<R extends TrackingToken>
Optional<R> Retrieve a token of giventokenTypeif it is wrapped by this token.Returns the token representing the furthest position in the stream described by this token.upperBound(TrackingToken other) Returns the token that represents the furthest possible position in a stream that either this token or the givenotherrepresents.Returns the token indicating the progress of the upper half (the half with the higher segmentId) of the merged segment represented by this token
-
Constructor Details
-
MergedTrackingToken
@ConstructorProperties({"lowerSegmentToken","upperSegmentToken"}) public MergedTrackingToken(TrackingToken lowerSegmentToken, TrackingToken upperSegmentToken) Initialize a Merged Token, with thelowerSegmentTokenrepresenting the progress of the segment with the lower segmentId, andupperSegmentTokenrepresenting the progress of the segment with the higher segmentId.- Parameters:
lowerSegmentToken- the token of the half with the lower segment IDupperSegmentToken- the token of the half with the higher segment ID
-
MergedTrackingToken
protected MergedTrackingToken(TrackingToken lowerSegmentToken, TrackingToken upperSegmentToken, boolean lowerSegmentAdvanced, boolean upperSegmentAdvanced) Initialize a Merged Token, with thelowerSegmentTokenrepresenting the progress of the segment with the lower segmentId, andupperSegmentTokenrepresenting the progress of the segment with the higher segmentId, additionally indicating if either of these segments were advanced by the latest call toadvancedTo(TrackingToken)- Parameters:
lowerSegmentToken- the token of the half with the lower segment IDupperSegmentToken- the token of the half with the higher segment IDlowerSegmentAdvanced- whether the lower segment advanced in the last callupperSegmentAdvanced- whether the upper segment advanced in the last call
-
-
Method Details
-
merged
public static TrackingToken merged(TrackingToken lowerSegmentToken, TrackingToken upperSegmentToken) Create a merged token using the givenlowerSegmentTokenandupperSegmentToken.- Parameters:
lowerSegmentToken- the token of the half with the lower segment IDupperSegmentToken- the token of the half with the higher segment ID- Returns:
- a token representing the position of the merger of both tokens
-
isMergeInProgress
Indicates whether the giventrackingTokenrepresents a token that is part of a merge.- Parameters:
trackingToken- the token to verify- Returns:
trueif the token indicates a merge
-
mergePosition
Return the estimated relative token position this Segment will have after a merge operation is complete. In case no estimation can be given or no merge in progress, anOptionalLong.empty()will be returned.- Returns:
- the estimated relative position this Segment will reach after a merge operation is complete.
-
lowerBound
Description copied from interface:TrackingTokenReturns a token that represents the lower bound between this and theothertoken. Effectively, the returned token will cause events not received by both this and theothertoken to be redelivered.- Specified by:
lowerBoundin interfaceTrackingToken- Parameters:
other- The token to compare to this one- Returns:
- The token representing the lower bound of the two
-
position
Description copied from interface:TrackingTokenReturn the estimated relative position this token represents. In case no estimation can be given anOptionalLong.empty()will be returned.- Specified by:
positionin interfaceTrackingToken- Returns:
- the estimated relative position of this token
-
upperBound
Description copied from interface:TrackingTokenReturns the token that represents the furthest possible position in a stream that either this token or the givenotherrepresents. Effectively, this means this token will only deliver events that neither this, nor the other have been received.- Specified by:
upperBoundin interfaceTrackingToken- Parameters:
other- The token to compare this token to- Returns:
- a token that represents the furthest position of this or the other stream
-
covers
Description copied from interface:TrackingTokenIndicates whether this token covers theothertoken completely. That means that this token represents a position in a stream that has received all the events that a stream represented by theothertoken has received.Note that this operation is only safe when comparing tokens obtained from events from the same
StreamableEventSource.- Specified by:
coversin interfaceTrackingToken- Parameters:
other- The token to compare to this one- Returns:
trueif this token covers the other, otherwisefalse
-
samePositionAs
Description copied from interface:TrackingTokenIndicates whetherthistoken is at the exact same spot in the event stream as theothertoken.This method is particularly useful when comparing tokens from different points in time, such as during replay detection, where token implementations may naturally differ.
By default, this method checks bidirectional coverage:
this.covers(other) && other.covers(this), which ensures both tokens are at the same position.- Specified by:
samePositionAsin interfaceTrackingToken- Parameters:
other- The token to validate againstthistoken.- Returns:
trueif this token is at the same location as the other token, otherwisefalse. Returnsfalseifotherisnull.- See Also:
-
advancedTo
Description copied from interface:WrappedTokenAdvance this token to the givennewToken.- Specified by:
advancedToin interfaceWrappedToken- Parameters:
newToken- The token representing the position to advance to- Returns:
- a token representing the new position
-
unwrap
Description copied from interface:WrappedTokenRetrieve a token of giventokenTypeif it is wrapped by this token.- Specified by:
unwrapin interfaceWrappedToken- Type Parameters:
R- The generic type of the token to unwrap to- Parameters:
tokenType- The type of token to unwrap to- Returns:
- an optional with the unwrapped token, if found
-
lowerBound
Description copied from interface:WrappedTokenReturns the token representing the current position in the stream.- Specified by:
lowerBoundin interfaceWrappedToken- Returns:
- the token representing the current position in the stream
-
upperBound
Description copied from interface:WrappedTokenReturns the token representing the furthest position in the stream described by this token. This is usually a position that has been (partially) processed before.- Specified by:
upperBoundin interfaceWrappedToken- Returns:
- the token representing the furthest position reached in the stream
-
lowerSegmentToken
Returns the token indicating the progress of the lower half (the half with the lower segmentId) of the merged segment represented by this token- Returns:
- the token indicating the progress of the lower half of the merged segment
-
upperSegmentToken
Returns the token indicating the progress of the upper half (the half with the higher segmentId) of the merged segment represented by this token- Returns:
- the token indicating the progress of the upper half of the merged segment
-
isLowerSegmentAdvanced
public boolean isLowerSegmentAdvanced()Indicates whether the last call toadvancedTo(TrackingToken)caused the lower segment to advance- Returns:
- true if the last advancement moved the lower segment
-
isUpperSegmentAdvanced
public boolean isUpperSegmentAdvanced()Indicates whether the last call toadvancedTo(TrackingToken)caused the upper segment to advance- Returns:
- true if the last advancement moved the upper segment
-
equals
-
hashCode
public int hashCode() -
toString
-