io.aeron.archive.Archive Java Examples

The following examples show how to use io.aeron.archive.Archive. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeddedRecordingThroughput.java    From aeron with Apache License 2.0 6 votes vote down vote up
public EmbeddedRecordingThroughput()
{
    final String archiveDirName = Archive.Configuration.archiveDirName();
    final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ?
        Samples.createTempDir() : new File(archiveDirName);

    archivingMediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            .spiesSimulateConnection(true)
            .dirDeleteOnStart(true),
        new Archive.Context()
            .recordingEventsEnabled(false)
            .archiveDir(archiveDir));

    aeron = Aeron.connect();

    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .aeron(aeron));
}
 
Example #2
Source File: EmbeddedReplayThroughput.java    From aeron with Apache License 2.0 6 votes vote down vote up
public EmbeddedReplayThroughput()
{
    final String archiveDirName = Archive.Configuration.archiveDirName();
    final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ?
        Samples.createTempDir() : new File(archiveDirName);

    archivingMediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            .dirDeleteOnStart(true),
        new Archive.Context()
            .archiveDir(archiveDir)
            .recordingEventsEnabled(false));

    aeron = Aeron.connect();

    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .aeron(aeron));
}
 
Example #3
Source File: BuyerApplication.java    From artio with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws InterruptedException
{
    System.setProperty(CONTROL_CHANNEL_PROP_NAME, "aeron:udp?endpoint=localhost:9010");
    System.setProperty(CONTROL_RESPONSE_CHANNEL_PROP_NAME, "aeron:udp?endpoint=localhost:9020");

    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(SHARED)
        .dirDeleteOnStart(true)
        .aeronDirectoryName(AERON_DIRECTORY_NAME);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true)
        .aeronDirectoryName(AERON_DIRECTORY_NAME)
        .recordingEventsChannel(RECORDING_EVENTS_CHANNEL);

    try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(context, archiveContext))
    {
        SampleUtil.runAgentUntilSignal(
            new BuyerAgent(),
            driver.mediaDriver());
    }
}
 
