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 MultiClusteredServicesTest method shouldSupportMultipleServicesPerNode.
@Test
@InterruptAfter(20)
public void shouldSupportMultipleServicesPerNode() {
final List<TestCluster.NodeContext> nodeContexts = new ArrayList<>();
final List<TestCluster.ServiceContext> serviceContexts = new ArrayList<>();
final List<ClusteredMediaDriver> clusteredMediaDrivers = new ArrayList<>();
final List<ClusteredServiceContainer> clusteredServiceContainers = new ArrayList<>();
nodeContexts.add(TestCluster.nodeContext(0, true));
nodeContexts.add(TestCluster.nodeContext(1, true));
nodeContexts.add(TestCluster.nodeContext(2, true));
serviceContexts.add(TestCluster.serviceContext(0, 0, nodeContexts.get(0), ServiceA::new));
serviceContexts.add(TestCluster.serviceContext(0, 1, nodeContexts.get(0), ServiceB::new));
serviceContexts.add(TestCluster.serviceContext(1, 0, nodeContexts.get(1), ServiceA::new));
serviceContexts.add(TestCluster.serviceContext(1, 1, nodeContexts.get(1), ServiceB::new));
serviceContexts.add(TestCluster.serviceContext(2, 0, nodeContexts.get(2), ServiceA::new));
serviceContexts.add(TestCluster.serviceContext(2, 1, nodeContexts.get(2), ServiceB::new));
nodeContexts.forEach((context) -> {
try {
clusteredMediaDrivers.add(ClusteredMediaDriver.launch(context.mediaDriverCtx, context.archiveCtx, context.consensusModuleCtx));
} finally {
systemTestWatcher.dataCollector().add(context.mediaDriverCtx.aeronDirectory());
systemTestWatcher.dataCollector().add(context.archiveCtx.archiveDir());
systemTestWatcher.dataCollector().add(context.consensusModuleCtx.clusterDir());
}
});
serviceContexts.forEach((context) -> {
context.serviceContainerCtx.aeronDirectoryName(context.aeronCtx.aeronDirectoryName());
try {
clusteredServiceContainers.add(ClusteredServiceContainer.launch(context.serviceContainerCtx));
} finally {
systemTestWatcher.dataCollector().add(context.serviceContainerCtx.clusterDir());
}
});
final String aeronDirName = CommonContext.getAeronDirectoryName();
final MediaDriver clientMediaDriver = MediaDriver.launch(new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).aeronDirectoryName(aeronDirName).nameResolver(new RedirectingNameResolver(TestCluster.DEFAULT_NODE_MAPPINGS)));
final AeronCluster client = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(aeronDirName).ingressChannel(CommonContext.UDP_CHANNEL).ingressEndpoints(TestCluster.ingressEndpoints(0, 3)));
try {
final DirectBuffer buffer = new UnsafeBuffer(new byte[100]);
while (client.offer(buffer, 0, 100) < 0) {
Tests.yield();
}
Tests.awaitValue(serviceAMessageCount, 3);
Tests.awaitValue(serviceBMessageCount, 3);
} finally {
CloseHelper.closeAll(client, clientMediaDriver);
clusteredMediaDrivers.forEach((clusteredMediaDriver) -> clusteredMediaDriver.consensusModule().close());
CloseHelper.closeAll(clusteredServiceContainers);
CloseHelper.closeAll(clusteredMediaDrivers);
clientMediaDriver.context().deleteDirectory();
}
}
use of io.aeron.cluster.service.ClusteredServiceContainer in project aeron by real-logic.
the class MultiClusteredServicesTest method shouldSupportMultipleServicesPerNode.
@Test
@InterruptAfter(20)
public void shouldSupportMultipleServicesPerNode() {
final List<TestCluster.NodeContext> nodeContexts = new ArrayList<>();
final List<TestCluster.ServiceContext> serviceContexts = new ArrayList<>();
final List<ClusteredMediaDriver> clusteredMediaDrivers = new ArrayList<>();
final List<ClusteredServiceContainer> clusteredServiceContainers = new ArrayList<>();
nodeContexts.add(TestCluster.nodeContext(0, true));
nodeContexts.add(TestCluster.nodeContext(1, true));
nodeContexts.add(TestCluster.nodeContext(2, true));
serviceContexts.add(TestCluster.serviceContext(0, 0, nodeContexts.get(0), ServiceA::new));
serviceContexts.add(TestCluster.serviceContext(0, 1, nodeContexts.get(0), ServiceB::new));
serviceContexts.add(TestCluster.serviceContext(1, 0, nodeContexts.get(1), ServiceA::new));
serviceContexts.add(TestCluster.serviceContext(1, 1, nodeContexts.get(1), ServiceB::new));
serviceContexts.add(TestCluster.serviceContext(2, 0, nodeContexts.get(2), ServiceA::new));
serviceContexts.add(TestCluster.serviceContext(2, 1, nodeContexts.get(2), ServiceB::new));
nodeContexts.forEach((context) -> {
try {
clusteredMediaDrivers.add(ClusteredMediaDriver.launch(context.mediaDriverCtx, context.archiveCtx, context.consensusModuleCtx));
} finally {
systemTestWatcher.dataCollector().add(context.mediaDriverCtx.aeronDirectory());
systemTestWatcher.dataCollector().add(context.archiveCtx.archiveDir());
systemTestWatcher.dataCollector().add(context.consensusModuleCtx.clusterDir());
}
});
serviceContexts.forEach((context) -> {
context.serviceContainerCtx.aeronDirectoryName(context.aeronCtx.aeronDirectoryName());
try {
clusteredServiceContainers.add(ClusteredServiceContainer.launch(context.serviceContainerCtx));
} finally {
systemTestWatcher.dataCollector().add(context.serviceContainerCtx.clusterDir());
}
});
final String aeronDirName = CommonContext.getAeronDirectoryName();
final MediaDriver clientMediaDriver = MediaDriver.launch(new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).aeronDirectoryName(aeronDirName).nameResolver(new RedirectingNameResolver(TestCluster.DEFAULT_NODE_MAPPINGS)));
final AeronCluster client = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(aeronDirName).ingressChannel(CommonContext.UDP_CHANNEL).ingressEndpoints(TestCluster.ingressEndpoints(0, 3)));
try {
final DirectBuffer buffer = new UnsafeBuffer(new byte[100]);
while (client.offer(buffer, 0, 100) < 0) {
Tests.yield();
}
Tests.awaitValue(serviceAMessageCount, 3);
Tests.awaitValue(serviceBMessageCount, 3);
} finally {
CloseHelper.closeAll(client, clientMediaDriver);
clusteredMediaDrivers.forEach((clusteredMediaDriver) -> clusteredMediaDriver.consensusModule().close());
CloseHelper.closeAll(clusteredServiceContainers);
CloseHelper.closeAll(clusteredMediaDrivers);
clientMediaDriver.context().deleteDirectory();
}
}
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 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());
}
}
Aggregations