Class DelegatingClock
java.lang.Object
java.time.Clock
io.fluxzero.common.DelegatingClock
- All Implemented Interfaces:
InstantSource
A concrete implementation of a
Clock that delegates its method calls to another Clock
instance, allowing runtime manipulation of the delegated clock.
This class is useful when you need to dynamically switch the clock's implementation during runtime, for example, testing scenarios requiring adjustable or controlled time flows.
The delegated clock instance is stored atomically to ensure thread-safe updates.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetZone()instant()Registers a listener that is invoked whenever the backing clock changes.voidsetDelegate(@NonNull Clock delegate) Replaces the backing clock and notifies registered change listeners after the new clock is visible.Methods inherited from class Clock
equals, fixed, hashCode, millis, offset, system, systemDefaultZone, systemUTC, tick, tickMillis, tickMinutes, tickSeconds
-
Constructor Details
-
DelegatingClock
public DelegatingClock()
-
-
Method Details
-
setDelegate
Replaces the backing clock and notifies registered change listeners after the new clock is visible. -
onChange
Registers a listener that is invoked whenever the backing clock changes.- Parameters:
listener- callback to invoke aftersetDelegate(Clock)- Returns:
- registration that removes the listener
-
getZone
-
withZone
-
instant
- Specified by:
instantin interfaceInstantSource- Specified by:
instantin classClock
-