use of com.hazelcast.internal.metrics.DoubleProbeFunction in project hazelcast by hazelcast.
the class DoubleGaugeImpl method read.
@Override
public double read() {
ProbeInstance probeInstance = getProbeInstance();
ProbeFunction function = null;
Object source = null;
if (probeInstance != null) {
function = probeInstance.function;
source = probeInstance.source;
}
if (function == null || source == null) {
clearProbeInstance();
return DEFAULT_VALUE;
}
try {
if (function instanceof LongProbeFunction) {
LongProbeFunction longFunction = (LongProbeFunction) function;
return longFunction.get(source);
} else {
DoubleProbeFunction doubleFunction = (DoubleProbeFunction) function;
return doubleFunction.get(source);
}
} catch (Exception e) {
metricsRegistry.logger.warning("Failed to access probe:" + name, e);
return DEFAULT_VALUE;
}
}
use of com.hazelcast.internal.metrics.DoubleProbeFunction in project hazelcast by hazelcast.
the class LongGaugeImpl method read.
@Override
public long read() {
ProbeInstance probeInstance = getProbeInstance();
ProbeFunction function = null;
Object source = null;
if (probeInstance != null) {
function = probeInstance.function;
source = probeInstance.source;
}
if (function == null || source == null) {
clearProbeInstance();
return DEFAULT_VALUE;
}
try {
if (function instanceof LongProbeFunction) {
LongProbeFunction longFunction = (LongProbeFunction) function;
return longFunction.get(source);
} else {
DoubleProbeFunction doubleFunction = (DoubleProbeFunction) function;
double doubleResult = doubleFunction.get(source);
return Math.round(doubleResult);
}
} catch (Exception e) {
metricsRegistry.logger.warning("Failed to access probe:" + name, e);
return DEFAULT_VALUE;
}
}
use of com.hazelcast.internal.metrics.DoubleProbeFunction in project hazelcast by hazelcast.
the class MetricsRegistryImpl method render.
private void render(ProbeRenderer renderer, ProbeInstance probeInstance) {
ProbeFunction function = probeInstance.function;
Object source = probeInstance.source;
String name = probeInstance.name;
if (function == null || source == null) {
renderer.renderNoValue(name);
return;
}
try {
if (function instanceof LongProbeFunction) {
LongProbeFunction longFunction = (LongProbeFunction) function;
renderer.renderLong(name, longFunction.get(source));
} else {
DoubleProbeFunction doubleFunction = (DoubleProbeFunction) function;
renderer.renderDouble(name, doubleFunction.get(source));
}
} catch (Exception e) {
renderer.renderException(name, e);
}
}
use of com.hazelcast.internal.metrics.DoubleProbeFunction in project hazelcast by hazelcast.
the class DoubleGaugeImplTest method whenDoubleProbe.
@Test
public void whenDoubleProbe() {
metricsRegistry.register(this, "foo", MANDATORY, new DoubleProbeFunction() {
@Override
public double get(Object o) {
return 10;
}
});
DoubleGauge gauge = metricsRegistry.newDoubleGauge("foo");
double actual = gauge.read();
assertEquals(10, actual, 0.1);
}
use of com.hazelcast.internal.metrics.DoubleProbeFunction in project hazelcast by hazelcast.
the class DoubleGaugeImplTest method whenProbeThrowsException.
@Test
public void whenProbeThrowsException() {
metricsRegistry.register(this, "foo", MANDATORY, new DoubleProbeFunction() {
@Override
public double get(Object o) {
throw new RuntimeException();
}
});
DoubleGauge gauge = metricsRegistry.newDoubleGauge("foo");
double actual = gauge.read();
assertEquals(0, actual, 0.1);
}
Aggregations