Package 

Class ServerClockOffset


  • 
    public final class ServerClockOffset
    
                        

    Tracks the offset between the local device clock and the server clock using NTP-style estimation from WebSocket health check round-trips.

    The algorithm keeps only the sample with the lowest observed RTT, since a smaller round-trip means less room for network asymmetry to distort the measurement. Under the assumption that clock skew is constant for the duration of a session, the estimate monotonically improves over time.

    Thread-safe: single-field writes use Volatile for visibility; compound read-modify-write sequences are guarded by lock for atomicity.

    • Method Summary

      Modifier and Type Method Description
      final Date estimatedServerTime() Returns the current time adjusted to the server timescale.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ServerClockOffset

        ServerClockOffset(Function0<Long> localTimeMs, Long maxRttMs, Long maxOffsetMs)
        Parameters:
        localTimeMs - Clock source for the local device time (injectable for tests).
        maxRttMs - Upper bound on plausible RTT.
        maxOffsetMs - Upper bound on the absolute value of the computed clock offset.
    • Method Detail

      • estimatedServerTime

         final Date estimatedServerTime()

        Returns the current time adjusted to the server timescale.

        Before the first onConnected call, this returns the raw local time (offset = 0).