Class ShutdownCountdown
One server's countdown to an operator-scheduled shutdown, run on this process's MonotonicClock from the time remaining the database measured.
public sealed class ShutdownCountdown
- Inheritance
-
ShutdownCountdown
- Inherited Members
Remarks
The deadline lives on the server's database row as an absolute UTC instant. Comparing that
instant with DateTime.UtcNow, as the world and scene servers used to, compared the
scheduler's clock with this host's: a host a minute fast stopped a minute early, a clock
stepped forward by NTP stopped the server at once, and the world server and the scene
servers clearing its players each counted down to a different moment. Every read of the row
now carries the seconds left as the database measured them in the reading statement, and
this class anchors that on the monotonic clock at the moment the reply arrived.
Each reading can only place the deadline late, never early. The database measured
the time left before the reply travelled back and was handed to the caller, so a reading's
anchor, arrival + remaining, is late by that round trip. While the scheduled instant
is unchanged, the earliest anchor seen is therefore the best estimate, and a later reading
only ever tightens it. A different instant is a new schedule and starts over.
A pure object with no Unity or network dependency, so the rule is pinned by tests. Not thread-safe: each server adopts readings on its main thread.
Properties
Deadline
The deadline on MonotonicClock. Positive infinity when nothing is scheduled, or when a schedule arrived without a measurement.
public double Deadline { get; }
Property Value
IsScheduled
Whether a shutdown is scheduled.
public bool IsScheduled { get; }
Property Value
ScheduledAtUtc
The scheduled instant as the row holds it, or null when nothing is scheduled.
The schedule's identity: a changed value is a new countdown.
public DateTime? ScheduledAtUtc { get; }
Property Value
Methods
Adopt(ServerControlReading)
Adopts one reading of the row. See Adopt(DateTime?, double?, double).
public bool Adopt(ServerControlReading reading)
Parameters
readingServerControlReading
Returns
- bool
True when the schedule changed.
Adopt(DateTime?, double?, double)
Adopts one reading of the row.
public bool Adopt(DateTime? scheduledAtUtc, double? secondsRemainingAtRead, double readAt)
Parameters
scheduledAtUtcDateTime?The row's scheduled instant, or null when none is scheduled.
secondsRemainingAtReaddouble?Seconds left before it as the database measured them in the reading statement; zero or negative once it has passed. A schedule with no measurement never falls due from this reading: stopping a server on a value nobody measured is the wrong way to fail.
readAtdoubleThe MonotonicClock reading taken when the reply arrived.
Returns
- bool
True when the schedule changed: set, moved to another instant, or cancelled.
Clear()
Forgets any schedule.
public void Clear()
IsDue(double)
Whether the scheduled shutdown has fallen due at now.
public bool IsDue(double now)
Parameters
nowdoubleA MonotonicClock reading.
Returns
SecondsRemaining(double)
Seconds left at now, never negative; infinity when none is scheduled.
public double SecondsRemaining(double now)
Parameters
nowdoubleA MonotonicClock reading.