Search in sources :

Example 11 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class ClusteredMediaDriver method launch.

/**
 * Launch a new {@link ClusteredMediaDriver} with provided contexts.
 *
 * @param driverCtx          for configuring the {@link MediaDriver}.
 * @param archiveCtx         for configuring the {@link Archive}.
 * @param consensusModuleCtx for the configuration of the {@link ConsensusModule}.
 * @return a new {@link ClusteredMediaDriver} with the provided contexts.
 */
public static ClusteredMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx, final ConsensusModule.Context consensusModuleCtx) {
    MediaDriver driver = null;
    Archive archive = null;
    ConsensusModule consensusModule = null;
    try {
        driver = MediaDriver.launch(driverCtx);
        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId);
        final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? archiveCtx.errorHandler() : driverCtx.errorHandler();
        archive = Archive.launch(archiveCtx.mediaDriverAgentInvoker(driver.sharedAgentInvoker()).aeronDirectoryName(driver.aeronDirectoryName()).errorHandler(errorHandler).errorCounter(errorCounter));
        consensusModule = ConsensusModule.launch(consensusModuleCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()));
        return new ClusteredMediaDriver(driver, archive, consensusModule);
    } catch (final Exception ex) {
        CloseHelper.quietCloseAll(consensusModule, archive, driver);
        throw ex;
    }
}
Also used : ErrorHandler(org.agrona.ErrorHandler) Archive(io.aeron.archive.Archive) MediaDriver(io.aeron.driver.MediaDriver) AtomicCounter(org.agrona.concurrent.status.AtomicCounter)

Example 12 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class ClusterBackupMediaDriver method launch.

/**
 * Launch a new {@link ClusterBackupMediaDriver} with provided contexts.
 *
 * @param driverCtx        for configuring the {@link MediaDriver}.
 * @param archiveCtx       for configuring the {@link Archive}.
 * @param clusterBackupCtx for the configuration of the {@link ClusterBackup}.
 * @return a new {@link ClusterBackupMediaDriver} with the provided contexts.
 */
public static ClusterBackupMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx, final ClusterBackup.Context clusterBackupCtx) {
    MediaDriver driver = null;
    Archive archive = null;
    ClusterBackup clusterBackup = null;
    try {
        driver = MediaDriver.launch(driverCtx.spiesSimulateConnection(true));
        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId);
        final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? archiveCtx.errorHandler() : driverCtx.errorHandler();
        archive = Archive.launch(archiveCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()).mediaDriverAgentInvoker(driver.sharedAgentInvoker()).errorHandler(errorHandler).errorCounter(errorCounter));
        clusterBackup = ClusterBackup.launch(clusterBackupCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()));
        return new ClusterBackupMediaDriver(driver, archive, clusterBackup);
    } catch (final Exception ex) {
        CloseHelper.quietCloseAll(clusterBackup, archive, driver);
        throw ex;
    }
}
Also used : ErrorHandler(org.agrona.ErrorHandler) Archive(io.aeron.archive.Archive) MediaDriver(io.aeron.driver.MediaDriver) AtomicCounter(org.agrona.concurrent.status.AtomicCounter)

Example 13 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class RateSubscriber method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 * @throws InterruptedException if the task is interrupted
 * @throws ExecutionException if the {@link Future} has an error.
 */
public static void main(final String[] args) throws InterruptedException, ExecutionException {
    System.out.println("Subscribing to " + CHANNEL + " on stream id " + STREAM_ID);
    final MediaDriver driver = EMBEDDED_MEDIA_DRIVER ? MediaDriver.launchEmbedded() : null;
    final ExecutorService executor = Executors.newFixedThreadPool(1);
    final Aeron.Context ctx = new Aeron.Context().availableImageHandler(SamplesUtil::printAvailableImage).unavailableImageHandler(SamplesUtil::printUnavailableImage);
    if (EMBEDDED_MEDIA_DRIVER) {
        ctx.aeronDirectoryName(driver.aeronDirectoryName());
    }
    final RateReporter reporter = new RateReporter(TimeUnit.SECONDS.toNanos(1), SamplesUtil::printRate);
    final AtomicBoolean running = new AtomicBoolean(true);
    SigInt.register(() -> {
        reporter.halt();
        running.set(false);
    });
    try (Aeron aeron = Aeron.connect(ctx);
        Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) {
        final Future<?> future = executor.submit(() -> SamplesUtil.subscriberLoop(rateReporterHandler(reporter), FRAGMENT_COUNT_LIMIT, running).accept(subscription));
        reporter.run();
        System.out.println("Shutting down...");
        future.get();
    }
    executor.shutdown();
    if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
        System.out.println("Warning: not all tasks completed promptly");
    }
    CloseHelper.close(driver);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaDriver(io.aeron.driver.MediaDriver) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron)

