use of io.aeron.archive.Archive in project Aeron by real-logic.
the class RecordingDescriptorCollectorTest method shouldShouldNotReuseDescriptorIfPoolSizeIsZero.
@Test
void shouldShouldNotReuseDescriptorIfPoolSizeIsZero(@TempDir final Path tempDir) {
try (MediaDriver mediaDriver = MediaDriver.launch(new MediaDriver.Context().dirDeleteOnStart(true));
Archive ignore = Archive.launch(new Archive.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()).archiveDir(tempDir.resolve("archive").toFile()).deleteArchiveOnStart(true));
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron).ownsAeronClient(false))) {
createRecordings(aeronArchive, 3);
final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(0);
long fromRecordingId = 0;
int count = aeronArchive.listRecordings(fromRecordingId, 1, collector.reset());
assertEquals(1, count);
final RecordingDescriptor desc0 = collector.descriptors().get(0);
fromRecordingId += count;
count = aeronArchive.listRecordings(fromRecordingId, 1, collector.reset());
assertEquals(1, count);
final RecordingDescriptor desc1 = collector.descriptors().get(0);
assertNotEquals(desc0.recordingId(), desc1.recordingId());
}
}
use of io.aeron.archive.Archive in project Aeron by real-logic.
the class RecordingDescriptorCollectorTest method shouldCollectPagesOfRecordingDescriptors.
@Test
@InterruptAfter(10)
void shouldCollectPagesOfRecordingDescriptors(@TempDir final Path tempDir) {
try (MediaDriver mediaDriver = MediaDriver.launch(new MediaDriver.Context().dirDeleteOnStart(true));
Archive ignore = Archive.launch(new Archive.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()).archiveDir(tempDir.resolve("archive").toFile()).deleteArchiveOnStart(true));
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron).ownsAeronClient(false))) {
final int numRecordings = 10;
createRecordings(aeronArchive, numRecordings);
final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(3);
long fromRecordingId = 0;
int count;
while (0 < (count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset()))) {
final List<RecordingDescriptor> descriptors = collector.descriptors();
assertThat(count, lessThanOrEqualTo(collector.poolSize()));
assertThat(descriptors.size(), lessThanOrEqualTo(collector.poolSize()));
// noinspection OptionalGetWithoutIsPresent
final long maxRecordingId = descriptors.stream().mapToLong(RecordingDescriptor::recordingId).max().getAsLong();
fromRecordingId = maxRecordingId + 1;
}
}
}
use of io.aeron.archive.Archive 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.archive.Archive 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.archive.Archive 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