Class CachedNanoClock

java.lang.Object
org.agrona.concurrent.CachedNanoClock
All Implemented Interfaces:
NanoClock

public class CachedNanoClock extends Object implements NanoClock
A NanoClock that caches a timestamp which can be updated with update(long).

Instances are threadsafe with the read being volatile.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
    Time in nanoseconds.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    advance(long nanos)
    Advance the value of the timestamp in with release ordered semantics.
    long
    The number of ticks in nanoseconds the clock has advanced since starting.
    void
    update(long timeNs)
    Update the value of the timestamp with release memory ordered semantics.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • timeNs

      protected volatile long timeNs
      Time in nanoseconds.
  • Constructor Details

    • CachedNanoClock

      public CachedNanoClock()
      Create a new instance.
  • Method Details

    • nanoTime

      public long nanoTime()
      The number of ticks in nanoseconds the clock has advanced since starting.

      This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary origin time (perhaps in the future, so values may be negative). The same origin is used by all invocations of this method in an instance of a Java virtual machine; other virtual machine instances are likely to use a different origin.

      Specified by:
      nanoTime in interface NanoClock
      Returns:
      number of ticks in nanoseconds the clock has advanced since starting.
      See Also:
    • update

      public void update(long timeNs)
      Update the value of the timestamp with release memory ordered semantics.
      Parameters:
      timeNs - value to update the timestamp.
    • advance

      public void advance(long nanos)
      Advance the value of the timestamp in with release ordered semantics.
      Parameters:
      nanos - to advance the timestamp.