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

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

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

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * Same as {@link GaugeMetricInfo} but the tracked value is a time or duration.
 *
 * @since 15.0
 */
public final class TimeGaugeMetricInfo extends BaseMetricInfo {

   private final Function function;
   private final TimeUnit timeUnit;

   public TimeGaugeMetricInfo(String name, String description, Map map, Function function, TimeUnit timeUnit) {
      super(name, description, map);
      this.function = Objects.requireNonNull(function);
      this.timeUnit = Objects.requireNonNull(timeUnit);
   }

   /**
    * @return The {@link Supplier} to invoke to return the current value of the metric.
    */
   public Supplier getGauge(T instance) {
      return () -> function.apply(instance);
   }

   /**
    * @return The {@link TimeUnit} of the tracked value.
    */
   public TimeUnit getTimeUnit() {
      return timeUnit;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy