use of com.hazelcast.internal.metrics.LongProbeFunction 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.LongProbeFunction 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.LongProbeFunction 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.LongProbeFunction in project hazelcast by hazelcast.
the class DiagnosticsLogTest method testRollover.
@Test
public void testRollover() {
String id = generateRandomString(10000);
final List<File> files = new LinkedList<File>();
LongProbeFunction f = new LongProbeFunction() {
@Override
public long get(Object source) throws Exception {
return 0;
}
};
for (int k = 0; k < 10; k++) {
metricsRegistry.register(this, id + k, ProbeLevel.MANDATORY, f);
}
// we run for some time to make sure we get enough rollovers.
while (files.size() < 3) {
final File file = diagnosticsLogFile.file;
if (file != null) {
if (!files.contains(file)) {
files.add(file);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertExist(file);
}
});
}
sleepMillis(100);
}
// eventually all these files should be gone.
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (File file : files) {
assertNotExist(file);
}
}
});
}
use of com.hazelcast.internal.metrics.LongProbeFunction in project hazelcast by hazelcast.
the class LongGaugeImplTest method whenProbeThrowsException.
@Test
public void whenProbeThrowsException() {
metricsRegistry.register(this, "foo", MANDATORY, new LongProbeFunction() {
@Override
public long get(Object o) {
throw new RuntimeException();
}
});
LongGauge gauge = metricsRegistry.newLongGauge("foo");
long actual = gauge.read();
assertEquals(0, actual);
}
Aggregations