Package io.ably.lib.util
Interface Clock
- All Known Implementing Classes:
SystemClock
public interface Clock
Abstraction over time-related operations used throughout the SDK.
The default implementation, SystemClock, delegates to the real system clock and
standard Java concurrency primitives. Tests and debug builds can supply an alternative
implementation (e.g. a fake/controllable clock) via DebugOptions.clock
to drive time-dependent behaviour deterministically without sleeping.
-
Method Summary
Modifier and TypeMethodDescriptionlongReturns the current wall-clock time in milliseconds since the Unix epoch (1 January 1970 00:00:00 UTC), analogous toSystem.currentTimeMillis().longnanoTime()Returns the current wall-clock time in nanoseconds since the Unix epoch (1 January 1970 00:00:00 UTC), analogous toSystem.nanoTime().Creates a newAblyTimerbacked by this clock.voidCauses the current thread to wait until either another thread callsObject.notify()/Object.notifyAll()ontarget, or the specified timeout elapses — analogous toObject.wait(long).
-
Method Details
-
currentTimeMillis
long currentTimeMillis()Returns the current wall-clock time in milliseconds since the Unix epoch (1 January 1970 00:00:00 UTC), analogous toSystem.currentTimeMillis().- Returns:
- current time in milliseconds
-
nanoTime
long nanoTime()Returns the current wall-clock time in nanoseconds since the Unix epoch (1 January 1970 00:00:00 UTC), analogous toSystem.nanoTime().- Returns:
- current time in nanoseconds
-
newTimer
Creates a newAblyTimerbacked by this clock.The name is used for diagnostic and logging purposes (e.g. as the underlying
Timerthread name).- Parameters:
-
name- a human-readable label for the timer; must not benull - Returns:
- a new
AblyTimerinstance ready to schedule tasks
-
waitOn
Causes the current thread to wait until either another thread callsObject.notify()/Object.notifyAll()ontarget, or the specified timeout elapses — analogous toObject.wait(long).The caller must hold the monitor of
targetbefore invoking this method, exactly as required byObject.wait(long).- Parameters:
-
target- the object whose monitor the current thread holds and will wait on; must not benull -
timeout- maximum time to wait in milliseconds;0means wait indefinitely - Throws:
-
InterruptedException- if the current thread is interrupted while waiting
-