Interface Clock
- 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 TypeMethodDescriptioninstant()The current instant, as seen by this clock.voidsleep(long millis) Suspend the calling thread for the given duration, as measured by this clock.static ClockThe default clock, backed by the system wall clock andThread.sleep(long).
-
Method Details
-
instant
Instant instant()The current instant, as seen by this clock. -
sleep
Suspend the calling thread for the given duration, as measured by this clock. Deliberately mirrorsThread.sleep(long)'s checkedInterruptedExceptionrather 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
The default clock, backed by the system wall clock andThread.sleep(long).
-