Class GlobalSequenceTrackingToken
java.lang.Object
org.axonframework.messaging.eventhandling.processing.streaming.token.GlobalSequenceTrackingToken
- All Implemented Interfaces:
Comparable<GlobalSequenceTrackingToken>,TrackingToken
public class GlobalSequenceTrackingToken
extends Object
implements TrackingToken, Comparable<GlobalSequenceTrackingToken>
Tracking token based on the global sequence number of an event.
- Since:
- 3.0
- Author:
- Rene de Waele
-
Field Summary
Fields inherited from interface org.axonframework.messaging.eventhandling.processing.streaming.token.TrackingToken
FIRST, LATEST, RESOURCE_KEY -
Constructor Summary
ConstructorsConstructorDescriptionGlobalSequenceTrackingToken(long globalIndex) Initializes aGlobalSequenceTrackingTokenfrom the givenglobalIndexof the event. -
Method Summary
Modifier and TypeMethodDescriptionintbooleancovers(TrackingToken other) Indicates whether this token covers theothertoken completely.booleanlongGet the global sequence number of the eventinthashCode()lowerBound(TrackingToken other) Returns a token that represents the lower bound between this and theothertoken.next()Returns a newGlobalSequenceTrackingTokeninstance with sequence number incremented by 1.offsetBy(int offset) Returns a newGlobalSequenceTrackingTokeninstance that is the sum of this token's sequence number and the givenoffset.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()upperBound(TrackingToken other) Returns the token that represents the furthest possible position in a stream that either this token or the givenotherrepresents.
-
Constructor Details
-
GlobalSequenceTrackingToken
Initializes aGlobalSequenceTrackingTokenfrom the givenglobalIndexof the event.- Parameters:
globalIndex- the global sequence number of the event
-
-
Method Details
-
getGlobalIndex
public long getGlobalIndex()Get the global sequence number of the event- Returns:
- the global sequence number of the event
-
offsetBy
Returns a newGlobalSequenceTrackingTokeninstance that is the sum of this token's sequence number and the givenoffset.- Parameters:
offset- the offset between this token's sequence number of that of the returned instance- Returns:
- a new tracking token with global sequence increased with the given offset
-
next
Returns a newGlobalSequenceTrackingTokeninstance with sequence number incremented by 1.- Returns:
- a new tracking token with sequence number incremented by 1
-
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
-
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:
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<GlobalSequenceTrackingToken>
-
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
-