Interface TrackingToken
- 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final TrackingTokenA specialTrackingTokenthat indicates the very beginning of an event stream.static final TrackingTokenA specialTrackingTokenthat represents the latest (tail) position in an event stream.static final Context.ResourceKey<TrackingToken> -
Method Summary
Modifier and TypeMethodDescriptionstatic ContextaddToContext(Context context, TrackingToken token) booleancovers(TrackingToken other) Indicates whether this token covers theothertoken completely.static Optional<TrackingToken> fromContext(Context context) Returns anOptionalof {TrackingToken}, returning the resource keyed under theRESOURCE_KEYin the givencontext.lowerBound(TrackingToken other) Returns a token that represents the lower bound between this and theothertoken.default OptionalLongposition()Return the estimated relative position this token represents.default booleansamePositionAs(TrackingToken other) Indicates whetherthistoken is at the exact same spot in the event stream as theothertoken.upperBound(TrackingToken other) Returns the token that represents the furthest possible position in a stream that either this token or the givenotherrepresents.
-
Field Details
-
RESOURCE_KEY
-
FIRST
A specialTrackingTokenthat indicates the very beginning of an event stream.Used to explicitly represent the first position in a stream instead of using
null. -
LATEST
A specialTrackingTokenthat represents the latest (tail) position in an event stream.This can be used to indicate that a processor wants to start at the newest available event, skipping historical events.
-
-
Method Details
-
addToContext
- Parameters:
context- TheContextto add the giventokento.token- The {TrackingToken} to add to the givencontextusing theRESOURCE_KEY.- Returns:
- The resulting context.
-
fromContext
Returns anOptionalof {TrackingToken}, returning the resource keyed under theRESOURCE_KEYin the givencontext.- Parameters:
context- TheContextto retrieve theTrackingTokenfrom, if present.- Returns:
- An
Optionalof {TrackingToken}, returning the resource keyed under theRESOURCE_KEYin the givencontext.
-
lowerBound
Returns 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.- Parameters:
other- The token to compare to this one- Returns:
- The token representing the lower bound of the two
-
upperBound
Returns 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.- Parameters:
other- The token to compare this token to- Returns:
- a token that represents the furthest position of this or the other stream
-
covers
Indicates 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.- Parameters:
other- The token to compare to this one- Returns:
trueif this token covers the other, otherwisefalse
-
position
Return the estimated relative position this token represents. In case no estimation can be given anOptionalLong.empty()will be returned.- Returns:
- the estimated relative position of this token
-
samePositionAs
Indicates 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.- Parameters:
other- The token to validate againstthistoken.- Returns:
trueif this token is at the same location as the other token, otherwisefalse. Returnsfalseifotherisnull.- Since:
- 4.12.3
- See Also:
-