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 Details

    • currentTimeMillis

      long currentTimeMillis()
      Returns the current wall-clock time in milliseconds since the Unix epoch (1 January 1970 00:00:00 UTC), analogous to System.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 to System.nanoTime().
      Returns:
      current time in nanoseconds
    • newTimer

      AblyTimer newTimer(String name)
      Creates a new AblyTimer backed by this clock.

      The name is used for diagnostic and logging purposes (e.g. as the underlying Timer thread name).

      Parameters:
      name - a human-readable label for the timer; must not be null
      Returns:
      a new AblyTimer instance ready to schedule tasks
    • waitOn

      void waitOn(Object target, long timeout) throws InterruptedException
      Causes the current thread to wait until either another thread calls Object.notify() / Object.notifyAll() on target, or the specified timeout elapses — analogous to Object.wait(long).

      The caller must hold the monitor of target before invoking this method, exactly as required by Object.wait(long).

      Parameters:
      target - the object whose monitor the current thread holds and will wait on; must not be null
      timeout - maximum time to wait in milliseconds; 0 means wait indefinitely
      Throws:
      InterruptedException - if the current thread is interrupted while waiting