Class GapAwareTrackingToken
- All Implemented Interfaces:
TrackingToken
TrackingToken that uses the global insertion sequence number of the event to determine
tracking order and additionally stores a set of possible gaps that have been detected while tracking the event
store.
By storing the sequence numbers of gaps, i.e. sequence numbers of events that may have been inserted but have not been committed to the store, consumers are able to track the event store uninterruptedly even when there are gaps in the sequence numbers of events. If a gap is detected the event store can check if meanwhile this gap has been filled each time a new batch of events is fetched.
- Author:
- Rene de Waele
-
Field Summary
Fields inherited from interface org.axonframework.messaging.eventhandling.processing.streaming.token.TrackingToken
FIRST, LATEST, RESOURCE_KEY -
Constructor Summary
ConstructorsConstructorDescriptionGapAwareTrackingToken(long index, Collection<Long> gaps) This constructor is mean't to be used for deserialization. -
Method Summary
Modifier and TypeMethodDescriptionadvanceTo(long index, int maxGapOffset) Returns a newGapAwareTrackingTokeninstance based on this token but which has advanced to givenindex.booleancovers(TrackingToken other) Indicates whether this token covers theothertoken completely.createSortedSetOf(Collection<Long> gaps, long index) Construct aSortedSetof the givengapsto be set in this Tracking Token.booleangetGaps()Get aSortedSetof this token's gaps.longgetIndex()Get the highest global sequence of events seen up until the point of this tracking token.booleanhasGaps()Check if this token contains one ore more gaps.inthashCode()lowerBound(TrackingToken other) Returns a token that represents the lower bound between this and theothertoken.static GapAwareTrackingTokennewInstance(long index, Collection<Long> gaps) position()Return the estimated relative position this token represents.booleansamePositionAs(TrackingToken other) Indicates whetherthistoken is at the exact same spot in the event stream as theothertoken.toString()upperBound(TrackingToken otherToken) Returns the token that represents the furthest possible position in a stream that either this token or the givenotherrepresents.withGapsTruncatedAt(long truncationPoint) Returns a copy of the current token, with gaps truncated at the giventruncationPoint.
-
Constructor Details
-
GapAwareTrackingToken
@ConstructorProperties({"index","gaps"}) public GapAwareTrackingToken(long index, Collection<Long> gaps) This constructor is mean't to be used for deserialization.
Please usenewInstance(long, Collection)to create new instances.- Parameters:
index- the highest global sequence number of events up until (and including) this tracking tokengaps- global sequence numbers of events that have not been seen yet even though these sequence numbers are smaller than the current index. These missing sequence numbers may be filled in later when those events get committed to the store or may never be filled in if those events never get committed.
-
-
Method Details
-
newInstance
- Parameters:
index- the highest global sequence number of events up until (and including) this tracking tokengaps- global sequence numbers of events that have not been seen yet even though these sequence numbers are smaller than the current index. These missing sequence numbers may be filled in later when those events get committed to the store or may never be filled in if those events never get committed.- Returns:
- a new tracking token from given index and gaps
-
createSortedSetOf
Construct aSortedSetof the givengapsto be set in this Tracking Token. The givenindexwill be consolidated to ensure the last gap in the set is smaller. If this is not the case, anIllegalArgumentExceptionis thrown- Parameters:
gaps- theCollectionof gaps to created aSortedSetout ofindex- alongwhich is required to be bigger than the last known gap in the set- Returns:
- a
SortedSetconstructed out of the givengaps
-
advanceTo
Returns a newGapAwareTrackingTokeninstance based on this token but which has advanced to givenindex. Gaps that have fallen behind the index by more than themaxGapOffsetwill not be included in the new token.Note that the given
indexshould be one of the current token's gaps or be higher than the current token's index.If
allowGapsis set tofalse, any gaps that occur before the givenindexare removed from the returned token.- Parameters:
index- the global sequence number of the next eventmaxGapOffset- the maximum distance between a gap and the token's index- Returns:
- the new token that has advanced from the current token
-
withGapsTruncatedAt
Returns a copy of the current token, with gaps truncated at the giventruncationPoint. This removes any gaps with index strictly smaller than thetruncationPointand disregards these when comparing this token to any other tokens.Note that truncation information is not serialized as part of the token.
- Parameters:
truncationPoint- The index up to (and including) which gaps are to be disregarded.- Returns:
- a Token without any gaps strictly smaller than given
truncationPoint
-
getIndex
public long getIndex()Get the highest global sequence of events seen up until the point of this tracking token.- Returns:
- the highest global event sequence number seen so far
-
getGaps
Get aSortedSetof this token's gaps.- Returns:
- the gaps of this token
-
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:
otherToken- 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
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.For
GapAwareTrackingToken, this method only compares the index positions, ignoring the gap structures. This is useful when comparing tokens from different points in time, where gap structures may naturally differ.The method returns
trueif both tokens have the same index value.- 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:
-
hasGaps
public boolean hasGaps()Check if this token contains one ore more gaps.- Returns:
trueif this token contains gaps,falseotherwise
-
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
-