io.aeron.driver.ThreadingMode Java Examples

The following examples show how to use io.aeron.driver.ThreadingMode. 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: LowLatencyMediaDriver.java    From rpc-bench with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("checkstyle:UncommentedMain")
public static void main(final String... args) {
  MediaDriver.loadPropertiesFiles(args);

  setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true");
  setProperty("aeron.mtu.length", "16384");
  setProperty("aeron.socket.so_sndbuf", "2097152");
  setProperty("aeron.socket.so_rcvbuf", "2097152");
  setProperty("aeron.rcv.initial.window.length", "2097152");

  final MediaDriver.Context ctx = new MediaDriver.Context()
      .threadingMode(ThreadingMode.DEDICATED)
      .dirsDeleteOnStart(true)
      .termBufferSparseFile(false)
      .conductorIdleStrategy(new BusySpinIdleStrategy())
      .receiverIdleStrategy(new BusySpinIdleStrategy())
      .senderIdleStrategy(new BusySpinIdleStrategy());

  try (MediaDriver ignored = MediaDriver.launch(ctx)) {
    new SigIntBarrier().await();

  }
}
 
Example #2
Source File: PongTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void before()
{
    driver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .errorHandler(Tests::onError)
            .publicationTermBufferLength(LogBufferDescriptor.TERM_MIN_LENGTH)
            .threadingMode(ThreadingMode.SHARED),
        testWatcher);

    pingClient = Aeron.connect();
    pongClient = Aeron.connect();

    pingSubscription = pongClient.addSubscription(PING_URI, PING_STREAM_ID);
    pingPublication = pingClient.addPublication(PING_URI, PING_STREAM_ID);

    pongSubscription = pingClient.addSubscription(PONG_URI, PONG_STREAM_ID);
    pongPublication = pongClient.addPublication(PONG_URI, PONG_STREAM_ID);
}
 
Example #3
Source File: SpecifiedPositionPublicationTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRejectSpecifiedPositionForConcurrentPublications()
{
    final ErrorHandler mockErrorHandler = mock(ErrorHandler.class);
    final MediaDriver.Context context = new MediaDriver.Context()
        .errorHandler(mockErrorHandler)
        .dirDeleteOnStart(true)
        .publicationTermBufferLength(LogBufferDescriptor.TERM_MIN_LENGTH)
        .threadingMode(ThreadingMode.SHARED);

    try (TestMediaDriver ignore = TestMediaDriver.launch(context, testWatcher);
        Aeron aeron = Aeron.connect())
    {
        final String channel = new ChannelUriStringBuilder()
            .media("ipc")
            .initialPosition(1024, -873648623, 65536)
            .build();

        assertThrows(RegistrationException.class, () -> aeron.addPublication(channel, 1001));
    }
    finally
    {
        context.deleteDirectory();
    }
}
 
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: MultiDestinationCastTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void launch()
{
    final String baseDirA = ROOT_DIR + "A";
    final String baseDirB = ROOT_DIR + "B";

    buffer.putInt(0, 1);

    final MediaDriver.Context driverAContext = new MediaDriver.Context()
        .errorHandler(Tests::onError)
        .publicationTermBufferLength(TERM_BUFFER_LENGTH)
        .aeronDirectoryName(baseDirA)
        .threadingMode(ThreadingMode.SHARED);

    driverBContext.publicationTermBufferLength(TERM_BUFFER_LENGTH)
        .errorHandler(Tests::onError)
        .aeronDirectoryName(baseDirB)
        .threadingMode(ThreadingMode.SHARED);

    driverA = TestMediaDriver.launch(driverAContext, testWatcher);
    driverB = TestMediaDriver.launch(driverBContext, testWatcher);
    clientA = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverAContext.aeronDirectoryName()));
    clientB = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverBContext.aeronDirectoryName()));
}
 
