All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.commons.stat.SimpleTimerTracker Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.commons.stat;

import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.DoubleAdder;
import java.util.concurrent.atomic.LongAdder;

import io.micrometer.core.instrument.util.TimeUtils;

/**
 * A simple implementation of {@link TimerTracker} that keep tracks of events and the sum of their duration.
 *
 * @since 15.1
 */
public class SimpleTimerTracker implements TimerTracker {
   private final LongAdder counter;
   private final DoubleAdder totalTime;

   public SimpleTimerTracker() {
      counter = new LongAdder();
      totalTime = new DoubleAdder();
   }

   @Override
   public void update(Duration duration) {
      update(duration.toNanos(), TimeUnit.NANOSECONDS);
   }

   @Override
   public void update(long value, TimeUnit timeUnit) {
      counter.increment();
      totalTime.add(TimeUtils.convert(value, timeUnit, TimeUnit.NANOSECONDS));
   }

   @Override
   public long count() {
      return counter.sum();
   }

   public double totalTime() {
      return totalTime.sum();
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy