Class EpochTickClock

  • All Implemented Interfaces:
    Recyclable

    public class EpochTickClock
    extends java.lang.Object
    implements Recyclable
    This clock makes sure that each Span and Transaction uses a consistent clock which does not drift in case of NTP updates or leap seconds.

    The clock is initialized with wall clock time when the transaction starts and from there on uses System.nanoTime() in order to be able to measure durations. System.currentTimeMillis(), which uses wall clock time is not suitable for measuring durations because of the aforementioned possibility of clock drifts.

    • Constructor Summary

      Constructors 
      Constructor Description
      EpochTickClock()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getEpochMicros()  
      long getEpochMicros​(long nanoTime)  
      long init()
      Initializes and calibrates the clock based on wall clock time
      long init​(long epochMicrosWallClock, long nanoTime)
      Initializes and calibrates the clock based on wall clock time
      void init​(EpochTickClock other)
      Initializes the clock by aligning the offset with the offset of another clock.
      void resetState()
      resets pooled object state so it can be reused
      • Methods inherited from class java.lang.Object

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

      • EpochTickClock

        public EpochTickClock()
    • Method Detail

      • init

        public void init​(EpochTickClock other)
        Initializes the clock by aligning the offset with the offset of another clock.
        Parameters:
        other - the other clock, which has already been initialized
      • init

        public long init()
        Initializes and calibrates the clock based on wall clock time
        Returns:
        the epoch microsecond timestamp at initialization time
      • init

        public long init​(long epochMicrosWallClock,
                         long nanoTime)
        Initializes and calibrates the clock based on wall clock time
        Parameters:
        epochMicrosWallClock - the current timestamp in microseconds since epoch, based on wall clock time
        nanoTime - the current nanosecond ticks (mostly System.nanoTime()
        Returns:
        the epoch microsecond timestamp at initialization time
      • getEpochMicros

        public long getEpochMicros()
      • getEpochMicros

        public long getEpochMicros​(long nanoTime)
      • resetState

        public void resetState()
        Description copied from interface: Recyclable
        resets pooled object state so it can be reused
        Specified by:
        resetState in interface Recyclable