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.

@FunctionalInterface public interface Clock
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

    Modifier and Type
    Method
    Description
    long
    Returns the current time.
    static Clock
    Returns the clock of the host.
  • Method Details

    • nowMillis

      long nowMillis()
      Returns the current time.
      Returns:
      the milliseconds since the Unix epoch
    • system

      static Clock system()
      Returns the clock of the host.
      Returns:
      a clock that reads System.currentTimeMillis()