Class TimeSources

java.lang.Object
ai.badmonkey.agentspaces.common.time.TimeSources

public final class TimeSources extends Object
Turns the InstantSource a caller passed into the one TimeSource a node runs on (srad/agentspaces-event-loop.md §3.1, EL-C-06).
  • A TimeSource is itself.
  • The system clock (InstantSource.system(), Clock.systemUTC() or a system clock in any zone) is TimeSource.system(), so a caller that passed it gets monotonic local periods and the wall-step signal.
  • Any other plain InstantSource (a test's TestClock, an offset clock) is a wall-following source (followingWall(InstantSource, TimeSource)): wall time is the clock's, and the monotonic base follows the clock as well, held from going backwards, so a hand-driven test that moves its clock moves every local period with it, as before phase 3. Scheduling converts each deadline to a delay on the system source. Such a source has no watchdog and raises no wall step.
  • Field Details

    • MAX_DUE_AHEAD_MILLIS

      public static final long MAX_DUE_AHEAD_MILLIS
      The furthest ahead a converted deadline is filed: a wall step re-asks every participant anyway (EL-C-12).
      See Also:
  • Method Details

    • of

      public static TimeSource of(InstantSource clock)
      The time source for a clock (see the class comment).
      Parameters:
      clock - the clock
      Returns:
      the source
    • isSystemClock

      public static boolean isSystemClock(InstantSource clock)
      Whether the clock reads the system's wall time with no offset: InstantSource.system(), Clock.systemUTC(), a system clock in any zone, or TimeSource.system().
      Parameters:
      clock - the clock
      Returns:
      whether it is the system clock
    • followsWall

      public static boolean followsWall(TimeSource source)
      Whether the source's monotonic base follows a plain wall clock (followingWall(InstantSource, TimeSource)), so its local periods move only when that clock does.
      Parameters:
      source - the source
      Returns:
      whether it follows a wall clock
    • wallOf

      public static InstantSource wallOf(TimeSource source)
      The plain clock a wall-following source reads, or the source itself.
      Parameters:
      source - the source
      Returns:
      the wall clock
    • followingWall

      public static TimeSource followingWall(InstantSource wall, TimeSource base)
      A source whose wall time and monotonic base both follow a plain clock (the base held from going backwards), with scheduling and sleeps converted to delays on another source (see the class comment).
      Parameters:
      wall - the clock
      base - where tasks and sleeps really wait
      Returns:
      the source
    • withWall

      public static TimeSource withWall(InstantSource wall, TimeSource base)
      A source whose wall time is a clock's and whose monotonic base, scheduling, sleeps, wall steps and watchdog are another source's, for a caller that passes a separate wall clock beside a time source.
      Parameters:
      wall - the wall clock
      base - the rest
      Returns:
      the source
    • monoDue

      public static long monoDue(long monoNowNanos, long wallNowMillis, long deadlineMillis)
      A wall deadline as a deadline on the monotonic base, converted against both clocks read together, now, and filed at most MAX_DUE_AHEAD_MILLIS ahead (srad/agentspaces-event-loop.md §3.6, §10.8). The one converter every registrant whose leases and expiries are wall instants uses.
      Parameters:
      monoNowNanos - the monotonic now
      wallNowMillis - the wall now, read with it
      deadlineMillis - the wall deadline, or Long.MAX_VALUE for none
      Returns:
      the deadline on the monotonic base: monoNowNanos when it has passed, Long.MAX_VALUE for none