Example #4
Source File: AuthenticationTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void launchClusteredMediaDriver(final AuthenticatorSupplier authenticatorSupplier)
{
    clusteredMediaDriver = ClusteredMediaDriver.launch(
        new MediaDriver.Context()
            .warnIfDirectoryExists(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(ClusterTests.errorHandler(0))
            .dirDeleteOnStart(true)
            .dirDeleteOnShutdown(false),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .threadingMode(ArchiveThreadingMode.SHARED)
            .recordingEventsEnabled(false)
            .deleteArchiveOnStart(true),
        new ConsensusModule.Context()
            .errorHandler(ClusterTests.errorHandler(0))
            .authenticatorSupplier(authenticatorSupplier)
            .terminationHook(ClusterTests.TERMINATION_HOOK)
            .deleteDirOnStart(true));
}
 
Example #5
Source File: ClusterNodeRestartTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void launchClusteredMediaDriver(final boolean initialLaunch)
{
    clusteredMediaDriver = ClusteredMediaDriver.launch(
        new MediaDriver.Context()
            .warnIfDirectoryExists(initialLaunch)
            .threadingMode(ThreadingMode.SHARED)
            .termBufferSparseFile(true)
            .errorHandler(ClusterTests.errorHandler(0))
            .dirDeleteOnStart(true),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .recordingEventsEnabled(false)
            .threadingMode(ArchiveThreadingMode.SHARED)
            .deleteArchiveOnStart(initialLaunch),
        new ConsensusModule.Context()
            .errorHandler(ClusterTests.errorHandler(0))
            .terminationHook(terminationLatch::countDown)
            .deleteDirOnStart(initialLaunch));
}
 
Example #6
Source File: ClusterNodeTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void before()
{
    clusteredMediaDriver = ClusteredMediaDriver.launch(
        new MediaDriver.Context()
            .threadingMode(ThreadingMode.SHARED)
            .termBufferSparseFile(true)
            .errorHandler(ClusterTests.errorHandler(0))
            .dirDeleteOnStart(true),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .threadingMode(ArchiveThreadingMode.SHARED)
            .recordingEventsEnabled(false)
            .deleteArchiveOnStart(true),
        new ConsensusModule.Context()
            .errorHandler(ClusterTests.errorHandler(0))
            .terminationHook(ClusterTests.TERMINATION_HOOK)
            .logChannel("aeron:ipc")
            .deleteDirOnStart(true));
}
 
Example #7
Source File: ClusterTimerTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void launchClusteredMediaDriver(final boolean initialLaunch)
{
    clusteredMediaDriver = null;

    clusteredMediaDriver = ClusteredMediaDriver.launch(
        new MediaDriver.Context()
            .warnIfDirectoryExists(initialLaunch)
            .threadingMode(ThreadingMode.SHARED)
            .termBufferSparseFile(true)
            .errorHandler(ClusterTests.errorHandler(0))
            .dirDeleteOnStart(true),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .threadingMode(ArchiveThreadingMode.SHARED)
            .recordingEventsEnabled(false)
            .deleteArchiveOnStart(initialLaunch),
        new ConsensusModule.Context()
            .errorHandler(ClusterTests.errorHandler(0))
            .terminationHook(ClusterTests.TERMINATION_HOOK)
            .deleteDirOnStart(initialLaunch));
}
 
Example #8
Source File: TestFixtures.java    From artio with Apache License 2.0 5 votes vote down vote up
public static ArchivingMediaDriver launchMediaDriver(final MediaDriver.Context context)
{
    final Archive.Context archiveCtx = new Archive.Context()
        .deleteArchiveOnStart(context.dirDeleteOnStart())
        .segmentFileLength(context.ipcTermBufferLength());

    final ArchivingMediaDriver mediaDriver = ArchivingMediaDriver.launch(context, archiveCtx);
    archiveCtx.threadingMode(ArchiveThreadingMode.INVOKER);
    final String aeronDirectoryName = context.aeronDirectoryName();
    CloseChecker.onOpen(aeronDirectoryName, mediaDriver);

    return mediaDriver;
}
 
Example #9
Source File: ArchiveLoggingAgentTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void testArchiveLogging(final String enabledEvents, final EnumSet<ArchiveEventCode> expectedEvents)
    throws InterruptedException
{
    before(enabledEvents, expectedEvents);

    final String aeronDirectoryName = testDir.toPath().resolve("media").toString();

    final MediaDriver.Context mediaDriverCtx = new MediaDriver.Context()
        .errorHandler(Tests::onError)
        .aeronDirectoryName(aeronDirectoryName)
        .dirDeleteOnStart(true)
        .threadingMode(ThreadingMode.SHARED);

    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context()
        .aeronDirectoryName(aeronDirectoryName)
        .controlRequestChannel("aeron:udp?term-length=64k|endpoint=localhost:8010")
        .controlRequestStreamId(100)
        .controlResponseChannel("aeron:udp?term-length=64k|endpoint=localhost:8020")
        .controlResponseStreamId(101)
        .recordingEventsChannel("aeron:udp?control-mode=dynamic|control=localhost:8030");

    final Archive.Context archiveCtx = new Archive.Context()
        .errorHandler(Tests::onError)
        .archiveDir(new File(testDir, "archive"))
        .deleteArchiveOnStart(true)
        .controlChannel(aeronArchiveContext.controlRequestChannel())
        .controlStreamId(aeronArchiveContext.controlRequestStreamId())
        .localControlStreamId(aeronArchiveContext.controlRequestStreamId())
        .recordingEventsChannel(aeronArchiveContext.recordingEventsChannel())
        .threadingMode(ArchiveThreadingMode.SHARED);

    try (ArchivingMediaDriver ignore1 = ArchivingMediaDriver.launch(mediaDriverCtx, archiveCtx))
    {
        try (AeronArchive ignore2 = AeronArchive.connect(aeronArchiveContext))
        {
            latch.await();
        }
    }
}
 
Example #10
Source File: SingleNodeCluster.java    From aeron with Apache License 2.0 5 votes vote down vote up
public SingleNodeCluster(final ClusteredService externalService, final boolean cleanStart)
{
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context();
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context();
    final Archive.Context archiveContext = new Archive.Context();
    final ClusteredServiceContainer.Context serviceContainerContext = new ClusteredServiceContainer.Context();

    final ClusteredService service = null == externalService ? new SingleNodeCluster.Service() : externalService;

    mediaDriverContext
        .threadingMode(ThreadingMode.SHARED)
        .errorHandler(Throwable::printStackTrace)
        .dirDeleteOnShutdown(true)
        .dirDeleteOnStart(true);

    archiveContext
        .recordingEventsEnabled(false)
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(cleanStart);

    consensusModuleContext
        .errorHandler(Throwable::printStackTrace)
        .deleteDirOnStart(cleanStart);

    serviceContainerContext
        .clusteredService(service)
        .errorHandler(Throwable::printStackTrace);

    clusteredMediaDriver = ClusteredMediaDriver.launch(
        mediaDriverContext,
        archiveContext,
        consensusModuleContext);

    container = ClusteredServiceContainer.launch(serviceContainerContext);
}
 
Example #11
Source File: ClusteredMediaDriver.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * 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
            .spiesSimulateConnection(true));

        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.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;
    }
}
 
Example #12
Source File: ClusterBackupMediaDriver.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * 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() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.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 Throwable throwable)
    {
        CloseHelper.quietCloseAll(driver, archive, clusterBackup);
        throw throwable;
    }
}
 
Example #13
Source File: MediaDriverRestartTest.java    From artio with Apache License 2.0 5 votes vote down vote up
private void start(final boolean dirDeleteOnStart)
{
    final MediaDriver.Context context = TestFixtures.mediaDriverContext(
        TestFixtures.TERM_BUFFER_LENGTH, dirDeleteOnStart);
    context.driverTimeoutMs(DRIVER_TIMEOUT_MS);
    context.warnIfDirectoryExists(false);

    mediaDriver = ArchivingMediaDriver.launch(context, new Archive.Context());
    final String aeronDirectoryName = context.aeronDirectoryName();
    CloseChecker.onOpen(aeronDirectoryName, mediaDriver);

    final EngineConfiguration acceptingConfig = acceptingConfig(
        port, ACCEPTOR_ID, INITIATOR_ID);
    acceptingConfig.deleteLogFileDirOnStart(true);
    acceptingConfig.aeronContext().driverTimeoutMs(DRIVER_TIMEOUT_MS);

    acceptingEngine = FixEngine.launch(acceptingConfig);

    delete(CLIENT_LOGS);
    final EngineConfiguration initiatingConfig = initiatingConfig(libraryAeronPort);
    initiatingConfig.aeronContext().driverTimeoutMs(DRIVER_TIMEOUT_MS);
    initiatingEngine = FixEngine.launch(initiatingConfig);

    final LibraryConfiguration acceptingLibraryConfig = acceptingLibraryConfig(acceptingHandler);
    acceptingLibraryConfig.aeronContext().driverTimeoutMs(DRIVER_TIMEOUT_MS);
    acceptingLibrary = connect(acceptingLibraryConfig);

    final LibraryConfiguration configuration = new LibraryConfiguration()
        .sessionAcquireHandler(initiatingHandler)
        .sessionExistsHandler(initiatingHandler)
        .libraryAeronChannels(singletonList("aeron:udp?endpoint=localhost:" + libraryAeronPort));
    configuration.aeronContext().driverTimeoutMs(DRIVER_TIMEOUT_MS);

    initiatingLibrary = connect(configuration);
    testSystem = new TestSystem(acceptingLibrary, initiatingLibrary);

    connectSessions();
}
 
Example #14
Source File: SoleMediaDriver.java    From artio with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args)
{
    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(SHARED)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true);

    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(context, archiveContext))
    {
        StressUtil.awaitKeyPress();
    }
}
 
