Class AbstractMonotonicTimestampGenerator
- java.lang.Object
-
- com.datastax.driver.core.AbstractMonotonicTimestampGenerator
-
- All Implemented Interfaces:
TimestampGenerator
- Direct Known Subclasses:
LoggingMonotonicTimestampGenerator
public abstract class AbstractMonotonicTimestampGenerator extends Object implements TimestampGenerator
Base implementation for monotonic timestamp generators.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
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 propertycom.datastax.driver.USE_NATIVE_CLOCKis explicitly set tofalse.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 Summary
Constructors Constructor Description AbstractMonotonicTimestampGenerator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected longcomputeNext(long last)Compute the next timestamp, given the last timestamp previously generated.protected abstract voidonDrift(long currentTick, long lastTimestamp)Called when generated timestamps drift into the future compared to the underlying clock (in other words, iflastTimestamp >= currentTick).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.datastax.driver.core.TimestampGenerator
next
-
-
-
-
Method Detail
-
computeNext
protected long computeNext(long last)
Compute the next timestamp, given the last timestamp previously generated.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
org.apache.cassandra.service.ClientState#getTimestamp().- Parameters:
last- the last timestamp generated by this generator, in microseconds.- Returns:
- the next timestamp to use, in microseconds.
-
onDrift
protected abstract void onDrift(long currentTick, long lastTimestamp)Called when generated timestamps drift into the future compared to the underlying clock (in other words, iflastTimestamp >= 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).
- Parameters:
currentTick- the current clock tick, in microseconds.lastTimestamp- the last timestamp that was generated, in microseconds.
-
-