Package org.apache.polaris.ids.api
Interface MonotonicClock
- All Superinterfaces:
AutoCloseable
Provides a clock providing the current time in milliseconds, microseconds and instant since
1970-01-01-00:00:00.000. The returned timestamp values increase monotonically.
The functions provide nanosecond/microsecond/millisecond precision, but not necessarily the same resolution (how frequently the value changes) - no guarantees are made.
Implementation may adjust to wall clocks advancing faster than the real time. If and how exactly depends on the implementation, as long as none of the time values available via this interface "goes backwards".
Implementer notes: System.nanoTime() does not guarantee that the
values will be monotonically increasing when invocations happen from different
CPUs/cores/threads.
A default implementation of MonotonicClock can be injected as an application scoped
bean in CDI.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Current instant with nanosecond precision, can be used as a monotonically increasing wall clock.longCurrent timestamp as microseconds since epoch, can be used as a monotonically increasing wall clock.longCurrent timestamp as milliseconds since epoch, can be used as a monotonically increasing wall clock.longnanoTime()Monotonically increasing timestamp with nanosecond precision, not related to wall clock.voidsleepMillis(long millis) void
-
Method Details
-
currentTimeMicros
long currentTimeMicros()Current timestamp as microseconds since epoch, can be used as a monotonically increasing wall clock. -
currentTimeMillis
long currentTimeMillis()Current timestamp as milliseconds since epoch, can be used as a monotonically increasing wall clock. -
currentInstant
Instant currentInstant()Current instant with nanosecond precision, can be used as a monotonically increasing wall clock. -
nanoTime
long nanoTime()Monotonically increasing timestamp with nanosecond precision, not related to wall clock. -
sleepMillis
void sleepMillis(long millis) -
close
void close()- Specified by:
closein interfaceAutoCloseable
-
waitUntilTimeMillisAdvanced
void waitUntilTimeMillisAdvanced()
-