use of io.aeron.cluster.service.ClusteredServiceContainer in project Aeron by real-logic.
the class MultiModuleSharedDriverTest method shouldSupportTwoSingleNodeClusters.
@Test
@InterruptAfter(20)
@SuppressWarnings({ "try", "methodlength" })
public void shouldSupportTwoSingleNodeClusters() {
final MediaDriver.Context driverCtx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).nameResolver(new RedirectingNameResolver(TestCluster.DEFAULT_NODE_MAPPINGS)).dirDeleteOnShutdown(false).dirDeleteOnStart(true);
final Archive.Context archiveCtx = new Archive.Context().threadingMode(ArchiveThreadingMode.SHARED).archiveDir(new File(SystemUtil.tmpDirName(), "archive")).recordingEventsEnabled(false).deleteArchiveOnStart(true);
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx)) {
final ConsensusModule.Context moduleCtx0 = new ConsensusModule.Context().clusterId(0).deleteDirOnStart(true).clusterDir(new File(SystemUtil.tmpDirName(), "cluster-0-0")).logChannel("aeron:ipc?term-length=64k").logStreamId(100).serviceStreamId(104).consensusModuleStreamId(105).ingressChannel("aeron:udp?endpoint=localhost:9020").replicationChannel("aeron:udp?endpoint=localhost:0");
final ClusteredServiceContainer.Context containerCtx0 = new ClusteredServiceContainer.Context().clusterId(moduleCtx0.clusterId()).clusteredService(new EchoService()).clusterDir(moduleCtx0.clusterDir()).serviceStreamId(moduleCtx0.serviceStreamId()).consensusModuleStreamId(moduleCtx0.consensusModuleStreamId());
final ConsensusModule.Context moduleCtx1 = new ConsensusModule.Context().clusterId(1).deleteDirOnStart(true).clusterDir(new File(SystemUtil.tmpDirName(), "cluster-0-1")).logChannel("aeron:ipc?term-length=64k").logStreamId(200).serviceStreamId(204).consensusModuleStreamId(205).ingressChannel("aeron:udp?endpoint=localhost:9021").replicationChannel("aeron:udp?endpoint=localhost:0");
final ClusteredServiceContainer.Context containerCtx1 = new ClusteredServiceContainer.Context().clusteredService(new EchoService()).clusterDir(moduleCtx1.clusterDir()).serviceStreamId(moduleCtx1.serviceStreamId()).consensusModuleStreamId(moduleCtx1.consensusModuleStreamId()).clusterId(moduleCtx1.clusterId());
ConsensusModule consensusModule0 = null;
ClusteredServiceContainer container0 = null;
ConsensusModule consensusModule1 = null;
ClusteredServiceContainer container1 = null;
AeronCluster client0 = null;
AeronCluster client1 = null;
try {
consensusModule0 = ConsensusModule.launch(moduleCtx0);
consensusModule1 = ConsensusModule.launch(moduleCtx1);
container0 = ClusteredServiceContainer.launch(containerCtx0);
container1 = ClusteredServiceContainer.launch(containerCtx1);
final MutableReference<String> egress = new MutableReference<>();
final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length, header) -> egress.set(buffer.getStringWithoutLengthAscii(offset, length));
client0 = AeronCluster.connect(new AeronCluster.Context().egressListener(egressListener).ingressChannel(moduleCtx0.ingressChannel()).egressChannel("aeron:udp?endpoint=localhost:0"));
client1 = AeronCluster.connect(new AeronCluster.Context().egressListener(egressListener).ingressChannel(moduleCtx1.ingressChannel()).egressChannel("aeron:udp?endpoint=localhost:0"));
echoMessage(client0, "Message 0", egress);
echoMessage(client1, "Message 1", egress);
} finally {
systemTestWatcher.dataCollector().add(moduleCtx0.clusterDir());
systemTestWatcher.dataCollector().add(moduleCtx1.clusterDir());
CloseHelper.closeAll(client0, client1, consensusModule0, consensusModule1, container0, container1);
}
} finally {
systemTestWatcher.dataCollector().add(driverCtx.aeronDirectory());
systemTestWatcher.dataCollector().add(archiveCtx.archiveDir());
}
}
use of io.aeron.cluster.service.ClusteredServiceContainer in project Aeron by real-logic.
the class StartFromTruncatedRecordingLogTest method after.
@AfterEach
public void after() {
CloseHelper.closeAll(client, clientMediaDriver);
for (final ClusteredMediaDriver driver : clusteredMediaDrivers) {
if (null != driver) {
driver.consensusModule().close();
}
}
CloseHelper.closeAll(containers);
CloseHelper.closeAll(clusteredMediaDrivers);
clientMediaDriver.context().deleteDirectory();
for (final ClusteredServiceContainer container : containers) {
if (null != container) {
container.context().deleteDirectory();
}
}
for (final ClusteredMediaDriver driver : clusteredMediaDrivers) {
if (null != driver) {
driver.consensusModule().context().deleteDirectory();
driver.archive().context().deleteDirectory();
driver.mediaDriver().context().deleteDirectory();
}
}
}
use of io.aeron.cluster.service.ClusteredServiceContainer in project Aeron by real-logic.
the class BasicAuctionClusteredServiceNode method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
*/
@SuppressWarnings("try")
public static // tag::main[]
void main(final String[] args) {
// <1>
final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
final String[] hostnames = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost").split(// <2>
",");
final String hostname = hostnames[nodeId];
// <3>
final File baseDir = new File(System.getProperty("user.dir"), "node" + nodeId);
final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
// <4>
final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
// 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[]
final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
// tag::archive[]
final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, "archive")).controlChannel(udpChannel(nodeId, hostname, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
// end::archive[]
// tag::archive_client[]
final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
// end::archive_client[]
// tag::consensus_module[]
final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().errorHandler(errorHandler("Consensus Module")).clusterMemberId(// <1>
nodeId).clusterMembers(// <2>
clusterMembers(Arrays.asList(hostnames))).clusterDir(// <3>
new File(baseDir, "cluster")).ingressChannel(// <4>
"aeron:udp?term-length=64k").logChannel(// <5>
logControlChannel(nodeId, hostname, LOG_CONTROL_PORT_OFFSET)).replicationChannel(// <6>
logReplicationChannel(hostname)).archiveContext(// <7>
aeronArchiveContext.clone());
// end::consensus_module[]
// tag::clustered_service[]
final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(// <1>
aeronDirName).archiveContext(// <2>
aeronArchiveContext.clone()).clusterDir(new File(baseDir, "cluster")).clusteredService(// <3>
new BasicAuctionClusteredService()).errorHandler(errorHandler("Clustered Service"));
// tag::running[]
try (ClusteredMediaDriver clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverContext, archiveContext, // <1>
consensusModuleContext);
ClusteredServiceContainer container = ClusteredServiceContainer.launch(// <2>
clusteredServiceContext)) {
System.out.println("[" + nodeId + "] Started Cluster Node on " + hostname + "...");
// <3>
barrier.await();
System.out.println("[" + nodeId + "] Exiting");
}
// end::running[]
}
use of io.aeron.cluster.service.ClusteredServiceContainer in project aeron by real-logic.
the class EchoServiceNode method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
*/
@SuppressWarnings("try")
public static void main(final String[] args) {
final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
final String hostnamesStr = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost");
final String internalHostnamesStr = System.getProperty("aeron.cluster.tutorial.hostnames.internal", hostnamesStr);
final List<String> hostnames = Arrays.asList(hostnamesStr.split(","));
final List<String> internalHostnames = Arrays.asList(internalHostnamesStr.split(","));
final String baseDir = System.getProperty("aeron.cluster.tutorial.baseDir");
final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
final ClusterConfig clusterConfig = ClusterConfig.create(nodeId, hostnames, internalHostnames, PORT_BASE, new EchoService());
clusterConfig.mediaDriverContext().errorHandler(EchoServiceNode.errorHandler("Media Driver"));
clusterConfig.archiveContext().errorHandler(EchoServiceNode.errorHandler("Archive"));
clusterConfig.aeronArchiveContext().errorHandler(EchoServiceNode.errorHandler("Aeron Archive"));
clusterConfig.consensusModuleContext().errorHandler(errorHandler("Consensus Module"));
clusterConfig.clusteredServiceContext().errorHandler(errorHandler("Clustered Service"));
try (ClusteredMediaDriver ignore = ClusteredMediaDriver.launch(clusterConfig.mediaDriverContext(), clusterConfig.archiveContext(), clusterConfig.consensusModuleContext());
ClusteredServiceContainer ignore2 = ClusteredServiceContainer.launch(clusterConfig.clusteredServiceContext())) {
System.out.println("[" + nodeId + "] Started Cluster Node on " + hostnames.get(nodeId) + "...");
barrier.await();
System.out.println("[" + nodeId + "] Exiting");
}
}
use of io.aeron.cluster.service.ClusteredServiceContainer in project aeron by real-logic.
the class BasicAuctionClusteredServiceNode method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
*/
@SuppressWarnings("try")
public static // tag::main[]
void main(final String[] args) {
// <1>
final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
final String[] hostnames = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost").split(// <2>
",");
final String hostname = hostnames[nodeId];
// <3>
final File baseDir = new File(System.getProperty("user.dir"), "node" + nodeId);
final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
// <4>
final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
// 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[]
final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
// tag::archive[]
final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, "archive")).controlChannel(udpChannel(nodeId, hostname, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
// end::archive[]
// tag::archive_client[]
final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
// end::archive_client[]
// tag::consensus_module[]
final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().errorHandler(errorHandler("Consensus Module")).clusterMemberId(// <1>
nodeId).clusterMembers(// <2>
clusterMembers(Arrays.asList(hostnames))).clusterDir(// <3>
new File(baseDir, "cluster")).ingressChannel(// <4>
"aeron:udp?term-length=64k").logChannel(// <5>
logControlChannel(nodeId, hostname, LOG_CONTROL_PORT_OFFSET)).replicationChannel(// <6>
logReplicationChannel(hostname)).archiveContext(// <7>
aeronArchiveContext.clone());
// end::consensus_module[]
// tag::clustered_service[]
final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(// <1>
aeronDirName).archiveContext(// <2>
aeronArchiveContext.clone()).clusterDir(new File(baseDir, "cluster")).clusteredService(// <3>
new BasicAuctionClusteredService()).errorHandler(errorHandler("Clustered Service"));
// tag::running[]
try (ClusteredMediaDriver clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverContext, archiveContext, // <1>
consensusModuleContext);
ClusteredServiceContainer container = ClusteredServiceContainer.launch(// <2>
clusteredServiceContext)) {
System.out.println("[" + nodeId + "] Started Cluster Node on " + hostname + "...");
// <3>
barrier.await();
System.out.println("[" + nodeId + "] Exiting");
}
// end::running[]
}
Aggregations