Package org.apache.pulsar.broker.qos
Interface MonotonicSnapshotClock
- All Known Implementing Classes:
DefaultMonotonicSnapshotClock
public interface MonotonicSnapshotClock
An interface representing a clock that provides a monotonic counter in nanoseconds.
The counter is guaranteed to be monotonic, ensuring it will always increase or remain constant, but never decrease.
Monotonicity ensures the time will always progress forward, making it ideal for measuring elapsed time.
The monotonic clock is not related to the wall-clock time and is not affected by changes to the system time.
The tick value is only significant when compared to other values obtained from the same clock source
and should not be used for other purposes.
This interface assumes that the implementation can be implemented in a granular way. This means that the value is
advanced in steps of a configurable resolution that snapshots the underlying high precision monotonic clock source
value.
This design allows for optimizations that can improve performance on platforms where obtaining the value of a
platform monotonic clock is relatively expensive.
-
Method Summary
Modifier and TypeMethodDescriptionlonggetTickNanos(boolean requestSnapshot) Retrieves the latest snapshot of the tick value of the monotonic clock in nanoseconds.
-
Method Details
-
getTickNanos
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.- 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.
-