public class ReplayToken extends Object implements TrackingToken, WrappedToken, Serializable
| Constructor and Description |
|---|
ReplayToken(TrackingToken tokenAtReset)
Deprecated.
Use the
createReplayToken(TrackingToken) method instead. |
ReplayToken(TrackingToken tokenAtReset,
TrackingToken newRedeliveryToken)
Deprecated.
Use the
createReplayToken(TrackingToken, TrackingToken) method instead. |
| Modifier and Type | Method and Description |
|---|---|
TrackingToken |
advancedTo(TrackingToken newToken)
Advance this token to the given
newToken. |
Object |
context()
Returns the context that was provided when the token was reset.
|
boolean |
covers(TrackingToken other)
Indicates whether this token covers the
other token completely. |
static TrackingToken |
createReplayToken(TrackingToken tokenAtReset)
Creates a new TrackingToken that represents the tail of the stream.
|
static TrackingToken |
createReplayToken(TrackingToken tokenAtReset,
TrackingToken startPosition)
Creates a new TrackingToken that represents the given
startPosition of a stream. |
static TrackingToken |
createReplayToken(TrackingToken tokenAtReset,
TrackingToken startPosition,
Object resetContext)
Creates a new TrackingToken that represents the given
startPosition of a stream. |
boolean |
equals(Object o) |
TrackingToken |
getCurrentToken()
Gets the current token.
|
TrackingToken |
getTokenAtReset()
Gets the token representing the position at which the reset was triggered.
|
static OptionalLong |
getTokenAtReset(TrackingToken trackingToken)
Return the relative position at which a reset was triggered for this Segment.
|
int |
hashCode() |
static boolean |
isReplay(Message<?> message)
Indicates whether the given message is "redelivered", as a result of a previous reset.
|
static boolean |
isReplay(TrackingToken trackingToken)
Indicates whether the given
trackingToken represents a position that is part of a replay. |
TrackingToken |
lowerBound()
Returns the token representing the current position in the stream.
|
TrackingToken |
lowerBound(TrackingToken other)
Returns a token that represents the lower bound between this and the
other token. |
OptionalLong |
position()
Return the estimated relative position this token represents.
|
static <T> Optional<T> |
replayContext(EventMessage<?> message,
Class<T> contextClass)
Extracts the context from a
message of the matching contextClass. |
static <T> Optional<T> |
replayContext(TrackingToken trackingToken,
Class<T> contextClass)
Extracts the context from a
message of the matching contextClass. |
String |
toString() |
<R extends TrackingToken> |
unwrap(Class<R> tokenType)
Retrieve a token of given
tokenType if it is wrapped by this token. |
TrackingToken |
upperBound()
Returns the token representing the furthest position in the stream described by this token.
|
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. |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitadvance, unwrap, unwrapLowerBound, unwrapUpperBound@Deprecated public ReplayToken(TrackingToken tokenAtReset)
createReplayToken(TrackingToken) method instead.tokenAtReset to represent the position at which a reset was
triggered. The current token is reset to the initial position.
Using the createReplayToken(TrackingToken) is preferred, as it executes sanity checks on the
parameters.
tokenAtReset - The token representing the position at which the reset was triggered.@Deprecated public ReplayToken(TrackingToken tokenAtReset, TrackingToken newRedeliveryToken)
createReplayToken(TrackingToken, TrackingToken) method instead.tokenAtReset which represents the position at which a reset was triggered
and the newRedeliveryToken which represents current token.
Using the createReplayToken(TrackingToken, TrackingToken) is preferred, as it executes sanity checks on
the parameters.
tokenAtReset - The token representing the position at which the reset was triggerednewRedeliveryToken - The current tokenpublic static boolean isReplay(Message<?> message)
true, this
means this message has been delivered to this processor before its token was reset.message - The message to inspecttrue if the message is a replaypublic static TrackingToken createReplayToken(TrackingToken tokenAtReset, @Nullable TrackingToken startPosition)
startPosition of a stream. It will be in replay
state until the position of the provided tokenAtReset. After that, the tokenAtReset will become
the active token and the stream will no longer be considered as replaying.tokenAtReset - The token present when the reset was triggeredstartPosition - The position where the token should be reset to and start replaying fromstartPosition until the provided tokenAtResetpublic static TrackingToken createReplayToken(TrackingToken tokenAtReset, TrackingToken startPosition, Object resetContext)
startPosition of a stream. It will be in replay
state until the position of the provided tokenAtReset. After that, the tokenAtReset will become
the active token and the stream will no longer be considered as replaying.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 nullstartPosition until the provided tokenAtResetpublic static TrackingToken createReplayToken(TrackingToken tokenAtReset)
tokenAtReset. After that, the tokenAtReset will become the active token and the
stream will no longer be considered as replaying.tokenAtReset - The token present when the reset was triggeredpublic static <T> Optional<T> replayContext(EventMessage<?> message, @Nonnull Class<T> contextClass)
message of the matching contextClass.
Will resolve to an empty Optional if the provided message is not a TrackedEventMessage, doesn't
contain a ReplayToken, or the context isn't an instance of the provided contextClass, or there is
no context at all.
T - The type of the contextmessage - The message to extract the context fromcontextClass - The class the context should matchpublic static boolean isReplay(TrackingToken trackingToken)
trackingToken represents a position that is part of a replay.trackingToken - The token to verifytrue if the token indicates a replaypublic static <T> Optional<T> replayContext(TrackingToken trackingToken, @Nonnull Class<T> contextClass)
message of the matching contextClass.
Will resolve to an empty Optional if the provided token is not a ReplayToken, or the context
isn't an instance of the provided contextClass, or there is no context at all.
T - The type of the contexttrackingToken - The tracking token to extract the context fromcontextClass - The class the context should matchpublic static OptionalLong getTokenAtReset(TrackingToken trackingToken)
OptionalLong.empty() will be returned.public TrackingToken getTokenAtReset()
public TrackingToken getCurrentToken()
public TrackingToken advancedTo(TrackingToken newToken)
WrappedTokennewToken.advancedTo in interface WrappedTokennewToken - The token representing the position to advance topublic TrackingToken lowerBound(TrackingToken other)
TrackingTokenother token. Effectively, the
returned token will cause messages not received by both this and the other token to be redelivered.lowerBound in interface TrackingTokenother - The token to compare to this onepublic TrackingToken upperBound(TrackingToken other)
TrackingTokenother represents. Effectively, this means this token will only deliver messages that neither this, nor
the other have been received.upperBound in interface TrackingTokenother - The token to compare this token topublic boolean covers(TrackingToken other)
TrackingTokenother token completely. That means that this token represents a
position in a stream that has received all of the messages that a stream represented by the other token
has received.
Note that this operation is only safe when comparing tokens obtained from messages from the same
StreamableMessageSource.
covers in interface TrackingTokenother - The token to compare to this onetrue if this token covers the other, otherwise falsepublic TrackingToken lowerBound()
WrappedTokenlowerBound in interface WrappedTokenpublic TrackingToken upperBound()
WrappedTokenupperBound in interface WrappedTokenpublic <R extends TrackingToken> Optional<R> unwrap(Class<R> tokenType)
WrappedTokentokenType if it is wrapped by this token.unwrap in interface WrappedTokenR - The generic type of the token to unwrap totokenType - The type of token to unwrap to@Nullable public Object context()
public OptionalLong position()
TrackingTokenOptionalLong.empty() will be returned.position in interface TrackingTokenCopyright © 2010–2023. All rights reserved.