Example #6
Source File: NameReResolutionTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void before()
{
    final MediaDriver.Context context = new MediaDriver.Context()
        .publicationTermBufferLength(LogBufferDescriptor.TERM_MIN_LENGTH)
        .dirDeleteOnStart(true)
        .dirDeleteOnShutdown(true)
        .threadingMode(ThreadingMode.SHARED);

    TestMediaDriver.enableCsvNameLookupConfiguration(context, STUB_LOOKUP_CONFIGURATION);

    driver = TestMediaDriver.launch(context, testWatcher);

    client = Aeron.connect();
    countersReader = client.countersReader();
}
 
Example #7
Source File: EmbeddedPingPong.java    From aeron with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception
{
    loadPropertiesFiles(args);

    final MediaDriver.Context ctx = new MediaDriver.Context()
        .threadingMode(ThreadingMode.DEDICATED)
        .conductorIdleStrategy(new BackoffIdleStrategy(1, 1, 1000, 1000))
        .receiverIdleStrategy(NoOpIdleStrategy.INSTANCE)
        .senderIdleStrategy(NoOpIdleStrategy.INSTANCE);

    try (MediaDriver ignored = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect())
    {
        final Thread pongThread = startPong(aeron);
        pongThread.start();

        runPing(aeron);
        RUNNING.set(false);
        pongThread.join();

        System.out.println("Shutdown Driver...");
    }
}
 
Example #8
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 #9
Source File: SingleNodeCluster.java    From aeron with Apache License 2.0 6 votes vote down vote up
void connectClientToCluster()
{
    final String aeronDirectoryName = CommonContext.getAeronDirectoryName() + "-client";

    clientMediaDriver = MediaDriver.launch(
        new MediaDriver.Context()
            .threadingMode(ThreadingMode.SHARED)
            .dirDeleteOnStart(true)
            .dirDeleteOnShutdown(true)
            .errorHandler(Throwable::printStackTrace)
            .aeronDirectoryName(aeronDirectoryName));

    client = AeronCluster.connect(
        new AeronCluster.Context()
            .errorHandler(Throwable::printStackTrace)
            .egressListener(egressMessageListener)
            .aeronDirectoryName(aeronDirectoryName));
}
 
Example #10
Source File: LowLatencyMediaDriver.java    From aeron with Apache License 2.0 6 votes vote down vote up
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...");
    }
}
 
Example #11
Source File: MultiModuleSharedDriverTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
MultiClusterNode(final int nodeId)
{
    this.nodeId = nodeId;

    final MediaDriver.Context driverCtx = new MediaDriver.Context()
        .aeronDirectoryName(CommonContext.getAeronDirectoryName() + "-" + nodeId)
        .threadingMode(ThreadingMode.SHARED)
        .errorHandler(Tests::onError)
        .dirDeleteOnStart(true);

    final Archive.Context archiveCtx = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .archiveDir(new File(SystemUtil.tmpDirName(), "archive-" + nodeId))
        .controlChannel("aeron:udp?endpoint=localhost:801" + nodeId)
        .errorHandler(Tests::onError)
        .recordingEventsEnabled(false)
        .deleteArchiveOnStart(true);

    archivingMediaDriver = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
    consensusModule0 = consensusModule(0, driverCtx.aeronDirectoryName());
    container0 = container(consensusModule0.context());
    consensusModule1 = consensusModule(1, driverCtx.aeronDirectoryName());
    container1 = container(consensusModule1.context());
}
 
Example #12
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 #13
Source File: AeronUtil.java    From nd4j with Apache License 2.0 6 votes vote down vote up
/**
 * Get a media driver context
 * for sending ndarrays
 * based on a given length
 * where length is the length (number of elements)
 * in the ndarrays hat are being sent
 * @param length the length to based the ipc length
 * @return the media driver context based on the given length
 */
public static MediaDriver.Context getMediaDriverContext(int length) {
    //length of array * sizeof(float)
    int ipcLength = length * 16;
    //padding for NDArrayMessage
    ipcLength += 64;
    //must be a power of 2
    ipcLength *= 2;
    //ipc length must be positive power of 2
    while (!BitUtil.isPowerOfTwo(ipcLength))
        ipcLength += 2;
    // System.setProperty("aeron.term.buffer.size",String.valueOf(ipcLength));
    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
                                    /*  .ipcTermBufferLength(ipcLength)
                                      .publicationTermBufferLength(ipcLength)
                                      .maxTermBufferLength(ipcLength)*/
                                    .conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());
    return ctx;
}
 
