net.openhft.chronicle.core.pool.ClassAliasPool Java Examples
The following examples show how to use
net.openhft.chronicle.core.pool.ClassAliasPool.
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: OrderAdderMain.java From Chronicle-Queue-Demo with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { ClassAliasPool.CLASS_ALIASES.addAlias(NewOrderSingle.class); try (ChronicleQueue q = SingleChronicleQueueBuilder.binary("in").rollCycle(RollCycles.TEST8_DAILY).build()) { OMSIn in = q.acquireAppender().methodWriter(OMSIn.class); OMSIn in2 = Mocker.logging(OMSIn.class, "in - ", System.out); NewOrderSingle nos = new NewOrderSingle() .sender(toLong("sender")) .target(toLong("target")) .transactTime(now()) .sendingTime(now()) .orderQty(1) .ordType(OrderType.market) .side(BuySell.buy) .symbol(toLong("EURUSD")); System.out.println("\nHit blank line to add an order, anything else to exit"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int counter = 0; while ("".equals(br.readLine())) { nos.clOrdID(Long.toString(counter++)); in.newOrderSingle(nos); in2.newOrderSingle(nos); } } System.out.println("Finished"); System.exit(0); }
Example #2
Source File: ArrayTest.java From Chronicle-Map with Apache License 2.0 | 5 votes |
@Test public void test0() throws IOException, JSONException{ ClassAliasPool.CLASS_ALIASES.addAlias(MovingAverageArray.class); File file = new File(OS.getTarget() + "/pf-PosistionsAndClose-" + System.nanoTime()); ChronicleMap<Long, MovingAverageArray> mapWrite = ChronicleMap .of(Long.class, MovingAverageArray.class) .entries(100) .averageValue(createSampleWithSize(6, 0)) .createPersistedTo(file); mapWrite.put(1L, createSampleWithSize(6, 1)); mapWrite.put(2L, createSampleWithSize(4, 2)); mapWrite.close(); ChronicleMap<Long, MovingAverageArray> mapRead = ChronicleMapBuilder .of(Long.class, MovingAverageArray.class) .createPersistedTo(file); MovingAverageArray m = mapRead.get(1L); assertJSONEqualsAfterPrefix("!MovingAverageArray {\n" + " values: [\n" + " { movingAverage: 0.1, high: 0.1, low: 0.1, stdDev: 0.1 },\n" + " { movingAverage: 1.1, high: 1.1, low: 1.1, stdDev: 1.1 },\n" + " { movingAverage: 2.1, high: 2.1, low: 2.1, stdDev: 2.1 },\n" + " { movingAverage: 3.1, high: 3.1, low: 3.1, stdDev: 3.1 },\n" + " { movingAverage: 4.1, high: 4.1, low: 4.1, stdDev: 4.1 },\n" + " { movingAverage: 5.1, high: 5.1, low: 5.1, stdDev: 5.1 }\n" + " ]\n" + "}\n", m.toString()); MovingAverageArray m2 = mapRead.getUsing(2L, m); assertSame(m, m2); // object is recycled, so no objects are created. assertJSONEqualsAfterPrefix("!MovingAverageArray {\n" + " values: [\n" + " { movingAverage: 0.2, high: 0.2, low: 0.2, stdDev: 0.2 },\n" + " { movingAverage: 1.2, high: 1.2, low: 1.2, stdDev: 1.2 },\n" + " { movingAverage: 2.2, high: 2.2, low: 2.2, stdDev: 2.2 },\n" + " { movingAverage: 3.2, high: 3.2, low: 3.2, stdDev: 3.2 }\n" + " ]\n" + "}\n", m.toString()); }
Example #3
Source File: MessageReaderWriterTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void testWriteWhileReading() { ClassAliasPool.CLASS_ALIASES.addAlias(Message1.class); ClassAliasPool.CLASS_ALIASES.addAlias(Message2.class); File path1 = DirectoryUtils.tempDir("testWriteWhileReading1"); File path2 = DirectoryUtils.tempDir("testWriteWhileReading2"); try (ChronicleQueue queue1 = SingleChronicleQueueBuilder .binary(path1) .testBlockSize() .build(); ChronicleQueue queue2 = SingleChronicleQueueBuilder .binary(path2) .testBlockSize() .build()) { MethodReader reader2 = queue1.createTailer().methodReader(ObjectUtils.printAll(MessageListener.class)); MessageListener writer2 = queue2.acquireAppender().methodWriter(MessageListener.class); MessageListener processor = new MessageProcessor(writer2); MethodReader reader1 = queue1.createTailer().methodReader(processor); MessageListener writer1 = queue1.acquireAppender().methodWriter(MessageListener.class); for (int i = 0; i < 3; i++) { // write a message writer1.method1(new Message1("hello")); writer1.method2(new Message2(234)); // read those messages assertTrue(reader1.readOne()); assertTrue(reader1.readOne()); assertFalse(reader1.readOne()); // read the produced messages assertTrue(reader2.readOne()); assertTrue(reader2.readOne()); assertFalse(reader2.readOne()); } // System.out.println(queue1.dump()); } }
Example #4
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 #5
Source File: SingleCQFormat2Test.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void testMyData() { @NotNull File dir = getTmpDir(); ClassAliasPool.CLASS_ALIASES.addAlias(MyData.class); try (@NotNull ChronicleQueue queue = binary(dir) .rollCycle(RollCycles.TEST_DAILY) .blockSize(ChronicleQueue.TEST_BLOCK_SIZE).build()) { @NotNull ExcerptAppender appender = queue.acquireAppender(); try (DocumentContext dc = appender.writingDocument()) { @NotNull MyData name = new MyData("name", 12345, 1.2, 111); System.out.println(name); name.writeMarshallable(dc.wire()); @NotNull MyData name2 = new MyData("name2", 12346, 1.3, 112); System.out.println(name2); name2.writeMarshallable(dc.wire()); } String dump = queue.dump(); assertTrue(dump, dump.contains("--- !!meta-data #binary\n" + "index: [\n" + " # length: 8, used: 1\n" + " 392,\n" + " 0, 0, 0, 0, 0, 0, 0\n" + "]")); } }
Example #6
Source File: SingleCQFormat2Test.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@Test public void writeMarshallable() { ClassAliasPool.CLASS_ALIASES.addAlias(Order.class); @NotNull File dir = getTmpDir(); try (@NotNull ChronicleQueue queue = binary(dir) .rollCycle(RollCycles.TEST_DAILY) .blockSize(ChronicleQueue.TEST_BLOCK_SIZE) .build()) { @NotNull ExcerptAppender appender = queue.acquireAppender(); appender.writeDocument(new Order("Symbol", Side.Buy, 1.2345, 1e6)); appender.writeDocument(w -> w.write("newOrder").object(new Order("Symbol2", Side.Sell, 2.999, 10e6))); String expectedEager = "--- !!meta-data #binary\n" + "header: !SCQStore {\n" + " writePosition: [\n" + " 448,\n" + " 1924145348609\n" + " ],\n" + " indexing: !SCQSIndexing {\n" + " indexCount: 8,\n" + " indexSpacing: 1,\n" + " index2Index: 196,\n" + " lastIndex: 2\n" + " },\n" + " dataFormat: 1\n" + "}\n" + "# position: 196, header: -1\n" + "--- !!meta-data #binary\n" + "index2index: [\n" + " # length: 8, used: 1\n" + " 296,\n" + " 0, 0, 0, 0, 0, 0, 0\n" + "]\n" + "# position: 296, header: -1\n" + "--- !!meta-data #binary\n" + "index: [\n" + " # length: 8, used: 2\n" + " 392,\n" + " 448,\n" + " 0, 0, 0, 0, 0, 0\n" + "]\n" + "# position: 392, header: 0\n" + "--- !!data #binary\n" + "symbol: Symbol\n" + "side: Buy\n" + "limitPrice: 1.2345\n" + "quantity: 1E6\n" + "# position: 448, header: 1\n" + "--- !!data #binary\n" + "newOrder: !Order {\n" + " symbol: Symbol2,\n" + " side: Sell,\n" + " limitPrice: 2.999,\n" + " quantity: 10E6\n" + "}\n" + "...\n" + "# 130540 bytes remaining\n"; assertEquals(expectedEager, queue.dump()); } }