use of io.aeron.archive.client.AeronArchive 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.client.AeronArchive 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.client.AeronArchive in project aeron by real-logic.
the class ReplayedBasicSubscriber method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
*/
public static void main(final String[] args) {
System.out.println("Subscribing to " + CHANNEL + " on stream id " + STREAM_ID);
final FragmentHandler fragmentHandler = SamplesUtil.printAsciiMessage(STREAM_ID);
final AtomicBoolean running = new AtomicBoolean(true);
SigInt.register(() -> running.set(false));
// Create a unique response stream id so not to clash with other archive clients.
final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlResponseStreamId(AeronArchive.Configuration.controlResponseStreamId() + 2);
try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
final long recordingId = findLatestRecording(archive);
final long position = 0L;
final long length = Long.MAX_VALUE;
final long sessionId = archive.startReplay(recordingId, position, length, CHANNEL, REPLAY_STREAM_ID);
final String channel = ChannelUri.addSessionId(CHANNEL, (int) sessionId);
try (Subscription subscription = archive.context().aeron().addSubscription(channel, REPLAY_STREAM_ID)) {
SamplesUtil.subscriberLoop(fragmentHandler, FRAGMENT_COUNT_LIMIT, running).accept(subscription);
System.out.println("Shutting down...");
}
}
}
use of io.aeron.archive.client.AeronArchive in project aeron by real-logic.
the class ReplayedBasicSubscriber method findLatestRecording.
private static long findLatestRecording(final AeronArchive archive) {
final MutableLong lastRecordingId = new MutableLong();
final RecordingDescriptorConsumer consumer = (controlSessionId, correlationId, recordingId, startTimestamp, stopTimestamp, startPosition, stopPosition, initialTermId, segmentFileLength, termBufferLength, mtuLength, sessionId, streamId, strippedChannel, originalChannel, sourceIdentity) -> lastRecordingId.set(recordingId);
final long fromRecordingId = 0L;
final int recordCount = 100;
final int foundCount = archive.listRecordingsForUri(fromRecordingId, recordCount, CHANNEL, STREAM_ID, consumer);
if (foundCount == 0) {
throw new IllegalStateException("no recordings found");
}
return lastRecordingId.get();
}
use of io.aeron.archive.client.AeronArchive in project aeron by real-logic.
the class ArchiveCreator method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
*/
@SuppressWarnings("try")
public static void main(final String[] args) {
final String archiveDirName = Archive.Configuration.archiveDirName();
final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ? new File("archive") : new File(archiveDirName);
final MediaDriver.Context driverContext = new MediaDriver.Context().publicationTermBufferLength(TERM_LENGTH).termBufferSparseFile(true).threadingMode(ThreadingMode.SHARED).errorHandler(Throwable::printStackTrace).spiesSimulateConnection(true).dirDeleteOnStart(true);
final Archive.Context archiveContext = new Archive.Context().catalogCapacity(CATALOG_CAPACITY).segmentFileLength(SEGMENT_LENGTH).deleteArchiveOnStart(true).archiveDir(archiveDir).fileSyncLevel(0).threadingMode(ArchiveThreadingMode.SHARED);
System.out.println("Creating basic archive at " + archiveContext.archiveDir());
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverContext, archiveContext);
Aeron aeron = Aeron.connect();
AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron))) {
createRecording(aeron, aeronArchive, 0, (SEGMENT_LENGTH * 5L) + 1);
createRecording(aeron, aeronArchive, (long) TERM_LENGTH + (FrameDescriptor.FRAME_ALIGNMENT * 2), (SEGMENT_LENGTH * 3L) + 1);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
Aggregations