Example #15
Source File: Server.java    From artio with Apache License 2.0 5 votes vote down vote up
public Server()
{
    final AuthenticationStrategy authenticationStrategy = logon -> true;

    // Static configuration lasts the duration of a FIX-Gateway instance
    final String aeronChannel = "aeron:udp?endpoint=localhost:10000";
    final EngineConfiguration configuration = new EngineConfiguration()
        .bindTo("localhost", StressConfiguration.PORT)
        .logFileDir("stress-server-logs")
        .libraryAeronChannel(aeronChannel)
        .sessionPersistenceStrategy(alwaysPersistent());

    configuration
        .authenticationStrategy(authenticationStrategy)
        .agentNamePrefix("server-");

    System.out.println("Server Logs at " + configuration.logFileDir());

    StressUtil.cleanupOldLogFileDir(configuration);

    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(ThreadingMode.SHARED)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true);

    mediaDriver = ArchivingMediaDriver.launch(context, archiveContext);
    fixEngine = FixEngine.launch(configuration);

    final LibraryConfiguration libraryConfiguration = new LibraryConfiguration();
    libraryConfiguration
        .agentNamePrefix("server-");

    fixLibrary = blockingConnect(libraryConfiguration
        .sessionAcquireHandler((session, acquiredInfo) -> new StressSessionHandler(session))
        .sessionExistsHandler(new AcquiringSessionExistsHandler(true))
        .libraryAeronChannels(singletonList(aeronChannel)));
}
 
Example #16
Source File: ArchivingMediaDriver.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
static ArchivingMediaDriver launchArchiveWithEmbeddedDriver()
{
    MediaDriver driver = null;
    Archive archive = null;
    try
    {
        final MediaDriver.Context driverCtx = new MediaDriver.Context()
            .dirDeleteOnStart(true)
            .spiesSimulateConnection(true);

        driver = MediaDriver.launch(driverCtx);

        final Archive.Context archiveCtx = new Archive.Context()
            .aeronDirectoryName(driverCtx.aeronDirectoryName())
            .deleteArchiveOnStart(true);

        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ?
            new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter();

        final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ?
            driverCtx.errorHandler() : archiveCtx.errorHandler();

        archive = Archive.launch(archiveCtx
            .mediaDriverAgentInvoker(driver.sharedAgentInvoker())
            .aeronDirectoryName(driverCtx.aeronDirectoryName())
            .errorHandler(errorHandler)
            .errorCounter(errorCounter));
        return new ArchivingMediaDriver(driver, archive);
    }
    catch (final Exception ex)
    {
        CloseHelper.quietCloseAll(archive, driver);
        throw ex;
    }
}
 
Example #17
Source File: ExchangeApplication.java    From artio with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception
{
    final MessageValidationStrategy validationStrategy = MessageValidationStrategy.targetCompId(ACCEPTOR_COMP_ID)
        .and(MessageValidationStrategy.senderCompId(Collections.singletonList(INITIATOR_COMP_ID)));

    final AuthenticationStrategy authenticationStrategy = AuthenticationStrategy.of(validationStrategy);

    // Static configuration lasts the duration of a FIX-Gateway instance
    final EngineConfiguration configuration = new EngineConfiguration()
        .bindTo("localhost", 9999)
        .libraryAeronChannel(IPC_CHANNEL);
    configuration.authenticationStrategy(authenticationStrategy);

    cleanupOldLogFileDir(configuration);

    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(SHARED)
        .sharedIdleStrategy(backoffIdleStrategy())
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .idleStrategySupplier(CommonConfiguration::backoffIdleStrategy)
        .deleteArchiveOnStart(true);

    try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(context, archiveContext);
        FixEngine gateway = FixEngine.launch(configuration))
    {
        SampleUtil.runAgentUntilSignal(new ExchangeAgent(), driver.mediaDriver());
    }

    System.exit(0);
}
 
Example #18
Source File: ArchivingMediaDriver.java    From benchmarks with Apache License 2.0 4 votes vote down vote up
private ArchivingMediaDriver(final MediaDriver driver, final Archive archive)
{
    this.driver = driver;
    this.archive = archive;
}
 
