Class TimeSources
java.lang.Object
ai.badmonkey.agentspaces.common.time.TimeSources
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
TimeSourceis itself. - The system clock (
InstantSource.system(),Clock.systemUTC()or a system clock in any zone) isTimeSource.system(), so a caller that passed it gets monotonic local periods and the wall-step signal. - Any other plain
InstantSource(a test'sTestClock, 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe furthest ahead a converted deadline is filed: a wall step re-asks every participant anyway (EL-C-12). -
Method Summary
Modifier and TypeMethodDescriptionstatic TimeSourcefollowingWall(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).static booleanfollowsWall(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.static booleanisSystemClock(InstantSource clock) Whether the clock reads the system's wall time with no offset:InstantSource.system(),Clock.systemUTC(), a system clock in any zone, orTimeSource.system().static longmonoDue(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 mostMAX_DUE_AHEAD_MILLISahead (srad/agentspaces-event-loop.md §3.6, §10.8).static TimeSourceof(InstantSource clock) The time source for a clock (see the class comment).static InstantSourcewallOf(TimeSource source) The plain clock a wall-following source reads, or the source itself.static TimeSourcewithWall(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.
-
Field Details
-
MAX_DUE_AHEAD_MILLIS
public static final long MAX_DUE_AHEAD_MILLISThe furthest ahead a converted deadline is filed: a wall step re-asks every participant anyway (EL-C-12).- See Also:
-
-
Method Details
-
of
The time source for a clock (see the class comment).- Parameters:
clock- the clock- Returns:
- the source
-
isSystemClock
Whether the clock reads the system's wall time with no offset:InstantSource.system(),Clock.systemUTC(), a system clock in any zone, orTimeSource.system().- Parameters:
clock- the clock- Returns:
- whether it is the system clock
-
followsWall
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
The plain clock a wall-following source reads, or the source itself.- Parameters:
source- the source- Returns:
- the wall clock
-
followingWall
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 clockbase- where tasks and sleeps really wait- Returns:
- the source
-
withWall
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 clockbase- 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 mostMAX_DUE_AHEAD_MILLISahead (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 nowwallNowMillis- the wall now, read with itdeadlineMillis- the wall deadline, orLong.MAX_VALUEfor none- Returns:
- the deadline on the monotonic base:
monoNowNanoswhen it has passed,Long.MAX_VALUEfor none
-