Search in sources :

Example 1 with BusySpinIdleStrategy

use of org.agrona.concurrent.BusySpinIdleStrategy in project Aeron by real-logic.

the class LowLatencyMediaDriver method main.

public static void main(final String[] args) throws Exception {
    MediaDriver.loadPropertiesFiles(args);
    final MediaDriver.Context ctx = new MediaDriver.Context().termBufferSparseFile(false).threadingMode(ThreadingMode.DEDICATED).conductorIdleStrategy(new BusySpinIdleStrategy()).receiverIdleStrategy(new BusySpinIdleStrategy()).senderIdleStrategy(new BusySpinIdleStrategy());
    try (MediaDriver ignored = MediaDriver.launch(ctx)) {
        new ShutdownSignalBarrier().await();
        System.out.println("Shutdown Driver...");
    }
}
Also used : ShutdownSignalBarrier(org.agrona.concurrent.ShutdownSignalBarrier) MediaDriver(io.aeron.driver.MediaDriver) BusySpinIdleStrategy(org.agrona.concurrent.BusySpinIdleStrategy)

Example 2 with BusySpinIdleStrategy

use of org.agrona.concurrent.BusySpinIdleStrategy in project Aeron by real-logic.

the class Pong method main.

public static void main(final String[] args) throws Exception {
    final MediaDriver driver = EMBEDDED_MEDIA_DRIVER ? MediaDriver.launchEmbedded() : null;
    final Aeron.Context ctx = new Aeron.Context();
    if (EMBEDDED_MEDIA_DRIVER) {
        ctx.aeronDirectoryName(driver.aeronDirectoryName());
    }
    if (INFO_FLAG) {
        ctx.availableImageHandler(SamplesUtil::printAvailableImage);
        ctx.unavailableImageHandler(SamplesUtil::printUnavailableImage);
    }
    final IdleStrategy idleStrategy = new BusySpinIdleStrategy();
    System.out.println("Subscribing Ping at " + PING_CHANNEL + " on stream Id " + PING_STREAM_ID);
    System.out.println("Publishing Pong at " + PONG_CHANNEL + " on stream Id " + PONG_STREAM_ID);
    final AtomicBoolean running = new AtomicBoolean(true);
    SigInt.register(() -> running.set(false));
    try (Aeron aeron = Aeron.connect(ctx);
        Publication pongPublication = aeron.addPublication(PONG_CHANNEL, PONG_STREAM_ID);
        Subscription pingSubscription = aeron.addSubscription(PING_CHANNEL, PING_STREAM_ID)) {
        final FragmentAssembler dataHandler = new FragmentAssembler((buffer, offset, length, header) -> pingHandler(pongPublication, buffer, offset, length));
        while (running.get()) {
            idleStrategy.idle(pingSubscription.poll(dataHandler, FRAME_COUNT_LIMIT));
        }
        System.out.println("Shutting down...");
    }
    CloseHelper.quietClose(driver);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaDriver(io.aeron.driver.MediaDriver) BusySpinIdleStrategy(org.agrona.concurrent.BusySpinIdleStrategy) IdleStrategy(org.agrona.concurrent.IdleStrategy) BusySpinIdleStrategy(org.agrona.concurrent.BusySpinIdleStrategy) Publication(io.aeron.Publication) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron) FragmentAssembler(io.aeron.FragmentAssembler)

Aggregations

MediaDriver (io.aeron.driver.MediaDriver)2 BusySpinIdleStrategy (org.agrona.concurrent.BusySpinIdleStrategy)2 Aeron (io.aeron.Aeron)1 FragmentAssembler (io.aeron.FragmentAssembler)1 Publication (io.aeron.Publication)1 Subscription (io.aeron.Subscription)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IdleStrategy (org.agrona.concurrent.IdleStrategy)1 ShutdownSignalBarrier (org.agrona.concurrent.ShutdownSignalBarrier)1