Example #19
Source File: ClusterLoggingAgentTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
private void testClusterEventsLogging(
    final String enabledEvents, final EnumSet<ClusterEventCode> expectedEvents) throws InterruptedException
{
    before(enabledEvents, expectedEvents.size());

    final String aeronDirectoryName = testDir.toPath().resolve("media").toString();

    final Context mediaDriverCtx = new Context()
        .errorHandler(Tests::onError)
        .aeronDirectoryName(aeronDirectoryName)
        .dirDeleteOnStart(true)
        .threadingMode(ThreadingMode.SHARED);

    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context()
        .aeronDirectoryName(aeronDirectoryName)
        .controlRequestChannel("aeron:udp?term-length=64k|endpoint=localhost:8010")
        .controlRequestStreamId(100)
        .controlResponseChannel("aeron:udp?term-length=64k|endpoint=localhost:8020")
        .controlResponseStreamId(101)
        .recordingEventsChannel("aeron:udp?control-mode=dynamic|control=localhost:8030");

    final Archive.Context archiveCtx = new Archive.Context()
        .errorHandler(Tests::onError)
        .archiveDir(new File(testDir, "archive"))
        .deleteArchiveOnStart(true)
        .controlChannel(aeronArchiveContext.controlRequestChannel())
        .controlStreamId(aeronArchiveContext.controlRequestStreamId())
        .localControlStreamId(aeronArchiveContext.controlRequestStreamId())
        .recordingEventsChannel(aeronArchiveContext.recordingEventsChannel())
        .threadingMode(ArchiveThreadingMode.SHARED);

    final ConsensusModule.Context consensusModuleCtx = new ConsensusModule.Context()
        .errorHandler(Tests::onError)
        .clusterDir(new File(testDir, "consensus-module"))
        .archiveContext(aeronArchiveContext.clone())
        .clusterMemberId(0)
        .clusterMembers("0,localhost:20110,localhost:20220,localhost:20330,localhost:20440,localhost:8010")
        .logChannel("aeron:udp?term-length=256k|control-mode=manual|control=localhost:20550");

    final ClusteredService clusteredService = mock(ClusteredService.class);
    final ClusteredServiceContainer.Context clusteredServiceCtx = new ClusteredServiceContainer.Context()
        .aeronDirectoryName(aeronDirectoryName)
        .errorHandler(Tests::onError)
        .archiveContext(aeronArchiveContext.clone())
        .clusterDir(new File(testDir, "service"))
        .clusteredService(clusteredService);

    clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverCtx, archiveCtx, consensusModuleCtx);
    container = ClusteredServiceContainer.launch(clusteredServiceCtx);

    latch.await();
    verify(clusteredService, timeout(5000)).onRoleChange(eq(Cluster.Role.LEADER));

    final Set<Integer> expected = expectedEvents
        .stream()
        .map(ClusterEventLogger::toEventCodeId)
        .collect(toSet());

    assertEquals(expected, LOGGED_EVENTS);
}
 
Example #20
Source File: BasicAuctionClusteredServiceNode.java    From aeron with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args)
{
    final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));                // <1>

    final List<String> hostnames = Arrays.asList("localhost", "localhost", "localhost");             // <2>
    final String hostname = hostnames.get(nodeId);

    final File baseDir = new File(System.getProperty("user.dir"), "node" + nodeId);            // <3>
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";

    final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();                               // <4>
    // end::main[]

    // tag::media_driver[]
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context()
        .aeronDirectoryName(aeronDirName)
        .threadingMode(ThreadingMode.SHARED)
        .termBufferSparseFile(true)
        .multicastFlowControlSupplier(new MinMulticastFlowControlSupplier())
        .terminationHook(barrier::signal)
        .errorHandler(BasicAuctionClusteredServiceNode.errorHandler("Media Driver"));
    // end::media_driver[]

    // tag::archive[]
    final Archive.Context archiveContext = new Archive.Context()
        .archiveDir(new File(baseDir, "archive"))
        .controlChannel(udpChannel(nodeId, "localhost", ARCHIVE_CONTROL_REQUEST_PORT_OFFSET))
        .localControlChannel("aeron:ipc?term-length=64k")
        .recordingEventsEnabled(false)
        .threadingMode(ArchiveThreadingMode.SHARED);
    // end::archive[]

    // tag::archive_client[]
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context()
        .controlRequestChannel(archiveContext.controlChannel())
        .controlRequestStreamId(archiveContext.controlStreamId())
        .controlResponseChannel(udpChannel(nodeId, "localhost", ARCHIVE_CONTROL_RESPONSE_PORT_OFFSET))
        .aeronDirectoryName(aeronDirName);
    // end::archive_client[]

    // tag::consensus_module[]
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context()
        .errorHandler(errorHandler("Consensus Module"))
        .clusterMemberId(nodeId)                                                                     // <1>
        .clusterMembers(clusterMembers(hostnames))                                                   // <2>
        .clusterDir(new File(baseDir, "consensus-module"))                                     // <3>
        .ingressChannel("aeron:udp?term-length=64k")                                                 // <4>
        .logChannel(logControlChannel(nodeId, hostname, LOG_CONTROL_PORT_OFFSET))                    // <5>
        .archiveContext(aeronArchiveContext.clone());                                                // <6>
    // end::consensus_module[]

    // tag::clustered_service[]
    final ClusteredServiceContainer.Context clusteredServiceContext =
        new ClusteredServiceContainer.Context()
        .aeronDirectoryName(aeronDirName)                                                            // <1>
        .archiveContext(aeronArchiveContext.clone())                                                 // <2>
        .clusterDir(new File(baseDir, "service"))
        .clusteredService(new BasicAuctionClusteredService())                                        // <3>
        .errorHandler(errorHandler("Clustered Service"));
    // end::clustered_service[]

    // tag::running[]
    try (
        ClusteredMediaDriver clusteredMediaDriver = ClusteredMediaDriver.launch(
            mediaDriverContext, archiveContext, consensusModuleContext);                             // <1>
        ClusteredServiceContainer container = ClusteredServiceContainer.launch(
            clusteredServiceContext))                                                                // <2>
    {
        System.out.println("[" + nodeId + "] Started Cluster Node on " + hostname + "...");
        barrier.await();                                                                             // <3>
        System.out.println("[" + nodeId + "] Exiting");
    }
    // end::running[]
}
 