Example 14 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class LowLatencyMediaDriver method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process which will be used for loading properties files.
 */
@SuppressWarnings("try")
public static void main(final String[] args) {
    loadPropertiesFiles(args);
    final MediaDriver.Context ctx = new MediaDriver.Context().termBufferSparseFile(false).useWindowsHighResTimer(true).threadingMode(ThreadingMode.DEDICATED).conductorIdleStrategy(BusySpinIdleStrategy.INSTANCE).receiverIdleStrategy(NoOpIdleStrategy.INSTANCE).senderIdleStrategy(NoOpIdleStrategy.INSTANCE);
    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)

Example 15 with MediaDriver

use of io.aeron.driver.MediaDriver in project Aeron by real-logic.

the class Pong method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
public static void main(final String[] args) {
    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);
    System.out.println("Using exclusive publications " + EXCLUSIVE_PUBLICATIONS);
    final AtomicBoolean running = new AtomicBoolean(true);
    SigInt.register(() -> running.set(false));
    try (Aeron aeron = Aeron.connect(ctx);
        Subscription subscription = aeron.addSubscription(PING_CHANNEL, PING_STREAM_ID);
        Publication publication = EXCLUSIVE_PUBLICATIONS ? aeron.addExclusivePublication(PONG_CHANNEL, PONG_STREAM_ID) : aeron.addPublication(PONG_CHANNEL, PONG_STREAM_ID)) {
        final BufferClaim bufferClaim = new BufferClaim();
        final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> pingHandler(bufferClaim, publication, buffer, offset, length, header);
        while (running.get()) {
            idleStrategy.idle(subscription.poll(fragmentHandler, FRAME_COUNT_LIMIT));
        }
        System.out.println("Shutting down...");
    }
    CloseHelper.close(driver);
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) Aeron(io.aeron.Aeron) Subscription(io.aeron.Subscription) io.aeron.logbuffer(io.aeron.logbuffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Publication(io.aeron.Publication) CloseHelper(org.agrona.CloseHelper) SigInt(org.agrona.concurrent.SigInt) DirectBuffer(org.agrona.DirectBuffer) BusySpinIdleStrategy(org.agrona.concurrent.BusySpinIdleStrategy) IdleStrategy(org.agrona.concurrent.IdleStrategy) BusySpinIdleStrategy(org.agrona.concurrent.BusySpinIdleStrategy) IdleStrategy(org.agrona.concurrent.IdleStrategy) Publication(io.aeron.Publication) Aeron(io.aeron.Aeron) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaDriver(io.aeron.driver.MediaDriver) BusySpinIdleStrategy(org.agrona.concurrent.BusySpinIdleStrategy) Subscription(io.aeron.Subscription)

Aggregations

MediaDriver (io.aeron.driver.MediaDriver)59 Aeron (io.aeron.Aeron)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)22 Subscription (io.aeron.Subscription)13 FragmentHandler (io.aeron.logbuffer.FragmentHandler)11 ContinueBarrier (org.agrona.console.ContinueBarrier)11 Test (org.junit.jupiter.api.Test)10 Publication (io.aeron.Publication)9 IdleStrategy (org.agrona.concurrent.IdleStrategy)9 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)9 InterruptAfter (io.aeron.test.InterruptAfter)8 ExecutorService (java.util.concurrent.ExecutorService)8 BusySpinIdleStrategy (org.agrona.concurrent.BusySpinIdleStrategy)8 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)7 Archive (io.aeron.archive.Archive)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Tests (io.aeron.test.Tests)5 DirectBuffer (org.agrona.DirectBuffer)5 CommonContext (io.aeron.CommonContext)4 File (java.io.File)4