Search in sources :

Example 6 with JournalConfiguration

use of com.questdb.store.factory.configuration.JournalConfiguration in project questdb by bluestreak01.

the class SimpleReplicationClientMain method main.

public static void main(String[] args) throws Exception {
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
    Factory factory = new Factory(configuration, 1000, 1, 0);
    final JournalClient client = new JournalClient(factory);
    final Journal<Price> reader = factory.reader(Price.class, "price-copy");
    reader.setSequentialAccess(true);
    client.subscribe(Price.class, null, "price-copy", new JournalListener() {

        @Override
        public void onCommit() {
            int count = 0;
            long t = 0;
            for (Price p : JournalIterators.incrementBufferedIterator(reader)) {
                if (count == 0) {
                    t = p.getNanos();
                }
                count++;
            }
            System.out.println("took: " + (System.nanoTime() - t) + ", count=" + count);
        }

        @Override
        public void onEvent(int event) {
            System.out.println("There was an error");
        }
    });
    client.start();
    System.out.println("Client started");
}
Also used : JournalClient(com.questdb.net.ha.JournalClient) JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Price(org.questdb.examples.support.Price) JournalListener(com.questdb.store.JournalListener) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder)

Example 7 with JournalConfiguration

use of com.questdb.store.factory.configuration.JournalConfiguration in project questdb by bluestreak01.

the class SimpleReplicationServerMain method start.

public void start() throws Exception {
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(location);
    Factory factory = new Factory(configuration, 1000, 1, 0);
    JournalServer server = new JournalServer(factory);
    JournalWriter<Price> writer = factory.writer(Price.class);
    server.publish(writer);
    server.start();
    System.out.print("Publishing: ");
    for (int i = 0; i < 10; i++) {
        publishPrice(writer, i < 3 ? 1000000 : 100);
        Thread.sleep(TimeUnit.SECONDS.toMillis(2));
        System.out.print('.');
    }
    System.out.println(" [Done]");
}
Also used : JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Price(org.questdb.examples.support.Price) JournalServer(com.questdb.net.ha.JournalServer) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder)

Example 8 with JournalConfiguration

use of com.questdb.store.factory.configuration.JournalConfiguration in project questdb by bluestreak01.

the class SslReplicationClientMain method main.

public static void main(String[] args) throws Exception {
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
    Factory factory = new Factory(configuration, 1000, 1, 0);
    final JournalClient client = new JournalClient(new ClientConfig() {

        {
            getSslConfig().setSecure(true);
            try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                getSslConfig().setTrustStore(is, "changeit");
            }
        }
    }, factory);
    final Journal<Price> reader = factory.reader(Price.class, "price-copy");
    reader.setSequentialAccess(true);
    client.subscribe(Price.class, null, "price-copy", new JournalListener() {

        @Override
        public void onCommit() {
            int count = 0;
            long t = 0;
            for (Price p : JournalIterators.incrementBufferedIterator(reader)) {
                if (count == 0) {
                    t = p.getNanos();
                }
                count++;
            }
            System.out.println("took: " + (System.nanoTime() - t) + ", count=" + count);
        }

        @Override
        public void onEvent(int event) {
            System.out.println("There was an error");
        }
    });
    client.start();
    System.out.println("Client started");
}
Also used : JournalClient(com.questdb.net.ha.JournalClient) JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Price(org.questdb.examples.support.Price) InputStream(java.io.InputStream) JournalListener(com.questdb.store.JournalListener) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Example 9 with JournalConfiguration

use of com.questdb.store.factory.configuration.JournalConfiguration in project questdb by bluestreak01.

the class AppendObjectTimeSeries method main.

/**
 * Appends 1 million quotes to journal. Timestamp values are in chronological order.
 */
public static void main(String[] args) throws JournalException {
    if (args.length != 1) {
        System.out.println("Usage: " + AppendObjectTimeSeries.class.getName() + " <path>");
        System.exit(1);
    }
    String journalLocation = args[0];
    JournalConfiguration configuration = new JournalConfigurationBuilder() {

        {
            $(Quote.class, "quote").$ts();
        }
    }.build(journalLocation);
    try (Factory factory = new Factory(configuration, 1000, 1, 0)) {
        // delete existing quote journal
        Files.delete(new File(configuration.getJournalBase(), "quote"));
        try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
            final int count = 1000000;
            final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
            final Random r = new Random(System.currentTimeMillis());
            // reuse same same instance of Quote class to keep GC under control
            final Quote q = new Quote();
            long t = System.nanoTime();
            for (int i = 0; i < count; i++) {
                // prepare object for new set of data
                q.clear();
                // generate some data
                q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
                q.setAsk(Math.abs(r.nextDouble()));
                q.setBid(Math.abs(r.nextDouble()));
                q.setAskSize(Math.abs(r.nextInt() % 10000));
                q.setBidSize(Math.abs(r.nextInt() % 10000));
                q.setEx("LXE");
                q.setMode("Fast trading");
                q.setTimestamp(System.currentTimeMillis());
                writer.append(q);
            }
            // commit is necessary
            writer.commit();
            System.out.println("Journal size: " + writer.size());
            System.out.println("Generated " + count + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
        }
    }
}
Also used : Quote(org.questdb.examples.support.Quote) JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Random(java.util.Random) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) File(java.io.File)

Example 10 with JournalConfiguration

use of com.questdb.store.factory.configuration.JournalConfiguration in project questdb by bluestreak01.

the class AuthReplicationServerMain method start.

public void start() throws Exception {
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(location);
    Factory factory = new Factory(configuration, 1000, 2, 0);
    JournalServer server = new JournalServer(factory, (token, requestedKeys) -> "MY SECRET".equals(new String(token, "UTF8")));
    JournalWriter<Price> writer = factory.writer(Price.class);
    server.publish(writer);
    server.start();
    System.out.print("Publishing: ");
    for (int i = 0; i < 10; i++) {
        publishPrice(writer, i < 3 ? 1000000 : 100);
        Thread.sleep(TimeUnit.SECONDS.toMillis(2));
        System.out.print('.');
    }
    System.out.println(" [Done]");
}
Also used : JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Price(org.questdb.examples.support.Price) JournalServer(com.questdb.net.ha.JournalServer) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder)

Aggregations

Factory (com.questdb.store.factory.Factory)11 JournalConfiguration (com.questdb.store.factory.configuration.JournalConfiguration)11 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)10 Price (org.questdb.examples.support.Price)7 JournalClient (com.questdb.net.ha.JournalClient)4 JournalListener (com.questdb.store.JournalListener)4 ClientConfig (com.questdb.net.ha.config.ClientConfig)3 JournalServer (com.questdb.net.ha.JournalServer)2 JournalWriter (com.questdb.store.JournalWriter)2 Quote (org.questdb.examples.support.Quote)2 LogFactory (com.questdb.log.LogFactory)1 MPSequence (com.questdb.mp.MPSequence)1 RingQueue (com.questdb.mp.RingQueue)1 SCSequence (com.questdb.mp.SCSequence)1 ClusterController (com.questdb.net.ha.ClusterController)1 ServerConfig (com.questdb.net.ha.config.ServerConfig)1 ServerNode (com.questdb.net.ha.config.ServerNode)1 QueryCompiler (com.questdb.parser.sql.QueryCompiler)1 RecordSource (com.questdb.ql.RecordSource)1 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)1