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;
}
}
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;
}
}
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);
}
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 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);
}
Aggregations