use of org.spf4j.base.AbstractRunnable in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorder method closeOnShutdown.
private Runnable closeOnShutdown() {
final AbstractRunnable runnable = new AbstractRunnable(true) {
@Override
public void doRun() {
close();
}
};
org.spf4j.base.Runtime.queueHook(0, runnable);
return runnable;
}
use of org.spf4j.base.AbstractRunnable in project spf4j by zolyfarkas.
the class Flusher method flushEvery.
public static void flushEvery(final int intervalMillis, final MeasurementStore store) {
final ScheduledFuture<?> future = DefaultScheduler.INSTANCE.scheduleAtFixedRate(new AbstractRunnable(false) {
@Override
public void doRun() throws Exception {
store.flush();
}
}, intervalMillis, intervalMillis, TimeUnit.MILLISECONDS);
org.spf4j.base.Runtime.queueHookAtEnd(new AbstractRunnable(false) {
@Override
public void doRun() throws Exception {
try {
future.cancel(false);
} finally {
store.close();
}
}
});
}
use of org.spf4j.base.AbstractRunnable in project spf4j by zolyfarkas.
the class CpuUsageSampler method start.
@JmxExport
public static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime) {
if (samplingFuture == null) {
final MeasurementRecorder cpuUsage = RecorderFactory.createDirectRecorder("cpu-time", "ns", sampleTime);
samplingFuture = DefaultScheduler.INSTANCE.scheduleWithFixedDelay(new AbstractRunnable() {
private long lastValue = 0;
@Override
public void doRun() {
long currTime = getProcessCpuTimeNanos();
cpuUsage.record(currTime - lastValue);
lastValue = currTime;
}
}, sampleTime, sampleTime, TimeUnit.MILLISECONDS);
} else {
throw new IllegalStateException("Cpu time Sampling already started " + samplingFuture);
}
}
use of org.spf4j.base.AbstractRunnable in project spf4j by zolyfarkas.
the class GCUsageSampler method start.
@JmxExport
public static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime) {
if (samplingFuture == null) {
final MeasurementRecorder gcUsage = RecorderFactory.createDirectRecorder("gc-time", "ms", sampleTime);
samplingFuture = DefaultScheduler.INSTANCE.scheduleWithFixedDelay(new AbstractRunnable() {
private final TObjectLongMap lastValues = new TObjectLongHashMap();
@Override
public void doRun() {
synchronized (lastValues) {
gcUsage.record(getGCTimeDiff(MBEANS, lastValues));
}
}
}, sampleTime, sampleTime, TimeUnit.MILLISECONDS);
} else {
throw new IllegalStateException("GC usage sampling already started " + samplingFuture);
}
}
use of org.spf4j.base.AbstractRunnable in project spf4j by zolyfarkas.
the class NetworkMonitorAspectTest method testNetworkUsageRecording.
/**
* Test of nioReadLong method, of class NetworkMonitorAspect.
*/
@Test
public void testNetworkUsageRecording() throws InterruptedException, IOException, ExecutionException, TimeoutException {
System.setProperty("spf4j.perf.network.sampleTimeMillis", "1000");
Future<String> serverFuture = DefaultExecutor.INSTANCE.submit(new AbstractRunnable() {
@Override
public void doRun() throws IOException {
runServer();
}
}, "server");
if (!latch.await(10, TimeUnit.SECONDS)) {
serverFuture.get(1, TimeUnit.SECONDS);
throw new IOException("Unable to start server in " + 10 + "seconds" + serverFuture);
}
for (int i = 0; i < 100; i++) {
clientTest();
Thread.sleep(100);
}
terminated = true;
clientTest();
serverFuture.get();
}
Aggregations