Search in sources :

Example 21 with MethodReader

use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.

the class ResultGenerator method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        throw new IllegalArgumentException("Usage: <program> [resource-name]");
    }
    final ConfigParser configParser = new ConfigParser(args[0]);
    final List<StageConfig> allStageConfigs = configParser.getAllStageConfigs();
    final StageConfig lastStageConfig = allStageConfigs.get(allStageConfigs.size() - 1);
    Jvm.setExceptionHandlers((c, m, t) -> {
        System.out.println(m);
    }, (c, m, t) -> {
        System.out.println(m);
        if (t != null) {
            t.printStackTrace();
        }
    }, (c, m, t) -> System.out.println(m));
    try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(lastStageConfig.getOutputPath()).build();
        final Writer resultsWriter = new FileWriter("results.txt", false)) {
        final MethodReader methodReader = queue.createTailer().methodReader(new CapturingReceiver(resultsWriter));
        while (methodReader.readOne()) {
        // report
        }
    }
}
Also used : 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 22 with MethodReader

use of net.openhft.chronicle.bytes.MethodReader in project Chronicle-Queue by OpenHFT.

the class JDBCService method runLoop.

void runLoop() {
    try {
        JDBCResult result = out.acquireAppender().methodWriterBuilder(JDBCResult.class).recordHistory(true).get();
        JDBCComponent js = new JDBCComponent(connectionSupplier, result);
        MethodReader reader = in.createTailer().afterLastWritten(out).methodReader(js);
        Pauser pauser = Pauser.millis(1, 10);
        while (!closed) {
            if (reader.readOne())
                pauser.reset();
            else
                pauser.pause();
        }
    } catch (Throwable t) {
        LOGGER.warn("Run loop exited", t);
    }
}
Also used : MethodReader(net.openhft.chronicle.bytes.MethodReader) Pauser(net.openhft.chronicle.threads.Pauser)

Aggregations

MethodReader (net.openhft.chronicle.bytes.MethodReader)22 Test (org.junit.Test)13 SingleChronicleQueue (net.openhft.chronicle.queue.impl.single.SingleChronicleQueue)10 File (java.io.File)9 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)6 IOException (java.io.IOException)3 OS (net.openhft.chronicle.core.OS)3 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)3 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)3 ConfigParser (net.openhft.load.config.ConfigParser)3 StageConfig (net.openhft.load.config.StageConfig)3 FileWriter (java.io.FileWriter)2 Writer (java.io.Writer)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 IOTools (net.openhft.chronicle.core.io.IOTools)2 RollCycles (net.openhft.chronicle.queue.RollCycles)2 MessageHistory (net.openhft.chronicle.wire.MessageHistory)2 Assert (org.junit.Assert)2 Assert.assertEquals (org.junit.Assert.assertEquals)2