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, 1, 1)) .receiverIdleStrategy(new NoOpIdleStrategy()) .senderIdleStrategy(new NoOpIdleStrategy()); try (MediaDriver ignored = MediaDriver.launch(ctx)) { final Thread pongThread = startPong(ignored.aeronDirectoryName()); pongThread.start(); runPing(ignored.aeronDirectoryName()); RUNNING.set(false); pongThread.join(); System.out.println("Shutdown Driver..."); } }
public EmbeddedRecordingThroughput() { final String archiveDirName = Archive.Configuration.archiveDirName(); final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ? TestUtil.createTempDir() : new File(archiveDirName); archivingMediaDriver = ArchivingMediaDriver.launch( new MediaDriver.Context() .spiesSimulateConnection(true) .dirDeleteOnStart(true), new Archive.Context() .deleteArchiveOnStart(true) .archiveDir(archiveDir)); aeron = Aeron.connect(); aeronArchive = AeronArchive.connect( new AeronArchive.Context() .aeron(aeron)); }
public static void main(final String[] args) { 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..."); } } }
@Before public void before() { final String aeronDirectoryName = CommonContext.generateRandomDirName(); archivingMediaDriver = ArchivingMediaDriver.launch( new MediaDriver.Context() .aeronDirectoryName(aeronDirectoryName) .termBufferSparseFile(true) .threadingMode(ThreadingMode.SHARED) .errorHandler(Throwable::printStackTrace) .spiesSimulateConnection(false) .dirDeleteOnStart(true), new Archive.Context() .maxCatalogEntries(MAX_CATALOG_ENTRIES) .aeronDirectoryName(aeronDirectoryName) .deleteArchiveOnStart(true) .archiveDir(new File(IoUtil.tmpDirName(), "archive")) .fileSyncLevel(0) .threadingMode(ArchiveThreadingMode.SHARED)); aeron = Aeron.connect( new Aeron.Context() .aeronDirectoryName(aeronDirectoryName)); aeronArchive = AeronArchive.connect( new AeronArchive.Context() .aeron(aeron)); }
@Test public void shouldStartAndStopInstantly() { final MediaDriver.Context driverCtx = new MediaDriver.Context() .errorHandler(Throwable::printStackTrace); try (MediaDriver ignore = MediaDriver.launchEmbedded(driverCtx)) { final Aeron.Context clientCtx = new Aeron.Context() .aeronDirectoryName(driverCtx.aeronDirectoryName()); //noinspection EmptyTryBlock try (Aeron ignored = Aeron.connect(clientCtx)) { // ignore } } finally { driverCtx.deleteAeronDirectory(); } } }
@Theory @Test public void shouldHaveCorrectTermBufferLength(final String channel) { final MediaDriver.Context ctx = new MediaDriver.Context() .errorHandler(Throwable::printStackTrace) .publicationTermBufferLength(TEST_TERM_LENGTH * 2) .ipcTermBufferLength(TEST_TERM_LENGTH * 2); try (MediaDriver ignore = MediaDriver.launch(ctx); Aeron aeron = Aeron.connect(); Publication publication = aeron.addPublication(channel, STREAM_ID)) { assertThat(publication.termBufferLength(), is(TEST_TERM_LENGTH)); } finally { ctx.deleteAeronDirectory(); } } }
private void launchClusteredMediaDriver(final boolean initialLaunch) { clusteredMediaDriver = null; clusteredMediaDriver = ClusteredMediaDriver.launch( new MediaDriver.Context() .warnIfDirectoryExists(initialLaunch) .threadingMode(ThreadingMode.SHARED) .termBufferSparseFile(true) .errorHandler(TestUtil.errorHandler(0)) .dirDeleteOnStart(true), new Archive.Context() .maxCatalogEntries(MAX_CATALOG_ENTRIES) .threadingMode(ArchiveThreadingMode.SHARED) .deleteArchiveOnStart(initialLaunch), new ConsensusModule.Context() .errorHandler(TestUtil.errorHandler(0)) .snapshotCounter(mockSnapshotCounter) .terminationHook(TestUtil.TERMINATION_HOOK) .deleteDirOnStart(initialLaunch)); }
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(Throwable::printStackTrace) .publicationTermBufferLength(TERM_BUFFER_LENGTH) .aeronDirectoryName(baseDirA) .threadingMode(THREADING_MODE); final MediaDriver.Context driverBContext = new MediaDriver.Context() .errorHandler(Throwable::printStackTrace) .publicationTermBufferLength(TERM_BUFFER_LENGTH) .aeronDirectoryName(baseDirB) .threadingMode(THREADING_MODE); driverA = MediaDriver.launch(driverAContext); driverB = MediaDriver.launch(driverBContext); clientA = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverAContext.aeronDirectoryName())); clientB = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverBContext.aeronDirectoryName())); }
private void startClient() { if (client != null) { client.close(); client = null; clientMediaDriver.close(); } final String aeronDirName = CommonContext.getAeronDirectoryName(); clientMediaDriver = MediaDriver.launch( new MediaDriver.Context() .threadingMode(ThreadingMode.SHARED) .aeronDirectoryName(aeronDirName) .dirDeleteOnStart(true)); client = AeronCluster.connect( new AeronCluster.Context() .egressListener(egressMessageListener) .aeronDirectoryName(aeronDirName) .ingressChannel("aeron:udp") .clusterMemberEndpoints("0=localhost:20110,1=localhost:20111,2=localhost:20112")); }
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(Throwable::printStackTrace) .publicationTermBufferLength(TERM_BUFFER_LENGTH) .aeronDirectoryName(baseDirA) .threadingMode(ThreadingMode.SHARED); driverBContext.publicationTermBufferLength(TERM_BUFFER_LENGTH) .errorHandler(Throwable::printStackTrace) .aeronDirectoryName(baseDirB) .threadingMode(ThreadingMode.SHARED); driverA = MediaDriver.launch(driverAContext); driverB = MediaDriver.launch(driverBContext); clientA = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverAContext.aeronDirectoryName())); clientB = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverBContext.aeronDirectoryName())); }
private void launchClusteredMediaDriver(final AuthenticatorSupplier authenticatorSupplier) { clusteredMediaDriver = null; clusteredMediaDriver = ClusteredMediaDriver.launch( new MediaDriver.Context() .warnIfDirectoryExists(true) .threadingMode(ThreadingMode.SHARED) .errorHandler(TestUtil.errorHandler(0)) .dirDeleteOnStart(true), new Archive.Context() .maxCatalogEntries(MAX_CATALOG_ENTRIES) .threadingMode(ArchiveThreadingMode.SHARED) .deleteArchiveOnStart(true), new ConsensusModule.Context() .errorHandler(Throwable::printStackTrace) .authenticatorSupplier(authenticatorSupplier) .terminationHook(TestUtil.TERMINATION_HOOK) .deleteDirOnStart(true)); } }
private void launch(final String channelOne, final int streamOne, final String channelTwo, final int streamTwo) { driverOne = MediaDriver.launchEmbedded( new MediaDriver.Context() .errorHandler(Throwable::printStackTrace) .termBufferSparseFile(true)); driverTwo = MediaDriver.launchEmbedded( new MediaDriver.Context() .errorHandler(Throwable::printStackTrace) .termBufferSparseFile(true)); publisherOne = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverOne.aeronDirectoryName())); subscriberOne = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverTwo.aeronDirectoryName())); publisherTwo = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverOne.aeronDirectoryName())); subscriberTwo = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverTwo.aeronDirectoryName())); subscriptionOne = subscriberOne.addSubscription(channelOne, streamOne); subscriptionTwo = subscriberTwo.addSubscription(channelTwo, streamTwo); publicationOne = publisherOne.addPublication(channelOne, streamOne); publicationTwo = publisherTwo.addPublication(channelTwo, streamTwo); }
@Before public void before() { clusteredMediaDriver = ClusteredMediaDriver.launch( new MediaDriver.Context() .threadingMode(ThreadingMode.SHARED) .termBufferSparseFile(true) .errorHandler(TestUtil.errorHandler(0)) .dirDeleteOnStart(true), new Archive.Context() .maxCatalogEntries(MAX_CATALOG_ENTRIES) .threadingMode(ArchiveThreadingMode.SHARED) .deleteArchiveOnStart(true), new ConsensusModule.Context() .errorHandler(TestUtil.errorHandler(0)) .terminationHook(TestUtil.TERMINATION_HOOK) .deleteDirOnStart(true)); }
@Before public void before() { driver = MediaDriver.launch( new MediaDriver.Context() .errorHandler(Throwable::printStackTrace) .publicationTermBufferLength(LogBufferDescriptor.TERM_MIN_LENGTH) .threadingMode(ThreadingMode.SHARED)); 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); }
private void launch() { labelBuffer.putStringWithoutLengthAscii(0, COUNTER_LABEL); driver = MediaDriver.launch( new MediaDriver.Context() .errorHandler(Throwable::printStackTrace) .threadingMode(ThreadingMode.SHARED)); clientA = Aeron.connect( new Aeron.Context() .availableCounterHandler(availableCounterHandlerClientA) .unavailableCounterHandler(unavailableCounterHandlerClientA)); clientB = Aeron.connect( new Aeron.Context() .availableCounterHandler(availableCounterHandlerClientB) .unavailableCounterHandler(unavailableCounterHandlerClientB)); }
/** * Launch an isolated MediaDriver embedded in the current process with a generated aeronDirectoryName that can be * retrieved by calling aeronDirectoryName. * <p> * If the aeronDirectoryName is set as a system property to something different than * {@link CommonContext#AERON_DIR_PROP_DEFAULT} then this set value will be used. * * @return the newly started MediaDriver. */ public static MediaDriver launchEmbedded() { return launchEmbedded(new Context()); }
void startClient() { final String aeronDirName = CommonContext.getAeronDirectoryName(); clientMediaDriver = MediaDriver.launch( new MediaDriver.Context() .threadingMode(ThreadingMode.SHARED) .aeronDirectoryName(aeronDirName)); client = AeronCluster.connect( new AeronCluster.Context() .egressListener(egressMessageListener) .aeronDirectoryName(aeronDirName) .ingressChannel("aeron:udp") .clusterMemberEndpoints(staticClusterMemberEndpoints)); }
/** * Launch a new {@link ArchivingMediaDriver} with defaults for {@link MediaDriver.Context} and * {@link Archive.Context}. * * @return a new {@link ArchivingMediaDriver} with default contexts. */ public static ArchivingMediaDriver launch() { return launch(new MediaDriver.Context(), new Archive.Context()); }
/** * Launch a MediaDriver embedded in the current process with default configuration. * * @return the newly started MediaDriver. */ public static MediaDriver launch() { return launch(new Context()); }
/** * 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()); }