Class ReplayToken
java.lang.Object
org.axonframework.messaging.eventhandling.processing.streaming.token.ReplayToken
- All Implemented Interfaces:
TrackingToken,WrappedToken
Token keeping track of the position before a reset was triggered. This allows for downstream components to detect
messages that are redelivered as part of a replay.
- Since:
- 3.2
- Author:
- Allard Buijze
-
Field Summary
Fields inherited from interface org.axonframework.messaging.eventhandling.processing.streaming.token.TrackingToken
FIRST, LATEST, RESOURCE_KEY -
Method Summary
Modifier and TypeMethodDescriptionadvancedTo(TrackingToken newToken) Advance this token to the givennewToken.context()Returns the context that was provided when the token was reset.booleancovers(TrackingToken other) Indicates whether this token covers theothertoken completely.static TrackingTokencreateReplayToken(TrackingToken tokenAtReset) Creates a new TrackingToken that represents the tail of the stream.static TrackingTokencreateReplayToken(TrackingToken tokenAtReset, TrackingToken startPosition) Creates a new TrackingToken that represents the givenstartPositionof a stream.static TrackingTokencreateReplayToken(TrackingToken tokenAtReset, TrackingToken startPosition, Object resetContext) Creates a new TrackingToken that represents the givenstartPositionof a stream.booleanGets the current token.Gets the token representing the position at which the reset was triggered.static OptionalLonggetTokenAtReset(TrackingToken trackingToken) Return the relative position at which a reset was triggered for this Segment.inthashCode()static booleanisReplay(TrackingToken trackingToken) Indicates whether the giventrackingTokenrepresents a position that is part of a replay.Returns the token representing the current position in the stream.lowerBound(TrackingToken other) Returns a token that represents the lower bound between this and theothertoken.position()Return the estimated relative position this token represents.static <T> Optional<T> replayContext(TrackingToken trackingToken, Class<T> contextClass) Extracts the context from amessageof the matchingcontextClass.booleansamePositionAs(TrackingToken other) Indicates whetherthistoken is at the exact same spot in the event stream as theothertoken.toString()<R extends TrackingToken>
Optional<R> Retrieve a token of giventokenTypeif it is wrapped by this token.Returns the token representing the furthest position in the stream described by this token.upperBound(TrackingToken other) Returns the token that represents the furthest possible position in a stream that either this token or the givenotherrepresents.
-
Method Details
-
createReplayToken
public static TrackingToken createReplayToken(TrackingToken tokenAtReset, @Nullable TrackingToken startPosition) Creates a new TrackingToken that represents the givenstartPositionof a stream. It will be in replay state until the position of the providedtokenAtReset. After that, thetokenAtResetwill become the active token and the stream will no longer be considered as replaying.- Parameters:
tokenAtReset- The token present when the reset was triggeredstartPosition- The position where the token should be reset to and start replaying from- Returns:
- A token that represents a reset to the
startPositionuntil the providedtokenAtReset
-
createReplayToken
public static TrackingToken createReplayToken(TrackingToken tokenAtReset, TrackingToken startPosition, Object resetContext) Creates a new TrackingToken that represents the givenstartPositionof a stream. It will be in replay state until the position of the providedtokenAtReset. After that, thetokenAtResetwill become the active token and the stream will no longer be considered as replaying.- Parameters:
tokenAtReset- The token present when the reset was triggeredstartPosition- The position where the token should be reset to and start replaying fromresetContext- The context given to the reset, may be null- Returns:
- A token that represents a reset to the
startPositionuntil the providedtokenAtReset
-
createReplayToken
Creates a new TrackingToken that represents the tail of the stream. It will be in replay state until the position of the providedtokenAtReset. After that, thetokenAtResetwill become the active token and the stream will no longer be considered as replaying.- Parameters:
tokenAtReset- The token present when the reset was triggered- Returns:
- A token that represents a reset to the tail of the stream
-
isReplay
Indicates whether the giventrackingTokenrepresents a position that is part of a replay.- Parameters:
trackingToken- The token to verify- Returns:
trueif the token indicates a replay
-
replayContext
public static <T> Optional<T> replayContext(TrackingToken trackingToken, @Nonnull Class<T> contextClass) Extracts the context from amessageof the matchingcontextClass.Will resolve to an empty
Optionalif the provided token is not aReplayToken, or the context isn't an instance of the providedcontextClass, or there is no context at all.- Type Parameters:
T- The type of the context- Parameters:
trackingToken- The tracking token to extract the context fromcontextClass- The class the context should match- Returns:
- The context, if present in the token
-
getTokenAtReset
Return the relative position at which a reset was triggered for this Segment. In case a replay finished or no replay is active, anOptionalLong.empty()will be returned.- Returns:
- the relative position at which a reset was triggered for this token
-
getTokenAtReset
Gets the token representing the position at which the reset was triggered.- Returns:
- the token representing the position at which the reset was triggered
-
getCurrentToken
Gets the current token.- Returns:
- the current token
-
advancedTo
Description copied from interface:WrappedTokenAdvance this token to the givennewToken.- Specified by:
advancedToin interfaceWrappedToken- Parameters:
newToken- The token representing the position to advance to- Returns:
- a token representing the new position
-
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:
-
lowerBound
Description copied from interface:WrappedTokenReturns the token representing the current position in the stream.- Specified by:
lowerBoundin interfaceWrappedToken- Returns:
- the token representing the current position in the stream
-
upperBound
Description copied from interface:WrappedTokenReturns the token representing the furthest position in the stream described by this token. This is usually a position that has been (partially) processed before.- Specified by:
upperBoundin interfaceWrappedToken- Returns:
- the token representing the furthest position reached in the stream
-
unwrap
Description copied from interface:WrappedTokenRetrieve a token of giventokenTypeif it is wrapped by this token.- Specified by:
unwrapin interfaceWrappedToken- Type Parameters:
R- The generic type of the token to unwrap to- Parameters:
tokenType- The type of token to unwrap to- Returns:
- an optional with the unwrapped token, if found
-
context
Returns the context that was provided when the token was reset.- Returns:
- The context, null if none was provided during reset.
-
equals
-
hashCode
public int hashCode() -
toString
-
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
-