public abstract class AbstractMonotonicTimestampGenerator extends Object implements TimestampGenerator
System.currentTimeMillis()
.
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 false
.
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 invoked.Constructor and Description |
---|
AbstractMonotonicTimestampGenerator() |
Modifier and Type | Method and Description |
---|---|
protected long |
computeNext(long last)
Compute the next timestamp, given the last timestamp previously generated.
|
protected abstract void |
onDrift(long currentTick,
long lastTimestamp)
Called when generated timestamps drift into the future compared to the underlying clock (in other words, if
lastTimestamp >= currentTick ). |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
next
protected long computeNext(long last)
onDrift(long, long)
will be invoked.
This implementation is inspired by org.apache.cassandra.service.ClientState#getTimestamp()
.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.