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.
Modifier and Type | Method and Description |
---|---|
GapAwareTrackingToken |
advanceTo(long index,
int maxGapOffset)
Deprecated.
Use
advanceTo(long, int, boolean) instead |
GapAwareTrackingToken |
advanceTo(long index,
int maxGapOffset,
boolean allowGaps)
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. |
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)
|
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. |
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.@Deprecated public GapAwareTrackingToken advanceTo(long index, int maxGapOffset)
advanceTo(long, int, boolean)
insteadGapAwareTrackingToken
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.
index
- the global sequence number of the next eventmaxGapOffset
- the maximum distance between a gap and the token's indexpublic GapAwareTrackingToken advanceTo(long index, int maxGapOffset, boolean allowGaps)
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 indexallowGaps
- whether advancing to the given index should take into account that gaps may have appearedpublic 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.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
otherwiseCopyright © 2010–2018. All rights reserved.