All Known Subinterfaces:
WrappedToken
All Known Implementing Classes:
ConfigToken, GapAwareTrackingToken, GlobalSequenceTrackingToken, MergedTrackingToken, ReplayToken

public interface TrackingToken
Tag interface identifying a token that is used to identify the position of an event in an event stream. Event processors use this token to keep track of the events they have processed and still need to process.
Since:
3.0.0
Author:
Rene de Waele
  • Field Details

  • Method Details

    • addToContext

      static Context addToContext(Context context, TrackingToken token)
      Adds the given token to the given context using the RESOURCE_KEY.
      Parameters:
      context - The Context to add the given token to.
      token - The {TrackingToken} to add to the given context using the RESOURCE_KEY.
      Returns:
      The resulting context.
    • fromContext

      static Optional<TrackingToken> fromContext(Context context)
      Returns an Optional of {TrackingToken}, returning the resource keyed under the RESOURCE_KEY in the given context.
      Parameters:
      context - The Context to retrieve the TrackingToken from, if present.
      Returns:
      An Optional of {TrackingToken}, returning the resource keyed under the RESOURCE_KEY in the given context.
    • lowerBound

      TrackingToken lowerBound(TrackingToken other)
      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.
      Parameters:
      other - The token to compare to this one
      Returns:
      The token representing the lower bound of the two
    • upperBound

      TrackingToken upperBound(TrackingToken other)
      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.
      Parameters:
      other - The token to compare this token to
      Returns:
      a token that represents the furthest position of this or the other stream
    • covers

      boolean covers(TrackingToken other)
      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.

      Parameters:
      other - The token to compare to this one
      Returns:
      true if this token covers the other, otherwise false
    • position

      default OptionalLong position()
      Return the estimated relative position this token represents. In case no estimation can be given an OptionalLong.empty() will be returned.
      Returns:
      the estimated relative position of this token
    • samePositionAs

      default boolean samePositionAs(TrackingToken other)
      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.

      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.
      Since:
      4.12.3
      See Also: