All Known Implementing Classes:
ManualClock

public interface Clock
Abstraction over time, used by patterns that need to read the current instant or wait (Retry backoff, CircuitBreaker open-state duration, RateLimiter windows, ...). Extension point: test code can supply a manual/virtual implementation instead of systemClock() to make timing-based tests deterministic and instant.
  • Method Summary

    Modifier and Type
    Method
    Description
    The current instant, as seen by this clock.
    void
    sleep(long millis)
    Suspend the calling thread for the given duration, as measured by this clock.
    static Clock
    The default clock, backed by the system wall clock and Thread.sleep(long).
  • Method Details

    • instant

      Instant instant()
      The current instant, as seen by this clock.
    • sleep

      void sleep(long millis) throws InterruptedException
      Suspend the calling thread for the given duration, as measured by this clock. Deliberately mirrors Thread.sleep(long)'s checked InterruptedException rather than wrapping it in a resiliencia exception: callers already have an established, idiomatic interruption protocol (catch, restore the interrupt flag, react) to follow here, and every caller in this codebase does exactly that at the call site.
      Throws:
      InterruptedException
    • systemClock

      static Clock systemClock()
      The default clock, backed by the system wall clock and Thread.sleep(long).