use of io.aeron.driver.MediaDriver in project aeron by real-logic.
the class BasicSubscriber method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
*/
public static void main(final String[] args) {
System.out.println("Subscribing to " + CHANNEL + " on stream id " + STREAM_ID);
final MediaDriver driver = EMBEDDED_MEDIA_DRIVER ? MediaDriver.launchEmbedded() : null;
final Aeron.Context ctx = new Aeron.Context().availableImageHandler(SamplesUtil::printAvailableImage).unavailableImageHandler(SamplesUtil::printUnavailableImage);
if (EMBEDDED_MEDIA_DRIVER) {
ctx.aeronDirectoryName(driver.aeronDirectoryName());
}
final FragmentHandler fragmentHandler = SamplesUtil.printAsciiMessage(STREAM_ID);
final AtomicBoolean running = new AtomicBoolean(true);
// Register a SIGINT handler for graceful shutdown.
SigInt.register(() -> running.set(false));
// clean up resources when this try block is finished
try (Aeron aeron = Aeron.connect(ctx);
Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) {
SamplesUtil.subscriberLoop(fragmentHandler, FRAGMENT_COUNT_LIMIT, running).accept(subscription);
System.out.println("Shutting down...");
}
CloseHelper.close(driver);
}
use of io.aeron.driver.MediaDriver in project aeron by real-logic.
the class EmbeddedPingPong method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
* @throws InterruptedException if the thread is interrupted.
*/
public static void main(final String[] args) throws InterruptedException {
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 mediaDriver = MediaDriver.launch(ctx);
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()))) {
final Thread pongThread = startPong(aeron);
pongThread.start();
runPing(aeron);
RUNNING.set(false);
pongThread.join();
System.out.println("Shutdown Driver...");
}
}
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...");
}
}
use of io.aeron.driver.MediaDriver in project aeron by real-logic.
the class TestMediaDriverTest method connectToCMediaDriverWithoutSpecifyingAeronDir.
@Test
void connectToCMediaDriverWithoutSpecifyingAeronDir() {
assumeTrue(TestMediaDriver.shouldRunCMediaDriver());
final MediaDriver.Context context = new MediaDriver.Context().dirDeleteOnStart(true).dirDeleteOnShutdown(false);
assertEquals(CommonContext.getAeronDirectoryName(), context.aeronDirectoryName());
try (TestMediaDriver mediaDriver = CTestMediaDriver.launch(context, false, null);
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(context.aeronDirectoryName()))) {
final File aeronDirectory = aeron.context().aeronDirectory();
assertNotNull(aeronDirectory);
assertTrue(aeronDirectory.exists());
assertNotNull(mediaDriver);
} finally {
context.deleteDirectory();
}
}
use of io.aeron.driver.MediaDriver in project aeron by real-logic.
the class ClusterNetworkTopologyTest method connectAndSendMessages.
private void connectAndSendMessages(final String ingressChannel, final String ingressEndpoints, final Selector selector, final double messageCount) {
final String message = "Hello World!";
final MutableDirectBuffer messageBuffer = new UnsafeBuffer(ByteBuffer.allocate(128));
final int length = messageBuffer.putStringAscii(0, message);
final MutableReference<String> egressResponse = new MutableReference<>();
final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length1, header) -> {
final String stringAscii = buffer.getStringAscii(offset);
egressResponse.set(stringAscii);
};
try (MediaDriver mediaDriver = MediaDriver.launchEmbedded(new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).dirDeleteOnShutdown(true));
AeronCluster.AsyncConnect asyncConnect = AeronCluster.asyncConnect(new AeronCluster.Context().messageTimeoutNs(TimeUnit.SECONDS.toNanos(CLUSTER_START_ELECTION_TIMEOUT_S * 2)).egressListener(egressListener).egressChannel("aeron:udp?endpoint=10.42.0.1:0").aeronDirectoryName(mediaDriver.aeronDirectoryName()).ingressChannel(ingressChannel).ingressEndpoints(ingressEndpoints));
AeronCluster aeronCluster = pollUntilConnected(asyncConnect, selector)) {
for (int i = 0; i < messageCount; i++) {
Tests.await(() -> {
final long position = aeronCluster.offer(messageBuffer, 0, length);
pollSelector(selector);
return 0 < position;
}, SECONDS.toNanos(5));
Tests.await(() -> {
aeronCluster.pollEgress();
pollSelector(selector);
return message.equals(egressResponse.get());
}, SECONDS.toNanos(5));
}
}
}
Aggregations