Example #21
Source File: SampleServer.java    From artio with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args)
{
    final MessageValidationStrategy validationStrategy = MessageValidationStrategy.targetCompId(ACCEPTOR_COMP_ID)
        .and(MessageValidationStrategy.senderCompId(Collections.singletonList(INITIATOR_COMP_ID)));

    final AuthenticationStrategy authenticationStrategy = AuthenticationStrategy.of(validationStrategy);

    // Static configuration lasts the duration of a FIX-Gateway instance
    final String aeronChannel = "aeron:udp?endpoint=localhost:10000";
    final EngineConfiguration configuration = new EngineConfiguration()
        .bindTo("localhost", 9999)
        .libraryAeronChannel(aeronChannel);
    configuration.authenticationStrategy(authenticationStrategy);

    cleanupOldLogFileDir(configuration);

    final Context context = new Context()
        .threadingMode(SHARED)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true);

    try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(context, archiveContext);
        FixEngine gateway = FixEngine.launch(configuration))
    {
        final LibraryConfiguration libraryConfiguration = new LibraryConfiguration();

        // You register the new session handler - which is your application hook
        // that receives messages for new sessions
        libraryConfiguration
            .sessionAcquireHandler((session, acquiredInfo) -> onConnect(session))
            .sessionExistsHandler(new AcquiringSessionExistsHandler())
            .libraryAeronChannels(singletonList(aeronChannel));

        final IdleStrategy idleStrategy = CommonConfiguration.backoffIdleStrategy();

        try (FixLibrary library = SampleUtil.blockingConnect(libraryConfiguration))
        {
            final AtomicBoolean running = new AtomicBoolean(true);
            SigInt.register(() -> running.set(false));

            while (running.get())
            {
                idleStrategy.idle(library.poll(1));

                if (session != null && session.state() == DISCONNECTED)
                {
                    break;
                }
            }
        }
    }

    System.exit(0);
}
 
Example #22
Source File: ArchiveCreator.java    From aeron with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args)
{
    final String archiveDirName = Archive.Configuration.archiveDirName();
    final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ?
        new File("archive") : new File(archiveDirName);

    final MediaDriver.Context driverContext = new MediaDriver.Context()
        .publicationTermBufferLength(TERM_LENGTH)
        .termBufferSparseFile(true)
        .threadingMode(ThreadingMode.SHARED)
        .errorHandler(Throwable::printStackTrace)
        .spiesSimulateConnection(true)
        .dirDeleteOnStart(true);

    final Archive.Context archiveContext = new Archive.Context()
        .maxCatalogEntries(MAX_CATALOG_ENTRIES)
        .segmentFileLength(SEGMENT_LENGTH)
        .deleteArchiveOnStart(true)
        .archiveDir(archiveDir)
        .fileSyncLevel(0)
        .threadingMode(ArchiveThreadingMode.SHARED);

    System.out.println("Creating basic archive at " + archiveContext.archiveDir());

    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverContext, archiveContext);
        Aeron aeron = Aeron.connect();
        AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron)))
    {
        createRecording(
            aeron,
            aeronArchive,
            0,
            (SEGMENT_LENGTH * 5L) + 1);

        createRecording(
            aeron,
            aeronArchive,
            (long)TERM_LENGTH + (FrameDescriptor.FRAME_ALIGNMENT * 2),
            (SEGMENT_LENGTH * 3L) + 1);

    }
    catch (final Exception ex)
    {
        ex.printStackTrace();
    }
}
 
