Interface NanoClock

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 NanoClock
A monotonic clock in nanoseconds, injected into the connection layer so that timers can be driven deterministically in tests. The components of this package never read a clock; they take now as an argument, which the connection reads from its NanoClock.

Times from one clock are compared directly, so a clock must not wrap during a connection's lifetime (System.nanoTime() wraps after 292 years).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    The time that is not set, used where a time is optional.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    The current time.
    static NanoClock
    The system's monotonic clock.
  • Field Details

    • NONE

      static final long NONE
      The time that is not set, used where a time is optional. No clock returns it.
      See Also:
  • Method Details

    • nanoTime

      long nanoTime()
      The current time.
      Returns:
      nanoseconds from an arbitrary origin, never NONE
    • system

      static NanoClock system()
      The system's monotonic clock.
      Returns:
      a clock backed by System.nanoTime()