Interface Clock
- All Known Implementing Classes:
ManualClock
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A source of the current time.
The succession rules and the lease clock take an instant as a parameter, so they
need no clock at all. This interface is the seam for the code around them that reads
a real clock. CoordinationClient and Leadership read it. A test
supplies ManualClock, drives time by hand, and sleeps for nothing.
Every instant this module passes is a coordinate on the epoch-millisecond line.
An extent of time is a Duration. The two kinds never mix in one
value.
Example
Clock clock = Clock.system();
long now = clock.nowMillis();
boolean live = config.timing(lease).liveAt(now);
-
Method Summary
-
Method Details
-
nowMillis
long nowMillis()Returns the current time.- Returns:
- the milliseconds since the Unix epoch
-
system
Returns the clock of the host.- Returns:
- a clock that reads
System.currentTimeMillis()
-