Class DefaultMonotonicSnapshotClock

java.lang.Object
org.apache.pulsar.broker.qos.DefaultMonotonicSnapshotClock
All Implemented Interfaces:
AutoCloseable, MonotonicSnapshotClock

public class DefaultMonotonicSnapshotClock extends Object implements MonotonicSnapshotClock, AutoCloseable
Default implementation of MonotonicSnapshotClock. Starts a daemon thread that updates the snapshot value periodically with a configured interval. The close method should be called to stop the thread.
  • Constructor Details

    • DefaultMonotonicSnapshotClock

      public DefaultMonotonicSnapshotClock(long snapshotIntervalNanos, LongSupplier clockSource)
  • Method Details

    • getTickNanos

      public long getTickNanos(boolean requestSnapshot)
      Retrieves the latest snapshot of the tick value of the monotonic clock in nanoseconds. When requestSnapshot is set to true, the method will snapshot the underlying high-precision monotonic clock source so that the latest snapshot value is as accurate as possible. This may be a relatively expensive compared to a non-snapshot request. When requestSnapshot is set to false, the method will return the latest snapshot value which is updated by either a call that requested a snapshot or by an update thread that is configured to update the snapshot value periodically. This method returns a value that is guaranteed to be monotonic, meaning it will always increase or remain the same, never decrease. The returned value is only significant when compared to other values obtained from the same clock source and should not be used for other purposes.
      Specified by:
      getTickNanos in interface MonotonicSnapshotClock
      Parameters:
      requestSnapshot - If set to true, the method will request a new snapshot from the underlying more high-precision monotonic clock.
      Returns:
      The current tick value of the monotonic clock in nanoseconds.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable