com.signalfx.codahale.metrics.SettableDoubleGauge Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signalfx-codahale Show documentation
Show all versions of signalfx-codahale Show documentation
Dropwizard Codahale metrics plugin for signalfx
The newest version!
package com.signalfx.codahale.metrics;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Metric;
/**
*
* Works like a Gauge, but rather than getting its value from a callback, the value
* is set when needed. This can be somewhat convienent, but direct use of a Gauge is likely better
*
*
* Usage example:
*
{@code
* MetricRegister metricRegistry;
* SettableDoubleGauge settable = metricRegistry.register("metric.name", new SettableDoubleGauge());
* // ...
* settable.setValue(1.234);
* // ...
* settable.setValue(3.156);
* }
*
*/
public class SettableDoubleGauge implements Metric, Gauge {
/**
* Current value. Assignment will be atomic. See 17.7
*/
private volatile double value;
/**
* Set the current value the {@link Gauge} will return to something else.
* @param value last set value
* @return itself
*/
public SettableDoubleGauge setValue(double value) {
this.value = value;
return this;
}
/**
* The last value set by {@link #setValue(double)}}
* @return Last set value, or zero.
*/
public Double getValue() {
return value;
}
public final static class Builder implements MetricBuilder {
public static final Builder INSTANCE = new Builder();
private Builder() {
}
@Override
public SettableDoubleGauge newMetric() {
return new SettableDoubleGauge();
}
@Override
public boolean isInstance(Metric metric) {
return metric instanceof SettableDoubleGauge;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy