Java Code Examples for net.openhft.chronicle.bytes.MethodReader#readOne()
The following examples show how to use
net.openhft.chronicle.bytes.MethodReader#readOne() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TranslatorMain.java From Chronicle-Queue-Demo with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws InterruptedException { String pathfr = "queue-fr"; SingleChronicleQueue queuefr = SingleChronicleQueueBuilder.binary(pathfr).build(); MessageConsumer messageConsumer = queuefr.acquireAppender().methodWriter(MessageConsumer.class); MessageConsumer simpleTranslator = new SimpleTranslator(messageConsumer); String path_en = "queue-en"; SingleChronicleQueue queue_en = SingleChronicleQueueBuilder.binary(path_en).build(); MethodReader methodReader = queue_en.createTailer().methodReader(simpleTranslator); while (true) { if (!methodReader.readOne()) Thread.sleep(10); } }
Example 2
Source File: DumpDecodedMain.java From Chronicle-Queue-Demo with Apache License 2.0 | 6 votes |
public static void main(String[] args) { try (ChronicleQueue queue2 = ChronicleQueue.singleBuilder("out").sourceId(2).build()) { long last = Long.MAX_VALUE / 2; MethodReader methodReader = queue2.createTailer("dump") .methodReader(new EventHandler()); System.out.println("Started"); while (true) { long now = System.currentTimeMillis(); if (methodReader.readOne()) { last = now; } else { // stop if nothing for 2.5 seconds. if (now > last + 2500) break; Thread.yield(); } } } System.out.println(".. Finished"); System.exit(0); }
Example 3
Source File: JDBCService.java From Chronicle-Queue with Apache License 2.0 | 6 votes |
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 (!isClosed()) { if (reader.readOne()) pauser.reset(); else pauser.pause(); } } catch (Throwable t) { LOGGER.warn("Run loop exited", t); } }
Example 4
Source File: EventLoopServiceWrapper.java From Chronicle-Queue with Apache License 2.0 | 6 votes |
@Override public boolean action() throws InvalidEventHandlerException { if (isClosed()) { Closeable.closeQuietly(serviceImpl); Closeable.closeQuietly(serviceIn); Closeable.closeQuietly(outputQueue); Closeable.closeQuietly(inputQueues); throw new InvalidEventHandlerException(); } boolean busy = false; for (MethodReader reader : serviceIn) { busy |= reader.readOne(); } return busy; }
Example 5
Source File: OrderViewerMain.java From Chronicle-Queue-Demo with Apache License 2.0 | 5 votes |
public static void main(String[] args) { System.out.println("\nWaiting for messages"); try (ChronicleQueue q = SingleChronicleQueueBuilder.binary("in").rollCycle(RollCycles.TEST8_DAILY).build()) { OMSIn logging = Mocker.logging(OMSIn.class, "read - ", System.out); MethodReader reader = q.createTailer().methodReader(logging); while (true) { if (!reader.readOne()) Jvm.pause(50); } } }
Example 6
Source File: OutputMain.java From Chronicle-Queue-Demo with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws InterruptedException { String path = "queue-fr"; SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).build(); MessageConsumer messagePrinter = System.out::println; MethodReader methodReader = queue.createTailer().methodReader(messagePrinter); while (true) { if (!methodReader.readOne()) Thread.sleep(10); } }
Example 7
Source File: BridgeMain.java From Chronicle-Queue-Demo with Apache License 2.0 | 5 votes |
public static void main(String[] args) { IOTools.deleteDirWithFiles("in", 2); IOTools.deleteDirWithFiles("out", 2); long events = 0, lastPrint = 0; try (ChronicleQueue queue = ChronicleQueue.singleBuilder("in").sourceId(1).build()) { try (ChronicleQueue queue2 = ChronicleQueue.singleBuilder("out").sourceId(2).build()) { Events out = queue2.methodWriterBuilder(Events.class).recordHistory(true).build(); Events bridge = new BridgeEvents(out); MethodReader methodReader = queue.createTailer("bridge") .methodReader(bridge); System.out.println("Started"); long last = 0; while (running) { if (methodReader.readOne()) { events++; } else { long now = System.currentTimeMillis(); if (lastPrint != events && now > last + 250) { System.out.println("events: " + events); lastPrint = events; last = now; } else { Thread.yield(); } } } } } System.out.println("... finished"); }
Example 8
Source File: ResultGenerator.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
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 = ChronicleQueue.singleBuilder(lastStageConfig.getOutputPath()).build(); final Writer resultsWriter = new FileWriter("results.txt", false)) { final MethodReader methodReader = queue.createTailer().methodReader(new CapturingReceiver(resultsWriter)); while (methodReader.readOne()) { // report } } }
Example 9
Source File: MethodReaderQueueEntryHandler.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Override public void accept(final WireIn wireIn, final Consumer<String> messageHandler) { MethodReader methodReader = wireIn.methodReader(Mocker.intercepting(mrInterface, "", s -> { long hn = wireIn.headerNumber(); messageHandler.accept("header: " + hn + "\n" + s); })); while (methodReader.readOne()) { // read all } }
Example 10
Source File: MethodReaderObjectReuseTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void testOneOne() { ClassAliasPool.CLASS_ALIASES.addAlias(PingDTO.class); try (ChronicleQueue cq = SingleChronicleQueueBuilder.single(OS.TARGET + "/MethodReaderObjectReuseTest-" + System.nanoTime()).build()) { PingDTO.constructionExpected++; PingDTO pdtio = new PingDTO(); PingDTO.constructionExpected++; Pinger pinger = cq.acquireAppender().methodWriter(Pinger.class); for (int i = 0; i < 5; i++) { pinger.ping(pdtio); assertEquals(PingDTO.constructionExpected, PingDTO.constructionCounter); pdtio.bytes.append("hi"); } StringBuilder sb = new StringBuilder(); PingDTO.constructionExpected++; MethodReader reader = cq.createTailer() .methodReader( (Pinger) pingDTO -> sb.append("ping ").append(pingDTO)); assertEquals(PingDTO.constructionExpected, PingDTO.constructionCounter); while (reader.readOne()) ; assertEquals("ping !PingDTO {\n" + " bytes: \"\"\n" + "}\n" + "ping !PingDTO {\n" + " bytes: hi\n" + "}\n" + "ping !PingDTO {\n" + " bytes: hihi\n" + "}\n" + "ping !PingDTO {\n" + " bytes: hihihi\n" + "}\n" + "ping !PingDTO {\n" + " bytes: hihihihi\n" + "}\n", sb.toString()); } }
Example 11
Source File: JDBCServiceTest.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
private void doCreateTable(int repeats, int noUpdates) { for (int t = 0; t < repeats; t++) { long start = System.nanoTime(), written; File path1 = DirectoryUtils.tempDir("createTable1"); File path2 = DirectoryUtils.tempDir("createTable2"); File file = new File(OS.TARGET, "hsqldb-" + System.nanoTime()); file.deleteOnExit(); try (ChronicleQueue in = SingleChronicleQueueBuilder .binary(path1) .testBlockSize() .build(); ChronicleQueue out = SingleChronicleQueueBuilder .binary(path2) .testBlockSize() .build()) { JDBCService service = new JDBCService(in, out, () -> DriverManager.getConnection("jdbc:hsqldb:file:" + file.getAbsolutePath(), "SA", "")); JDBCStatement writer = service.createWriter(); writer.executeUpdate("CREATE TABLE tableName (\n" + "name VARCHAR(64) NOT NULL,\n" + "num INT\n" + ")\n"); for (int i = 1; i < (long) noUpdates; i++) writer.executeUpdate("INSERT INTO tableName (name, num)\n" + "VALUES (?, ?)", "name", i); written = System.nanoTime() - start; AtomicLong queries = new AtomicLong(); AtomicLong updates = new AtomicLong(); CountingJDBCResult countingJDBCResult = new CountingJDBCResult(queries, updates); MethodReader methodReader = service.createReader(countingJDBCResult); while (updates.get() < noUpdates) { if (!methodReader.readOne()) Thread.yield(); } Closeable.closeQuietly(service); long time = System.nanoTime() - start; System.out.printf("Average time to write each update %.1f us, average time to perform each update %.1f us%n", written / noUpdates / 1e3, time / noUpdates / 1e3); } finally { try { IOTools.deleteDirWithFiles(path1, 2); IOTools.deleteDirWithFiles(path2, 2); } catch (Exception e) { e.printStackTrace(); } } } }