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
  • Constructor Details

    • GlobalSequenceTrackingToken

      @ConstructorProperties("globalIndex") public GlobalSequenceTrackingToken(long globalIndex)
      Initializes a GlobalSequenceTrackingToken from the given globalIndex of 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

      public GlobalSequenceTrackingToken offsetBy(int offset)
      Returns a new GlobalSequenceTrackingToken instance that is the sum of this token's sequence number and the given offset.
      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 new GlobalSequenceTrackingToken instance with sequence number incremented by 1.
      Returns:
      a new tracking token with sequence number incremented by 1
    • lowerBound

      public TrackingToken lowerBound(TrackingToken other)
      Description copied from interface: TrackingToken
      Returns a token that represents the lower bound between this and the other token. Effectively, the returned token will cause events not received by both this and the other token to be redelivered.
      Specified by:
      lowerBound in interface TrackingToken
      Parameters:
      other - The token to compare to this one
      Returns:
      The token representing the lower bound of the two
    • upperBound

      public TrackingToken upperBound(TrackingToken other)
      Description copied from interface: TrackingToken
      Returns the token that represents the furthest possible position in a stream that either this token or the given other represents. Effectively, this means this token will only deliver events that neither this, nor the other have been received.
      Specified by:
      upperBound in interface TrackingToken
      Parameters:
      other - The token to compare this token to
      Returns:
      a token that represents the furthest position of this or the other stream
    • covers

      public boolean covers(TrackingToken other)
      Description copied from interface: TrackingToken
      Indicates whether this token covers the other token completely. That means that this token represents a position in a stream that has received all the events that a stream represented by the other token has received.

      Note that this operation is only safe when comparing tokens obtained from events from the same StreamableEventSource.

      Specified by:
      covers in interface TrackingToken
      Parameters:
      other - The token to compare to this one
      Returns:
      true if this token covers the other, otherwise false
    • samePositionAs

      public boolean samePositionAs(TrackingToken other)
      Description copied from interface: TrackingToken
      Indicates whether this token is at the exact same spot in the event stream as the other token.

      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:
      samePositionAs in interface TrackingToken
      Parameters:
      other - The token to validate against this token.
      Returns:
      true if this token is at the same location as the other token, otherwise false. Returns false if other is null.
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(GlobalSequenceTrackingToken o)
      Specified by:
      compareTo in interface Comparable<GlobalSequenceTrackingToken>
    • position

      public OptionalLong position()
      Description copied from interface: TrackingToken
      Return the estimated relative position this token represents. In case no estimation can be given an OptionalLong.empty() will be returned.
      Specified by:
      position in interface TrackingToken
      Returns:
      the estimated relative position of this token