public abstract class AbstractMonotonicTimestampGenerator extends Object implements TimestampGenerator
The accuracy of the generated timestamps is largely dependent on the granularity of the underlying operating system's clock.
Generally speaking, this granularity is millisecond, and the sub-millisecond part is simply a
counter that gets incremented until the next clock tick, as provided by
On some systems, however, it is possible to have a better granularity by using a JNR call to
gettimeofday. The driver will use this system call automatically whenever available,
unless the system property
com.datastax.driver.USE_NATIVE_CLOCK is explicitly set to
Beware that to guarantee monotonicity, if more than one call to
TimestampGenerator.next() is made within
the same microsecond, or in the event of a system clock skew, this generator might return
timestamps that drift out in the future. Whe this happens,
onDrift(long, long) is
|Constructor and Description|
|Modifier and Type||Method and Description|
Compute the next timestamp, given the last timestamp previously generated.
Called when generated timestamps drift into the future compared to the underlying clock (in other words, if
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
protected long computeNext(long last)
To guarantee monotonicity, the next timestamp should be strictly greater than the last one.
If the underlying clock fails to generate monotonically increasing timestamps, the generator
will simply increment the previous timestamp, and
onDrift(long, long) will be invoked.
This implementation is inspired by
last- the last timestamp generated by this generator, in microseconds.
protected abstract void onDrift(long currentTick, long lastTimestamp)
lastTimestamp >= currentTick).
This could happen if timestamps are requested faster than the clock granularity, or on a clock skew (for example because of a leap second).
currentTick- the current clock tick, in microseconds.
lastTimestamp- the last timestamp that was generated, in microseconds.
Copyright © 2012–2022. All rights reserved.