Search in sources :

Example 51 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleReaderTest method findByBinarySearchBeforeStart.

@Test
public void findByBinarySearchBeforeStart() {
    final File queueDir = getTmpDir();
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
        int max = 10, reps = 5;
        populateQueueWithTimestamps(queue, max, reps);
        // this should be before the start
        long tsToLookFor = getTimestampAtIndex(-1);
        ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
        reader.execute();
        assertEquals(max * reps, capturedOutput.size() / 2);
    }
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 52 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class ChronicleReaderTest method findByBinarySearchAfterEnd.

@Test
public void findByBinarySearchAfterEnd() {
    final File queueDir = getTmpDir();
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(queueDir).build()) {
        int max = 10, reps = 5;
        populateQueueWithTimestamps(queue, max, reps);
        // this should be after the end
        long tsToLookFor = getTimestampAtIndex(11);
        ChronicleReader reader = new ChronicleReader().withArg(ServicesTimestampLongConverter.INSTANCE.asString(tsToLookFor)).withBinarySearch(TimestampComparator.class.getCanonicalName()).withBasePath(queueDir.toPath()).withMessageSink(capturedOutput::add);
        reader.execute();
        assertEquals(0, capturedOutput.size());
    }
}
Also used : ChronicleReader(net.openhft.chronicle.queue.reader.ChronicleReader) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 53 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class QueueFileManager method update.

private void update() {
    long now = System.currentTimeMillis();
    if (lastUpdate + TIME_OUT > now)
        return;
    lastUpdate = now;
    Path path = Paths.get(basePath, relativePath);
    try (SingleChronicleQueue queue = SingleChronicleQueueBuilder.single(path.toFile()).readOnly(true).build()) {
        TableStore ts = queue.metaStore();
        tableStore = ts.shortDump();
        lastHeader = queue.dumpLastHeader();
    }
}
Also used : Path(java.nio.file.Path) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) TableStore(net.openhft.chronicle.queue.impl.TableStore)

Example 54 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class PublishDeltaGenerator method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        throw new IllegalArgumentException("Usage: <program> [resource-name]");
    }
    Jvm.setExceptionHandlers((c, m, t) -> {
    // System.out.println(m);
    }, (c, m, t) -> {
        // System.out.println(m);
        t.printStackTrace();
    }, (c, m, t) -> System.out.println(m));
    final ConfigParser configParser = new ConfigParser(args[0]);
    final List<StageConfig> allStageConfigs = configParser.getAllStageConfigs();
    final StageConfig lastStageConfig = allStageConfigs.get(allStageConfigs.size() - 1);
    try (final SingleChronicleQueue pubQueue = ChronicleQueue.singleBuilder(configParser.getPublisherConfig().outputDir()).build();
        final SingleChronicleQueue queue = ChronicleQueue.singleBuilder(lastStageConfig.getOutputPath()).build();
        final Writer resultsWriter = new FileWriter("publish-deltas.txt", false);
        final Writer s0Pub = new FileWriter("s0-deltas.txt", false);
        final Writer s1Pub = new FileWriter("s1-deltas.txt", false);
        final Writer s0s2Pub = new FileWriter("s0-s2-deltas.txt", false);
        final Writer s1s2Pub = new FileWriter("s1-s2-deltas.txt", false)) {
        final MethodReader reader = pubQueue.createTailer().methodReader(new CapturingReceiver(resultsWriter, m -> m.publishNanos));
        while (reader.readOne()) {
        // report
        }
        final MethodReader methodReader = queue.createTailer().methodReader(new DelegatingReceiver(new CapturingReceiver(s0Pub, m -> m.t0), new CapturingReceiver(s1Pub, m -> m.t1), new CapturingReceiver(s0s2Pub, m -> m.t2, 5), new CapturingReceiver(s1s2Pub, m -> m.t2, 6)));
        while (methodReader.readOne()) {
        // report
        }
    }
}
Also used : MethodReader(net.openhft.chronicle.bytes.MethodReader) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) FileWriter(java.io.FileWriter) LocalDateTime(java.time.LocalDateTime) IOException(java.io.IOException) EightyByteMessage(net.openhft.load.messages.EightyByteMessage) Jvm(net.openhft.chronicle.core.Jvm) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) StageConfig(net.openhft.load.config.StageConfig) DateTimeFormatter(java.time.format.DateTimeFormatter) Writer(java.io.Writer) ZoneOffset(java.time.ZoneOffset) ToLongFunction(java.util.function.ToLongFunction) ConfigParser(net.openhft.load.config.ConfigParser) FileWriter(java.io.FileWriter) ConfigParser(net.openhft.load.config.ConfigParser) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue) MethodReader(net.openhft.chronicle.bytes.MethodReader) StageConfig(net.openhft.load.config.StageConfig) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 55 with SingleChronicleQueue

use of net.openhft.chronicle.queue.impl.single.SingleChronicleQueue in project Chronicle-Queue by OpenHFT.

the class PublisherMain method createOutput.

private static MethodDefinition createOutput(final Path path) {
    final SingleChronicleQueue queue = outputQueue(path);
    final ExcerptAppender appender = queue.acquireAppender();
    return new GarbageFreeMethodPublisher(() -> appender);
}
Also used : ExcerptAppender(net.openhft.chronicle.queue.ExcerptAppender) SingleChronicleQueue(net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)

Aggregations

SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)70 Test (org.junit.Test)54 File (java.io.File)31 DocumentContext (net.openhft.chronicle.wire.DocumentContext)15 RandomAccessFile (java.io.RandomAccessFile)14 ChronicleReader (net.openhft.chronicle.queue.reader.ChronicleReader)13 SetTimeProvider (net.openhft.chronicle.core.time.SetTimeProvider)12 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)10 Ignore (org.junit.Ignore)10 NotNull (org.jetbrains.annotations.NotNull)9 MethodReader (net.openhft.chronicle.bytes.MethodReader)8 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)8 InternalAppender (net.openhft.chronicle.queue.impl.single.InternalAppender)7 Bytes (net.openhft.chronicle.bytes.Bytes)5 Path (java.nio.file.Path)4 OS (net.openhft.chronicle.core.OS)4 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)4 Assert (org.junit.Assert)4 IOException (java.io.IOException)3 TimeUnit (java.util.concurrent.TimeUnit)3