use of io.aeron.driver.MinMulticastFlowControlSupplier 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.driver.MinMulticastFlowControlSupplier in project aeron by real-logic.
the class MinFlowControlSystemTest method shouldRemoveDeadTaggedReceiverWithMinMulticastFlowControlStrategy.
@Test
@InterruptAfter(10)
void shouldRemoveDeadTaggedReceiverWithMinMulticastFlowControlStrategy() {
final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
int numMessagesLeftToSend = numMessagesToSend;
int numFragmentsReadFromA = 0, numFragmentsReadFromB = 0;
driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
driverAContext.multicastFlowControlSupplier(new MinMulticastFlowControlSupplier());
launch();
subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID);
publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
while (!subscriptionA.isConnected() || !subscriptionB.isConnected() || !publication.isConnected()) {
Tests.yield();
}
boolean isBClosed = false;
while (numFragmentsReadFromA < numMessagesToSend) {
if (numMessagesLeftToSend > 0) {
if (publication.offer(buffer, 0, buffer.capacity()) >= 0L) {
numMessagesLeftToSend--;
}
}
// A keeps up
numFragmentsReadFromA += subscriptionA.poll(fragmentHandlerA, 10);
// B receives up to 1/8 of the messages, then stops
if (numFragmentsReadFromB < (numMessagesToSend / 8)) {
numFragmentsReadFromB += subscriptionB.poll(fragmentHandlerB, 10);
} else if (!isBClosed) {
subscriptionB.close();
isBClosed = true;
}
}
verify(fragmentHandlerA, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
}
Aggregations