Search in sources :

Example 1 with AbstractRunnable

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;
}
Also used : AbstractRunnable(org.spf4j.base.AbstractRunnable)

Example 2 with AbstractRunnable

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();
            }
        }
    });
}
Also used : AbstractRunnable(org.spf4j.base.AbstractRunnable)

Example 3 with AbstractRunnable

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);
    }
}
Also used : AbstractRunnable(org.spf4j.base.AbstractRunnable) MeasurementRecorder(org.spf4j.perf.MeasurementRecorder) JmxExport(org.spf4j.jmx.JmxExport)

Example 4 with AbstractRunnable

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);
    }
}
Also used : AbstractRunnable(org.spf4j.base.AbstractRunnable) TObjectLongHashMap(gnu.trove.map.hash.TObjectLongHashMap) MeasurementRecorder(org.spf4j.perf.MeasurementRecorder) TObjectLongMap(gnu.trove.map.TObjectLongMap) JmxExport(org.spf4j.jmx.JmxExport)

Example 5 with AbstractRunnable

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();
}
Also used : AbstractRunnable(org.spf4j.base.AbstractRunnable) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

AbstractRunnable (org.spf4j.base.AbstractRunnable)16 IOException (java.io.IOException)6 JmxExport (org.spf4j.jmx.JmxExport)4 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 MeasurementRecorder (org.spf4j.perf.MeasurementRecorder)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Test (org.junit.Test)2 TObjectLongMap (gnu.trove.map.TObjectLongMap)1 TObjectLongHashMap (gnu.trove.map.hash.TObjectLongHashMap)1 File (java.io.File)1 UncheckedIOException (java.io.UncheckedIOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 DatagramChannel (java.nio.channels.DatagramChannel)1 ArrayList (java.util.ArrayList)1 ForkJoinPool (java.util.concurrent.ForkJoinPool)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 BeforeClass (org.junit.BeforeClass)1