Package com.higherfrequencytrading.chronicle

Examples of com.higherfrequencytrading.chronicle.Chronicle


        ChronicleTools.deleteOnExit(basePath1);
        ChronicleTools.deleteOnExit(basePath2);
        ChronicleTools.deleteOnExit(basePath3);

        Chronicle chronicle2w = new IndexedChronicle(basePath2);
        EventsWriter writer2 = new EventsWriter(chronicle2w);

        Chronicle chronicle1 = new IndexedChronicle(basePath1);
        InProcessChronicleSink sink = new InProcessChronicleSink(chronicle1, HOST, PORT);
        final EventsReader sinkReader = new EventsReader(sink.createExcerpt(), new BrokerEvents(writer2),
                TimingStage.SourceRead, TimingStage.EngineWrite);

        Thread cbt = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("CB: Waiting to consume events");
                // first broker thread.
                while (true) {
                    if (!sinkReader.read())
                        pause();
                }
            }
        }, "central broker");
        cbt.start();

        Chronicle chronicle3 = new IndexedChronicle(basePath3);
        InProcessChronicleSource source3 = new InProcessChronicleSource(chronicle3, PORT3);
        source3.busyWaitTimeNS(2 * 1000 * 1000);
        EventsWriter writer3 = new EventsWriter(source3);

        Chronicle chronicle2r = new IndexedChronicle(basePath2);
        final EventsReader reader2 = new EventsReader(chronicle2r.createExcerpt(),
                new BrokerEvents(writer3), TimingStage.EngineRead, TimingStage.SinkWrite);

        Thread pet = new Thread(new Runnable() {
            @Override
            public void run() {
View Full Code Here


    public static void main(String... ignored) throws IOException, InterruptedException {
        String basePath = TMP + "/1-source";
        ChronicleTools.deleteOnExit(basePath);

        Chronicle chronicle = new IndexedChronicle(basePath);
        InProcessChronicleSource source = new InProcessChronicleSource(chronicle, PORT);
        source.busyWaitTimeNS(2 * 1000 * 1000);

        EventsWriter writer = new EventsWriter(source);

View Full Code Here

    public static void main(String... ignored) throws IOException, InterruptedException {
        String basePath3 = TMP + "/3-sink";

        ChronicleTools.deleteOnExit(basePath3);

        Chronicle chronicle3 = new IndexedChronicle(basePath3);
        InProcessChronicleSink sink3 = new InProcessChronicleSink(chronicle3, HOST3, PORT3);
        final EventsReader sinkReader = new EventsReader(sink3.createExcerpt(), new LatencyEvents(), TimingStage.SinkRead, TimingStage.EngineWrite);

        while (true) {
            if (!sinkReader.read())
View Full Code Here

            intListener.inSync();

            replay(stringsListener);
            replay(intListener);

            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            SetWrapper<String> strings = new SetWrapper<String>(dataStore, "strings", String.class, new LinkedHashSet<String>(), 8);
            strings.addListener(stringsListener);
            SetWrapper<Integer> ints = new SetWrapper<Integer>(dataStore, "ints", Integer.class, new LinkedHashSet<Integer>(), 6);
            ints.addListener(intListener);

            dataStore.start();

            ints.add(0);
            strings.add("Hello");
            ints.add(1);
            strings.add("World");
            ints.add(2);

            strings.publishEvent("bye");
            ints.publishEvent("now");

            verify(stringsListener);
            verify(intListener);

            assertEquals("[Hello, World]", strings.toString());
            assertEquals("[0, 1, 2]", ints.toString());
            assertEquals(String[].class, strings.toArray().getClass());

            chronicle.close();
        }
        {
            SetListener stringsListener = createMock("strings", SetListener.class);
            stringsListener.eventStart(7, "strings");
            stringsListener.add("!");
            stringsListener.eventEnd(true);

            SetListener intListener = createMock("ints", SetListener.class);

            intListener.eventStart(8, "ints");
            intListener.add(3);
            intListener.eventEnd(true);

            stringsListener.inSync();
            intListener.inSync();

            replay(stringsListener);
            replay(intListener);
            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            SetWrapper<String> strings = new SetWrapper<String>(dataStore, "strings", String.class, new LinkedHashSet<String>(), 8);
            strings.addListener(stringsListener);
            SetWrapper<Integer> ints = new SetWrapper<Integer>(dataStore, "ints", Integer.class, new LinkedHashSet<Integer>(), 6);
            ints.addListener(intListener);
            // assume we have  all the events written so far
            dataStore.start(chronicle.size() - 1);

            strings.add("!");
            ints.add(3);

            verify(stringsListener);
            verify(intListener);

            assertEquals("[Hello, World, !]", strings.toString());
            assertEquals("[0, 1, 2, 3]", ints.toString());
            chronicle.close();
        }
    }
View Full Code Here

        String name = TMP + "/testSetPerformance";
        ChronicleTools.deleteOnExit(name);
        long start = System.nanoTime();
        int size;
        {
            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            SetWrapper<String> strings = new SetWrapper<String>(dataStore, "test", String.class, new LinkedHashSet<String>(), 9);
            SetWrapper<Integer> ints = new SetWrapper<Integer>(dataStore, "ints", Integer.class, new LinkedHashSet<Integer>(), 9);
            dataStore.start();
            ints.clear();
            strings.clear();
            for (int i = 0; i < 1000000; i++) {
                ints.add(i);
                strings.add(Integer.toString(i));
            }
            size = Math.min(strings.size(), ints.size());
            for (int i = 0; i < 1000000; i++) {
                ints.remove(i);
                strings.remove(Integer.toString(i));
            }

            chronicle.close();
        }
        long mid = System.nanoTime();
        {
            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            SetWrapper<String> strings = new SetWrapper<String>(dataStore, "test", String.class, new LinkedHashSet<String>(), 9);
            SetWrapper<Integer> ints = new SetWrapper<Integer>(dataStore, "ints", Integer.class, new LinkedHashSet<Integer>(), 9);
            dataStore.start();
            chronicle.close();
        }
        long end = System.nanoTime();
        System.out.printf("Took %.1f seconds avg to add&remove %,d elements and %.1f seconds avg to reload them%n",
                (mid - start) / 2e9, size, (end - mid) / 2e9);
    }
View Full Code Here

*/
public class JETest {
    public static void main(String[] args) throws Exception {
        final String basePath = "test";
        ChronicleTools.deleteOnExit(basePath);
        final Chronicle chronicle = new IntIndexedChronicle(basePath);
        final Excerpt excerpt = chronicle.createExcerpt();
        final int[] consolidates = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
        int repeats = 10000;
        for (int i = 0; i < repeats; i++) {
            excerpt.startExcerpt(8 + 4 + 4 * consolidates.length);
            excerpt.writeLong(System.nanoTime());
            excerpt.writeInt(consolidates.length);
            for (final int consolidate : consolidates) {
                excerpt.writeInt(consolidate);
            }
            excerpt.finish();
        }

        long[] times = new long[repeats];
        int[] nbcs = new int[repeats];
        int count = 0;
        final Excerpt excerpt2 = chronicle.createExcerpt();
        while (excerpt2.nextIndex()) {
            final long timestamp = excerpt2.readLong();
            long time = System.nanoTime() - timestamp;
            times[count] = time;
            final int nbConsolidates = excerpt2.readInt();
            nbcs[count] = nbConsolidates;
            for (int i = 0; i < nbConsolidates; i++) {
                excerpt2.readInt();
            }
            excerpt2.finish();
            count++;
        }
        for (int i = 0; i < count; i++) {
            System.out.print("latency: " + times[i] / repeats / 1e3 + " us average, ");
            System.out.println("nbConsolidates: " + nbcs[i]);
        }
        chronicle.close();
    }
View Full Code Here

        if x % 1000 == 0:
          print '... row %d' % x
*/

        String basePath = baseDir + "/deleteme.int";
        Chronicle chronicle = new IntIndexedChronicle(basePath);
        deleteOnExit(basePath);

        Excerpt record = chronicle.createExcerpt();
        final int warmup = 20000;
        final int rows = 1000000;

        byte[] xs = new byte[120];
        Arrays.fill(xs, (byte) 'x');
View Full Code Here

            stringsListener.inSync();
            intListener.inSync();

            replay(stringsListener);
            replay(intListener);
            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            ListWrapper<String> strings = new ListWrapper<String>(dataStore, "strings", String.class, new ArrayList<String>(), 8);
            strings.addListener(stringsListener);
            ListWrapper<Integer> ints = new ListWrapper<Integer>(dataStore, "ints", Integer.class, new ArrayList<Integer>(), 6);
            ints.addListener(intListener);

            dataStore.start();

            ints.add(0);
            strings.add("Hello");
            ints.add(1);
            strings.add("World");
            ints.add(2);

            strings.publishEvent("bye");
            ints.publishEvent("now");

            verify(stringsListener);
            verify(intListener);

            assertEquals("[Hello, World]", strings.toString());
            assertEquals("[0, 1, 2]", ints.toString());
            assertEquals(String[].class, strings.toArray().getClass());

            chronicle.close();
        }
        {
            ListListener stringsListener = createMock("strings", ListListener.class);
            stringsListener.eventStart(7, "strings");
            stringsListener.add("!");
            stringsListener.eventEnd(true);

            ListListener intListener = createMock("ints", ListListener.class);

            intListener.eventStart(8, "ints");
            intListener.add(3);
            intListener.eventEnd(true);

            stringsListener.inSync();
            intListener.inSync();

            replay(stringsListener);
            replay(intListener);

            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            ListWrapper<String> strings = new ListWrapper<String>(dataStore, "strings", String.class, new ArrayList<String>(), 8);
            strings.addListener(stringsListener);
            ListWrapper<Integer> ints = new ListWrapper<Integer>(dataStore, "ints", Integer.class, new ArrayList<Integer>(), 6);
            ints.addListener(intListener);

            // assume we have  all the events written so far
            dataStore.start(chronicle.size() - 1);

            strings.add("!");
            ints.add(3);

            verify(stringsListener);
            verify(intListener);

            assertEquals("[Hello, World, !]", strings.toString());
            assertEquals("[0, 1, 2, 3]", ints.toString());
            chronicle.close();
        }
    }
View Full Code Here

        String name = TMP + "/testListPerformance";
        ChronicleTools.deleteOnExit(name);
        long start = System.nanoTime();
        int size = 0;
        {
            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            ListWrapper<String> strings = new ListWrapper<String>(dataStore, "test", String.class, new ArrayList<String>(), 9);
            ListWrapper<Integer> ints = new ListWrapper<Integer>(dataStore, "ints", Integer.class, new ArrayList<Integer>(), 9);
            dataStore.start();
            ints.clear();
            strings.clear();
            for (int j = 0; j < 10000; j++) {
                for (int i = 0; i < 100; i++) {
                    ints.add(i);
                    strings.add(Integer.toString(i));
                }
                size += Math.min(strings.size(), ints.size());
                for (int i = 0; i < 100; i++) {
                    ints.remove((Integer) i);
                    strings.remove(i);
                }
            }

            chronicle.close();
        }
        long mid = System.nanoTime();
        {
            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            ListWrapper<String> strings = new ListWrapper<String>(dataStore, "test", String.class, new ArrayList<String>(), 9);
            ListWrapper<Integer> ints = new ListWrapper<Integer>(dataStore, "ints", Integer.class, new ArrayList<Integer>(), 9);
            dataStore.start();
            chronicle.close();
        }
        long end = System.nanoTime();
        System.out.printf("Took %.1f seconds avg to add&remove %,d elements and %.1f seconds avg to reload them%n",
                (mid - start) / 2e9, size, (end - mid) / 2e9);
    }
View Full Code Here

        String name = TMP + "/inject";
        ChronicleTools.deleteOnExit(name);
        for (int i = 0; i < 10; i++) {
            ExampleDataModel model = new ExampleDataModel();

            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            dataStore.inject(model);
            final AtomicInteger map2Count = new AtomicInteger();
            model.map2.addListener(new AbstractMapListener<Date, ExampleDataModel.MyType>() {
                @Override
                public void update(Date key, ExampleDataModel.MyType oldValue, ExampleDataModel.MyType newValue) {
                    map2Count.incrementAndGet();
                }
            });
            final AtomicInteger list2Count = new AtomicInteger();
            model.list2.addListener(new AbstractCollectionListener<ExampleDataModel.MyType>() {
                @Override
                public void add(ExampleDataModel.MyType element) {
                    list2Count.incrementAndGet();
                }
            });
            final AtomicInteger set2Count = new AtomicInteger();
            model.set2.addListener(new AbstractCollectionListener<ExampleDataModel.MyType>() {
                @Override
                public void add(ExampleDataModel.MyType element) {
                    set2Count.incrementAndGet();
                }
            });
            dataStore.start();

            model.map.put(new Date(i * 1000), new ExampleDataModel.MyType());
            model.map2.put(new Date(i * 1000), new ExampleDataModel.MyType());
            model.list.add(new ExampleDataModel.MyType());
            model.list2.add(new ExampleDataModel.MyType());
            model.set.add(new ExampleDataModel.MyType());
            model.set2.add(new ExampleDataModel.MyType());

            assertEquals(i + 1, model.map.size());
            assertEquals(i + 1, map2Count.get());
            assertEquals(i + 1, model.list.size());
            assertEquals(i + 1, list2Count.get());
            assertEquals(i + 1, model.set.size());
            assertEquals(i + 1, set2Count.get());
            MyAnnotation annotation = model.map2.getAnnotation(MyAnnotation.class);
            assertNotNull(annotation);
            assertEquals("My text", annotation.value());
            chronicle.close();
        }
    }
View Full Code Here

TOP

Related Classes of com.higherfrequencytrading.chronicle.Chronicle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.