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

com.wavefront.agent.histogram.accumulator.AgentDigestFactory Maven / Gradle / Ivy

package com.wavefront.agent.histogram.accumulator;

import com.tdunning.math.stats.AgentDigest;
import com.wavefront.common.TimeProvider;
import java.util.function.Supplier;

/**
 * A simple factory for creating {@link AgentDigest} objects with a specific compression level and
 * expiration TTL.
 *
 * @author [email protected]
 */
public class AgentDigestFactory {
  private final Supplier compressionSupplier;
  private final long ttlMillis;
  private final TimeProvider timeProvider;

  /**
   * @param compressionSupplier supplier for compression level setting.
   * @param ttlMillis default ttlMillis for new digests.
   * @param timeProvider time provider (in millis).
   */
  public AgentDigestFactory(
      Supplier compressionSupplier, long ttlMillis, TimeProvider timeProvider) {
    this.compressionSupplier = compressionSupplier;
    this.ttlMillis = ttlMillis;
    this.timeProvider = timeProvider;
  }

  public AgentDigest newDigest() {
    return new AgentDigest(compressionSupplier.get(), timeProvider.currentTimeMillis() + ttlMillis);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy