Class TimeService.SystemTimeService

java.lang.Object
org.jgroups.raft.util.TimeService.SystemTimeService
All Implemented Interfaces:
TimeService
Enclosing interface:
TimeService

public static final class TimeService.SystemTimeService extends Object implements TimeService
Live implementation backed by the JVM time.
Since:
2.0
Author:
José Bolina
  • Method Details

    • now

      public Instant now()
      Description copied from interface: TimeService
      Returns the current wall-clock time.

      Use this for human-readable timestamps. Do not use for latency measurement, wall-clock time is subject to NTP adjustments.

      Specified by:
      now in interface TimeService
      Returns:
      the current instant, or null when the service is disabled
    • nanos

      public long nanos()
      Description copied from interface: TimeService
      Returns a monotonic nanosecond timestamp.

      Capture a value with nanos() at the start of an operation, then pass it to TimeService.interval(long) to compute the elapsed time. The absolute value has no meaning outside of interval computation.

      Specified by:
      nanos in interface TimeService
      Returns:
      a monotonic nanosecond value, or 0 when disabled
    • interval

      public long interval(long start)
      Description copied from interface: TimeService
      Computes the elapsed nanoseconds since a previously captured TimeService.nanos() value.

      Typical usage:

      long start = timeService.nanos();
      // ... operation ...
      long elapsedNanos = timeService.interval(start);
      
      Specified by:
      interval in interface TimeService
      Parameters:
      start - a value previously returned by TimeService.nanos()
      Returns:
      elapsed nanoseconds, or 0 when disabled