Example #23
Source File: IndexedReplicatedRecording.java    From aeron with Apache License 2.0 4 votes vote down vote up
public IndexedReplicatedRecording()
{
    final String srcAeronDirectoryName = getAeronDirectoryName() + "-src";
    System.out.println("srcAeronDirectoryName=" + srcAeronDirectoryName);
    final String dstAeronDirectoryName = getAeronDirectoryName() + "-dst";
    System.out.println("dstAeronDirectoryName=" + dstAeronDirectoryName);

    final File srcArchiveDir = new File(SystemUtil.tmpDirName(), "src-archive");
    System.out.println("srcArchiveDir=" + srcArchiveDir);
    srcArchivingMediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(srcAeronDirectoryName)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Throwable::printStackTrace)
            .spiesSimulateConnection(true)
            .dirDeleteOnShutdown(true)
            .dirDeleteOnStart(true),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .controlChannel(SRC_CONTROL_REQUEST_CHANNEL)
            .archiveClientContext(new AeronArchive.Context().controlResponseChannel(SRC_CONTROL_RESPONSE_CHANNEL))
            .recordingEventsEnabled(false)
            .replicationChannel(SRC_REPLICATION_CHANNEL)
            .deleteArchiveOnStart(true)
            .archiveDir(srcArchiveDir)
            .fileSyncLevel(0)
            .threadingMode(ArchiveThreadingMode.SHARED));

    final File dstArchiveDir = new File(SystemUtil.tmpDirName(), "dst-archive");
    System.out.println("dstArchiveDir=" + dstArchiveDir);
    dstArchivingMediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(dstAeronDirectoryName)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Throwable::printStackTrace)
            .spiesSimulateConnection(true)
            .dirDeleteOnShutdown(true)
            .dirDeleteOnStart(true),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .controlChannel(DST_CONTROL_REQUEST_CHANNEL)
            .archiveClientContext(new AeronArchive.Context().controlResponseChannel(DST_CONTROL_RESPONSE_CHANNEL))
            .recordingEventsEnabled(false)
            .replicationChannel(DST_REPLICATION_CHANNEL)
            .deleteArchiveOnStart(true)
            .archiveDir(dstArchiveDir)
            .fileSyncLevel(0)
            .threadingMode(ArchiveThreadingMode.SHARED));

    srcAeron = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(srcAeronDirectoryName));

    dstAeron = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(dstAeronDirectoryName));

    srcAeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .idleStrategy(YieldingIdleStrategy.INSTANCE)
            .controlRequestChannel(SRC_CONTROL_REQUEST_CHANNEL)
            .controlResponseChannel(SRC_CONTROL_RESPONSE_CHANNEL)
            .aeron(srcAeron));

    dstAeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .idleStrategy(YieldingIdleStrategy.INSTANCE)
            .controlRequestChannel(DST_CONTROL_REQUEST_CHANNEL)
            .controlResponseChannel(DST_CONTROL_RESPONSE_CHANNEL)
            .aeron(dstAeron));
}
 