Example #14
Source File: ArchiveAuthenticationTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void launchArchivingMediaDriver(final AuthenticatorSupplier authenticatorSupplier)
{
    mediaDriver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(aeronDirectoryName)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Tests::onError)
            .spiesSimulateConnection(false)
            .dirDeleteOnStart(true),
        testWatcher);

    archive = Archive.launch(
        new Archive.Context()
            .maxCatalogEntries(Common.MAX_CATALOG_ENTRIES)
            .aeronDirectoryName(aeronDirectoryName)
            .deleteArchiveOnStart(true)
            .archiveDir(new File(SystemUtil.tmpDirName(), "archive"))
            .fileSyncLevel(0)
            .authenticatorSupplier(authenticatorSupplier)
            .threadingMode(ArchiveThreadingMode.SHARED));
}
 
Example #15
Source File: LowLatencyMediaDriver.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("checkstyle:UncommentedMain")
public static void main(final String... args) {
    MediaDriver.loadPropertiesFiles(args);

    setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true");
    setProperty("aeron.mtu.length", "16384");
    setProperty("aeron.socket.so_sndbuf", "2097152");
    setProperty("aeron.socket.so_rcvbuf", "2097152");
    setProperty("aeron.rcv.initial.window.length", "2097152");

    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());

    try (MediaDriver ignored = MediaDriver.launch(ctx)) {
        new SigIntBarrier().await();

    }
}
 
Example #16
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 #17
Source File: AeronUtil.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * Get a media driver context
 * for sending ndarrays
 * based on a given length
 * where length is the length (number of elements)
 * in the ndarrays hat are being sent
 * @param length the length to based the ipc length
 * @return the media driver context based on the given length
 */
public static MediaDriver.Context getMediaDriverContext(int length) {
    //length of array * sizeof(float)
    int ipcLength = length * 16;
    //padding for NDArrayMessage
    ipcLength += 64;
    //must be a power of 2
    ipcLength *= 2;
    //ipc length must be positive power of 2
    while (!BitUtil.isPowerOfTwo(ipcLength))
        ipcLength += 2;
    // System.setProperty("aeron.term.buffer.size",String.valueOf(ipcLength));
    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
                                    /*  .ipcTermBufferLength(ipcLength)
                                      .publicationTermBufferLength(ipcLength)
                                      .maxTermBufferLength(ipcLength)*/
                                    .conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());
    return ctx;
}
 
Example #18
Source File: LowLatencyMediaDriver.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("checkstyle:UncommentedMain")
public static void main(final String... args) {
    MediaDriver.loadPropertiesFiles(args);

    setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true");
    setProperty("aeron.mtu.length", "16384");
    setProperty("aeron.socket.so_sndbuf", "2097152");
    setProperty("aeron.socket.so_rcvbuf", "2097152");
    setProperty("aeron.rcv.initial.window.length", "2097152");

    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());

    try (MediaDriver ignored = MediaDriver.launch(ctx)) {
        new SigIntBarrier().await();

    }
}
 
Example #19
Source File: EmbeddedExclusiveBufferClaimIpcThroughput.java    From aeron with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception
{
    loadPropertiesFiles(args);

    final AtomicBoolean running = new AtomicBoolean(true);
    SigInt.register(() -> running.set(false));

    final MediaDriver.Context ctx = new MediaDriver.Context()
        .threadingMode(ThreadingMode.SHARED);

    try (MediaDriver ignore = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect();
        Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
        Publication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID))
    {
        final ImageRateSubscriber subscriber = new ImageRateSubscriber(FRAGMENT_COUNT_LIMIT, running, subscription);
        final Thread subscriberThread = new Thread(subscriber);
        subscriberThread.setName("subscriber");
        final Thread publisherThread = new Thread(new Publisher(running, publication));
        publisherThread.setName("publisher");
        final Thread rateReporterThread = new Thread(new ImageRateReporter(MESSAGE_LENGTH, running, subscriber));
        rateReporterThread.setName("rate-reporter");

        rateReporterThread.start();
        subscriberThread.start();
        publisherThread.start();

        subscriberThread.join();
        publisherThread.join();
        rateReporterThread.join();
    }
}
 
Example #20
Source File: EmbeddedBufferClaimIpcThroughput.java    From aeron with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception
{
    loadPropertiesFiles(args);

    final AtomicBoolean running = new AtomicBoolean(true);
    SigInt.register(() -> running.set(false));

    final MediaDriver.Context ctx = new MediaDriver.Context()
        .threadingMode(ThreadingMode.SHARED);

    try (MediaDriver ignore = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect();
        Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
        Publication publication = aeron.addPublication(CHANNEL, STREAM_ID))
    {
        final ImageRateSubscriber subscriber = new ImageRateSubscriber(FRAGMENT_COUNT_LIMIT, running, subscription);
        final Thread subscriberThread = new Thread(subscriber);
        subscriberThread.setName("subscriber");
        final Thread publisherThread = new Thread(new Publisher(running, publication));
        publisherThread.setName("publisher");
        final Thread rateReporterThread = new Thread(new ImageRateReporter(MESSAGE_LENGTH, running, subscriber));
        rateReporterThread.setName("rate-reporter");

        rateReporterThread.start();
        subscriberThread.start();
        publisherThread.start();

        subscriberThread.join();
        publisherThread.join();
        rateReporterThread.join();
    }
}
 
Example #21
Source File: MaxFlowControlStrategySystemTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void launch()
{
    final String baseDirA = ROOT_DIR + "A";
    final String baseDirB = ROOT_DIR + "B";

    buffer.putInt(0, 1);

    driverAContext.publicationTermBufferLength(TERM_BUFFER_LENGTH)
        .aeronDirectoryName(baseDirA)
        .timerIntervalNs(TimeUnit.MILLISECONDS.toNanos(100))
        .errorHandler(Tests::onError)
        .threadingMode(ThreadingMode.SHARED);

    driverBContext.publicationTermBufferLength(TERM_BUFFER_LENGTH)
        .aeronDirectoryName(baseDirB)
        .timerIntervalNs(TimeUnit.MILLISECONDS.toNanos(100))
        .errorHandler(Tests::onError)
        .threadingMode(ThreadingMode.SHARED);

    driverA = TestMediaDriver.launch(driverAContext, testWatcher);
    driverB = TestMediaDriver.launch(driverBContext, testWatcher);
    clientA = Aeron.connect(
        new Aeron.Context()
            .errorHandler(Tests::onError)
            .aeronDirectoryName(driverAContext.aeronDirectoryName()));

    clientB = Aeron.connect(
        new Aeron.Context()
            .errorHandler(Tests::onError)
            .aeronDirectoryName(driverBContext.aeronDirectoryName()));
}
 
Example #22
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 #23
Source File: BasicAuctionClusterClient.java    From aeron with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args)
{
    final int customerId = Integer.parseInt(System.getProperty("aeron.cluster.tutorial.customerId"));       // <1>
    final int numOfBids = Integer.parseInt(System.getProperty("aeron.cluster.tutorial.numOfBids"));         // <2>
    final int bidIntervalMs = Integer.parseInt(System.getProperty("aeron.cluster.tutorial.bidIntervalMs")); // <3>

    final String ingressEndpoints = ingressEndpoints(Arrays.asList("localhost", "localhost", "localhost"));
    final BasicAuctionClusterClient client = new BasicAuctionClusterClient(customerId, numOfBids, bidIntervalMs);

    // tag::connect[]
    final int egressPort = 19000 + customerId;

    try (
        MediaDriver mediaDriver = MediaDriver.launchEmbedded(new MediaDriver.Context()                      // <1>
            .threadingMode(ThreadingMode.SHARED)
            .dirDeleteOnStart(true)
            .dirDeleteOnShutdown(true));
        AeronCluster aeronCluster = AeronCluster.connect(
            new AeronCluster.Context()
            .egressListener(client)                                                                         // <2>
            .egressChannel("aeron:udp?endpoint=localhost:" + egressPort)                                    // <3>
            .aeronDirectoryName(mediaDriver.aeronDirectoryName())
            .ingressChannel("aeron:udp")                                                                    // <4>
            .ingressEndpoints(ingressEndpoints)))                                                           // <5>
    {
    // end::connect[]
        client.bidInAuction(aeronCluster);
    }
}
 
Example #24
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 #25
Source File: AeronNDArrayResponseTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());
    mediaDriver = MediaDriver.launchEmbedded(ctx);
    System.out.println("Using media driver directory " + mediaDriver.aeronDirectoryName());
    System.out.println("Launched media driver");
}
 
Example #26
Source File: AeronNDArrayResponseTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    if(isIntegrationTests()) {
        final MediaDriver.Context ctx =
                new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
                        .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                        .receiverIdleStrategy(new BusySpinIdleStrategy())
                        .senderIdleStrategy(new BusySpinIdleStrategy());
        mediaDriver = MediaDriver.launchEmbedded(ctx);
        System.out.println("Using media driver directory " + mediaDriver.aeronDirectoryName());
        System.out.println("Launched media driver");
    }
}
 
Example #27
Source File: EmbeddedExclusiveVectoredIpcThroughput.java    From aeron with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception
{
    loadPropertiesFiles(args);

    final AtomicBoolean running = new AtomicBoolean(true);
    SigInt.register(() -> running.set(false));

    final MediaDriver.Context ctx = new MediaDriver.Context()
        .threadingMode(ThreadingMode.SHARED);

    try (MediaDriver ignore = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect();
        Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
        ExclusivePublication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID))
    {
        final ImageRateSubscriber subscriber = new ImageRateSubscriber(FRAGMENT_COUNT_LIMIT, running, subscription);
        final Thread subscriberThread = new Thread(subscriber);
        subscriberThread.setName("subscriber");
        final Thread publisherThread = new Thread(new Publisher(running, publication));
        publisherThread.setName("publisher");
        final Thread rateReporterThread = new Thread(new ImageRateReporter(MESSAGE_LENGTH, running, subscriber));
        rateReporterThread.setName("rate-reporter");

        rateReporterThread.start();
        subscriberThread.start();
        publisherThread.start();

        subscriberThread.join();
        publisherThread.join();
        rateReporterThread.join();
    }
}
 
Example #28
Source File: TestCluster.java    From aeron with Apache License 2.0 5 votes vote down vote up
AeronCluster connectClient()
{
    final String aeronDirName = CommonContext.getAeronDirectoryName();

    if (null == clientMediaDriver)
    {
        dataCollector.add(Paths.get(aeronDirName));

        clientMediaDriver = MediaDriver.launch(
            new MediaDriver.Context()
                .threadingMode(ThreadingMode.SHARED)
                .dirDeleteOnStart(true)
                .dirDeleteOnShutdown(false)
                .aeronDirectoryName(aeronDirName));
    }

    CloseHelper.close(client);
    client = AeronCluster.connect(
        new AeronCluster.Context()
            .aeronDirectoryName(aeronDirName)
            .egressListener(egressMessageListener)
            .ingressChannel("aeron:udp?term-length=64k")
            .egressChannel(CLUSTER_EGRESS_CHANNEL)
            .ingressEndpoints(staticClusterMemberEndpoints));

    return client;
}
 
Example #29
Source File: StartFromTruncatedRecordingLogTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before()
{
    for (int i = 0; i < MEMBER_COUNT; i++)
    {
        echoServices[i] = new EchoService();
        startNode(i, true);
    }

    clientMediaDriver = MediaDriver.launch(
        new MediaDriver.Context()
            .threadingMode(ThreadingMode.SHARED)
            .warnIfDirectoryExists(false)
            .dirDeleteOnStart(true));
}
 
Example #30
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)));
}