public class GapAwareTrackingToken extends Object implements TrackingToken, Serializable
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.
Constructor and Description |
---|
GapAwareTrackingToken(long index,
Collection<Long> gaps)
This constructor is mean't to be used for deserialization.
|
Modifier and Type | Method and Description |
---|---|
GapAwareTrackingToken |
advanceTo(long index,
int maxGapOffset)
Returns a new
GapAwareTrackingToken instance based on this token but which has advanced to given index . |
boolean |
covers(TrackingToken other)
Indicates whether this token covers the
other token completely. |
protected static SortedSet<Long> |
createSortedSetOf(Collection<Long> gaps,
long index)
Construct a
SortedSet of the given gaps to be set in this Tracking Token. |
boolean |
equals(Object o) |
SortedSet<Long> |
getGaps()
Get a
SortedSet of this token's gaps. |
long |
getIndex()
Get the highest global sequence of events seen up until the point of this tracking token.
|
boolean |
hasGaps()
Check if this token contains one ore more gaps.
|
int |
hashCode() |
GapAwareTrackingToken |
lowerBound(TrackingToken other)
Returns a token that represents the lower bound between this and the
other token. |
static GapAwareTrackingToken |
newInstance(long index,
Collection<Long> gaps)
|
OptionalLong |
position()
Return the estimated relative position this token represents.
|
String |
toString() |
TrackingToken |
upperBound(TrackingToken otherToken)
Returns the token that represents the furthest possible position in a stream that either this token or the given
other represents. |
GapAwareTrackingToken |
withGapsTruncatedAt(long truncationPoint)
Returns a copy of the current token, with gaps truncated at the given
truncationPoint . |
@ConstructorProperties(value={"index","gaps"}) public GapAwareTrackingToken(long index, Collection<Long> gaps)
newInstance(long, Collection)
to create new instances.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.public static GapAwareTrackingToken newInstance(long index, Collection<Long> gaps)
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.protected static SortedSet<Long> createSortedSetOf(Collection<Long> gaps, long index)
SortedSet
of the given gaps
to be set in this Tracking Token. The given index
will be consolidated to ensure the last gap in the set is smaller. If this is not the case, an
IllegalArgumentException
is throwngaps
- the Collection
of gaps to created a SortedSet
out ofindex
- a long
which is required to be bigger than the last known gap in the setSortedSet
constructed out of the given gaps
public GapAwareTrackingToken advanceTo(long index, int maxGapOffset)
GapAwareTrackingToken
instance based on this token but which has advanced to given index
. Gaps that have fallen behind the index by more than the maxGapOffset
will not be included in the
new token.
Note that the given index
should be one of the current token's gaps or be higher than the current token's
index.
If allowGaps
is set to false
, any gaps that occur before the given index
are removed
from the returned token.
index
- the global sequence number of the next eventmaxGapOffset
- the maximum distance between a gap and the token's indexpublic GapAwareTrackingToken withGapsTruncatedAt(long truncationPoint)
truncationPoint
. This removes any
gaps with index strictly smaller than the truncationPoint
and disregards these when comparing this token
to any other tokens.
Note that truncation information is not serialized as part of the token.
truncationPoint
- The index up to (and including) which gaps are to be disregarded.truncationPoint
public long getIndex()
public SortedSet<Long> getGaps()
SortedSet
of this token's gaps.public GapAwareTrackingToken lowerBound(TrackingToken other)
TrackingToken
other
token. Effectively, the
returned token will cause messages not received by both this and the other
token to be redelivered.lowerBound
in interface TrackingToken
other
- The token to compare to this onepublic TrackingToken upperBound(TrackingToken otherToken)
TrackingToken
other
represents. Effectively, this means this token will only deliver messages that neither this, nor
the other have been received.upperBound
in interface TrackingToken
otherToken
- The token to compare this token topublic boolean covers(TrackingToken other)
TrackingToken
other
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 TrackingToken
other
- The token to compare to this onetrue
if this token covers the other, otherwise false
public boolean hasGaps()
true
if this token contains gaps, false
otherwisepublic OptionalLong position()
TrackingToken
OptionalLong.empty()
will be returned.position
in interface TrackingToken
Copyright © 2010–2024. All rights reserved.