com.codahale.metrics.CachedGauge Java Examples

The following examples show how to use com.codahale.metrics.CachedGauge. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CachedHistogram.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * Exposed for testing.
 * @param clock the {@link Clock} to use for the {@link CachedGauge}.
 * @param reservoir the {@link Reservoir} to use for the histogram.
 * @param timeoutMs the timeout for the value stored in the cache in milliseconds. After this time has passed, a new
 *                  value of the histogram at {@code quantile} will be calculated.
 * @param quantile the quantile of the histogram to cache.
 */
CachedHistogram(Clock clock, Reservoir reservoir, long timeoutMs, double quantile) {
  super(reservoir);
  cache = new CachedGauge<Double>(clock, timeoutMs, TimeUnit.MILLISECONDS) {
    @Override
    protected Double loadValue() {
      return getSnapshot().getValue(quantile);
    }
  };
}