Class ThreadLocalMonotonicTimestampGenerator

  • All Implemented Interfaces:
    TimestampGenerator

    public class ThreadLocalMonotonicTimestampGenerator
    extends LoggingMonotonicTimestampGenerator
    A timestamp generator that guarantees monotonically increasing timestamps on a per-thread basis, and logs warnings when timestamps drift in the future.

    Beware that there is a risk of timestamp collision with this generator when accessed by more than one thread at a time; only use it when threads are not in direct competition for timestamp ties (i.e., they are executing independent statements).

    See Also:
    AbstractMonotonicTimestampGenerator
    • Constructor Detail

      • ThreadLocalMonotonicTimestampGenerator

        public ThreadLocalMonotonicTimestampGenerator​(long warningThreshold,
                                                      TimeUnit warningThresholdUnit,
                                                      long warningInterval,
                                                      TimeUnit warningIntervalUnit)
        Creates a new instance.
        Parameters:
        warningThreshold - how far in the future timestamps are allowed to drift before a warning is logged.
        warningThresholdUnit - the unit for warningThreshold.
        warningInterval - how often the warning will be logged if timestamps keep drifting above the threshold.
        warningIntervalUnit - the unit for warningIntervalUnit.
    • Method Detail

      • next

        public long next()
        Description copied from interface: TimestampGenerator
        Returns the next timestamp.

        Implementors should enforce increasing monotonicity of timestamps, that is, a timestamp returned should always be strictly greater that any previously returned timestamp.

        Implementors should strive to achieve microsecond precision in the best possible way, which is usually largely dependent on the underlying operating system's capabilities.

        Returns:
        the next timestamp (in microseconds). If it equals Long.MIN_VALUE, it won't be sent by the driver, letting Cassandra generate a server-side timestamp.