Search in sources :

Example 46 with AeronArchive

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;
        }
    }
}
Also used : Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 47 with AeronArchive

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());
    }
}
Also used : Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test)

Example 48 with AeronArchive

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...");
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FragmentHandler(io.aeron.logbuffer.FragmentHandler) Subscription(io.aeron.Subscription) AeronArchive(io.aeron.archive.client.AeronArchive)

Example 49 with AeronArchive

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();
}
Also used : MutableLong(org.agrona.collections.MutableLong) Subscription(io.aeron.Subscription) RecordingDescriptorConsumer(io.aeron.archive.client.RecordingDescriptorConsumer) SampleConfiguration(io.aeron.samples.SampleConfiguration) AeronArchive(io.aeron.archive.client.AeronArchive) ChannelUri(io.aeron.ChannelUri) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FragmentHandler(io.aeron.logbuffer.FragmentHandler) SamplesUtil(io.aeron.samples.SamplesUtil) SigInt(org.agrona.concurrent.SigInt) MutableLong(org.agrona.collections.MutableLong) RecordingDescriptorConsumer(io.aeron.archive.client.RecordingDescriptorConsumer)

Example 50 with AeronArchive

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();
    }
}
Also used : Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) File(java.io.File) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron)

Aggregations

AeronArchive (io.aeron.archive.client.AeronArchive)54 Test (org.junit.jupiter.api.Test)28 MediaDriver (io.aeron.driver.MediaDriver)26 File (java.io.File)17 Aeron (io.aeron.Aeron)14 CommonContext (io.aeron.CommonContext)12 Context (io.aeron.archive.Archive.Context)12 InterruptAfter (io.aeron.test.InterruptAfter)12 Tests (io.aeron.test.Tests)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Archive (io.aeron.archive.Archive)10 ArchiveException (io.aeron.archive.client.ArchiveException)10 CountersReader (org.agrona.concurrent.status.CountersReader)10 Publication (io.aeron.Publication)8 FileStore (java.nio.file.FileStore)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)8 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)8 ChannelUriStringBuilder (io.aeron.ChannelUriStringBuilder)7 DEDICATED (io.aeron.archive.ArchiveThreadingMode.DEDICATED)6