Example #24
Source File: StartFromTruncatedRecordingLogTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
private void startNode(final int index, final boolean cleanStart)
{
    final String baseDirName = baseDirName(index);
    final String aeronDirName = aeronDirName(index);

    final AeronArchive.Context archiveCtx = new AeronArchive.Context()
        .controlRequestChannel(memberSpecificPort(ARCHIVE_CONTROL_REQUEST_CHANNEL, index))
        .controlRequestStreamId(100 + index)
        .controlResponseChannel(memberSpecificPort(ARCHIVE_CONTROL_RESPONSE_CHANNEL, index))
        .controlResponseStreamId(110 + index)
        .aeronDirectoryName(baseDirName);

    clusteredMediaDrivers[index] = ClusteredMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(aeronDirName)
            .warnIfDirectoryExists(false)
            .threadingMode(ThreadingMode.SHARED)
            .termBufferSparseFile(true)
            .errorHandler(ClusterTests.errorHandler(index))
            .dirDeleteOnShutdown(false)
            .dirDeleteOnStart(true),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .archiveDir(new File(baseDirName, "archive"))
            .controlChannel(archiveCtx.controlRequestChannel())
            .controlStreamId(archiveCtx.controlRequestStreamId())
            .localControlChannel("aeron:ipc?term-length=64k")
            .localControlStreamId(archiveCtx.controlRequestStreamId())
            .recordingEventsEnabled(false)
            .threadingMode(ArchiveThreadingMode.SHARED)
            .errorHandler(Tests::onError)
            .deleteArchiveOnStart(cleanStart),
        new ConsensusModule.Context()
            .errorHandler(ClusterTests.errorHandler(index))
            .clusterMemberId(index)
            .clusterMembers(CLUSTER_MEMBERS)
            .clusterDir(new File(baseDirName, "consensus-module"))
            .ingressChannel("aeron:udp?term-length=64k")
            .logChannel(memberSpecificPort(LOG_CHANNEL, index))
            .archiveContext(archiveCtx.clone())
            .shouldTerminateWhenClosed(false)
            .deleteDirOnStart(cleanStart));

    containers[index] = ClusteredServiceContainer.launch(
        new ClusteredServiceContainer.Context()
            .aeronDirectoryName(aeronDirName)
            .archiveContext(archiveCtx.clone())
            .clusterDir(new File(baseDirName, "service"))
            .clusteredService(echoServices[index])
            .errorHandler(ClusterTests.errorHandler(index)));
}
 
Example #25
Source File: ArchivingMediaDriver.java    From benchmarks with Apache License 2.0 4 votes vote down vote up
static ArchivingMediaDriver launchArchiveWithStandaloneDriver()
{
    return new ArchivingMediaDriver(null, Archive.launch(new Archive.Context().deleteArchiveOnStart(true)));
}
 
Example #26
Source File: ClusterBackupMediaDriver.java    From aeron with Apache License 2.0 4 votes vote down vote up
ClusterBackupMediaDriver(final MediaDriver driver, final Archive archive, final ClusterBackup clusterBackup)
{
    this.driver = driver;
    this.archive = archive;
    this.clusterBackup = clusterBackup;
}
 
Example #27
Source File: ClusteredMediaDriver.java    From aeron with Apache License 2.0 4 votes vote down vote up
ClusteredMediaDriver(final MediaDriver driver, final Archive archive, final ConsensusModule consensusModule)
{
    this.driver = driver;
    this.archive = archive;
    this.consensusModule = consensusModule;
}
 
Example #28
Source File: ClusterBackupMediaDriver.java    From aeron with Apache License 2.0 2 votes vote down vote up
/**
 * Launch a new {@link ClusterBackupMediaDriver} with default contexts.
 *
 * @return a new {@link ClusterBackupMediaDriver} with default contexts.
 */
public static ClusterBackupMediaDriver launch()
{
    return launch(new MediaDriver.Context(), new Archive.Context(), new ClusterBackup.Context());
}
 
Example #29
Source File: ClusteredMediaDriver.java    From aeron with Apache License 2.0 2 votes vote down vote up
/**
 * Get the {@link Archive} used in the aggregate.
 *
 * @return the {@link Archive} used in the aggregate.
 */
public Archive archive()
{
    return archive;
}
 
Example #30
Source File: ClusteredMediaDriver.java    From aeron with Apache License 2.0 2 votes vote down vote up
/**
 * Launch a new {@link ClusteredMediaDriver} with default contexts.
 *
 * @return a new {@link ClusteredMediaDriver} with default contexts.
 */
public static ClusteredMediaDriver launch()
{
    return launch(new MediaDriver.Context(), new Archive.Context(), new ConsensusModule.Context());
}