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);
}
}
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());
}
}
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();
}
}
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
}
}
}
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);
}
Aggregations