Class MultiSourceTrackingToken

java.lang.Object
org.axonframework.messaging.eventstreaming.MultiSourceTrackingToken
All Implemented Interfaces:
TrackingToken

public class MultiSourceTrackingToken extends Object implements TrackingToken
A TrackingToken implementation combining several TrackingTokens into one. Used to keep track of several event sources at once, like the MultiStreamableEventSource.
Since:
4.2
Author:
Greg Woods
  • Constructor Details

    • MultiSourceTrackingToken

      @ConstructorProperties("trackingTokens") public MultiSourceTrackingToken(Map<String,TrackingToken> trackingTokens)
      Construct a new MultiSourceTrackingToken from a map of existing tokens.
      Parameters:
      trackingTokens - the map of tokens which make up the MultiSourceTrackingToken
  • Method Details

    • lowerBound

      public TrackingToken lowerBound(TrackingToken other)
      Compares this token to other by comparing each member token with its counterpart in the other token. If the two tokens contain different number of constituent tokens, or have the same number but different names, then these two MultiSourceTrackingTokens must be tracking different MultiStreamableEventSources.
      Specified by:
      lowerBound in interface TrackingToken
      Parameters:
      other - The token to compare to this one
      Returns:
      token representing the lower bound of both tokens
    • upperBound

      public MultiSourceTrackingToken upperBound(TrackingToken other)
      Compares this token to other by comparing each member token with its counterpart in the other token. If the two tokens contain different number of constituent tokens, or have the same number but different names, then these two MultiSourceTrackingTokens must be tracking different MultiStreamableEventSources.
      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 streams
    • covers

      public boolean covers(TrackingToken other)
      Compares this token to other checking each member token with its counterpart to see if they are covered in the other token. If the two tokens contain different number of constituent tokens, or have the same number but different names, then these two MultiSourceTrackingTokens must be tracking different MultiStreamableEventSources.
      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:
    • advancedTo

      public MultiSourceTrackingToken advancedTo(String streamName, TrackingToken newTokenForStream)
      Advances a single token within the tokenMap
      Parameters:
      streamName - the stream/source which is being advanced
      newTokenForStream - the token representing the new position of the stream
      Returns:
      the token representing the current processing position of all streams.
    • getTokenForStream

      public TrackingToken getTokenForStream(String streamName)
      Return the tracking token for an individual stream
      Parameters:
      streamName - the name of the stream for the tracking token
      Returns:
      the tracking token for the stream
    • getTrackingTokens

      public Map<String,TrackingToken> getTrackingTokens()
      Returns the map containing the constituent tokens.
      Returns:
      the map containing the constituent tokens.
    • position

      public OptionalLong position()
      Returns the sum of all positions of the constituent tracking tokens.
      Specified by:
      position in interface TrackingToken
      Returns:
      Sum of all positions of the constituent tracking tokens.
    • 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