Class DefaultTimer

  • All Implemented Interfaces:
    Timer

    public class DefaultTimer
    extends java.lang.Object
    implements Timer
    A default Timer implementation that uses a Stopwatch instance internally to measure time.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.apache.iceberg.metrics.Timer

        Timer.Timed
    • Field Summary

      • Fields inherited from interface org.apache.iceberg.metrics.Timer

        NOOP
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultTimer​(java.util.concurrent.TimeUnit timeUnit)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long count()
      The number of times Timer.time(Duration) was called.
      void record​(long amount, java.util.concurrent.TimeUnit unit)
      Records a custom amount in the given time unit.
      Timer.Timed start()
      Starts the timer and returns a Timer.Timed instance.
      void time​(java.lang.Runnable runnable)
      Executes and measures the given Runnable instance.
      <T> T time​(java.util.function.Supplier<T> supplier)
      Gets the result from the given Supplier and measures its execution time.
      <T> T timeCallable​(java.util.concurrent.Callable<T> callable)
      Executes and measures the given Callable and returns its result.
      java.lang.String toString()  
      java.time.Duration totalDuration()
      The total duration that was recorded.
      java.util.concurrent.TimeUnit unit()
      The TimeUnit of the timer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.apache.iceberg.metrics.Timer

        isNoop, time
    • Constructor Detail

      • DefaultTimer

        public DefaultTimer​(java.util.concurrent.TimeUnit timeUnit)
    • Method Detail

      • totalDuration

        public java.time.Duration totalDuration()
        Description copied from interface: Timer
        The total duration that was recorded.
        Specified by:
        totalDuration in interface Timer
        Returns:
        The total duration that was recorded.
      • record

        public void record​(long amount,
                           java.util.concurrent.TimeUnit unit)
        Description copied from interface: Timer
        Records a custom amount in the given time unit.
        Specified by:
        record in interface Timer
        Parameters:
        amount - The amount to record
        unit - The time unit of the amount
      • time

        public <T> T time​(java.util.function.Supplier<T> supplier)
        Description copied from interface: Timer
        Gets the result from the given Supplier and measures its execution time.
        Specified by:
        time in interface Timer
        Type Parameters:
        T - The type of the Supplier.
        Parameters:
        supplier - The Supplier to execute and measure.
        Returns:
        The result of the underlying Supplier.
      • timeCallable

        public <T> T timeCallable​(java.util.concurrent.Callable<T> callable)
                           throws java.lang.Exception
        Description copied from interface: Timer
        Executes and measures the given Callable and returns its result.
        Specified by:
        timeCallable in interface Timer
        Type Parameters:
        T - The type of the Callable
        Parameters:
        callable - The Callable to execute and measure.
        Returns:
        The result of the underlying Callable.
        Throws:
        java.lang.Exception - In case the Callable fails.
      • time

        public void time​(java.lang.Runnable runnable)
        Description copied from interface: Timer
        Executes and measures the given Runnable instance.
        Specified by:
        time in interface Timer
        Parameters:
        runnable - The Runnable to execute and measure.
      • unit

        public java.util.concurrent.TimeUnit unit()
        Description copied from interface: Timer
        The TimeUnit of the timer.
        Specified by:
        unit in interface Timer
        Returns:
        The TimeUnit of the timer.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object