Search in sources :

Example 6 with Price

use of org.questdb.examples.support.Price in project questdb by bluestreak01.

the class SslReplicationServerMain method start.

public void start() throws Exception {
    Factory factory = new Factory(location, 1000, 1, 0);
    JournalServer server = new JournalServer(new ServerConfig() {

        {
            getSslConfig().setSecure(true);
            try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                getSslConfig().setKeyStore(is, "changeit");
            }
        }
    }, 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 : ServerConfig(com.questdb.net.ha.config.ServerConfig) Price(org.questdb.examples.support.Price) InputStream(java.io.InputStream) JournalServer(com.questdb.net.ha.JournalServer) Factory(com.questdb.store.factory.Factory)

Example 7 with Price

use of org.questdb.examples.support.Price in project questdb by bluestreak01.

the class AuthReplicationServerMain method publishPrice.

private void publishPrice(JournalWriter<Price> writer, int count) throws JournalException {
    long tZero = System.currentTimeMillis();
    System.out.println("sending: " + tZero);
    Price p = new Price();
    for (int i = 0; i < count; i++) {
        p.setTimestamp(tZero + i);
        p.setNanos(System.nanoTime());
        p.setSym(String.valueOf(i % 20));
        p.setPrice(i * 1.04598 + i);
        writer.append(p);
    }
    // commit triggers network publishing
    writer.commit();
}
Also used : Price(org.questdb.examples.support.Price)

Example 8 with Price

use of org.questdb.examples.support.Price 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)

Example 9 with Price

use of org.questdb.examples.support.Price in project questdb by bluestreak01.

the class ClusterConsumerMain method main.

public static void main(String[] args) throws Exception {
    final JournalConfiguration configuration = new JournalConfigurationBuilder() {

        {
            $(Price.class).$ts();
        }
    }.build(args[0]);
    final Factory factory = new Factory(configuration, 1000, 1, 0);
    final JournalClient client = new JournalClient(new ClientConfig("127.0.0.1:7080,127.0.0.1:7090") {

        {
            getReconnectPolicy().setRetryCount(6);
            getReconnectPolicy().setSleepBetweenRetriesMillis(1);
            getReconnectPolicy().setLoginRetryCount(2);
        }
    }, factory);
    final Journal<Price> reader = factory.reader(new JournalKey<>(Price.class, "price-copy", PartitionBy.NONE, 1000000000));
    reader.setSequentialAccess(true);
    client.subscribe(Price.class, null, "price-copy", 1000000000, 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++;
            }
            if (t == 0) {
                System.out.println("no data received");
            } else {
                System.out.println("took: " + (System.currentTimeMillis() - 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) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Example 10 with Price

use of org.questdb.examples.support.Price in project questdb by bluestreak01.

the class SimpleReplicationServerMain method publishPrice.

private void publishPrice(JournalWriter<Price> writer, int count) throws JournalException {
    long tZero = System.currentTimeMillis();
    System.out.println("sending: " + tZero);
    Price p = new Price();
    for (int i = 0; i < count; i++) {
        p.setTimestamp(tZero + i);
        p.setNanos(System.nanoTime());
        p.setSym(String.valueOf(i % 20));
        p.setPrice(i * 1.04598 + i);
        writer.append(p);
    }
    // commit triggers network publishing
    writer.commit();
}
Also used : Price(org.questdb.examples.support.Price)

Aggregations

Price (org.questdb.examples.support.Price)11 Factory (com.questdb.store.factory.Factory)8 JournalConfiguration (com.questdb.store.factory.configuration.JournalConfiguration)7 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)7 JournalClient (com.questdb.net.ha.JournalClient)4 JournalListener (com.questdb.store.JournalListener)4 JournalServer (com.questdb.net.ha.JournalServer)3 ClientConfig (com.questdb.net.ha.config.ClientConfig)3 ServerConfig (com.questdb.net.ha.config.ServerConfig)2 InputStream (java.io.InputStream)2 ClusterController (com.questdb.net.ha.ClusterController)1 ServerNode (com.questdb.net.ha.config.ServerNode)1 JournalWriter (com.questdb.store.JournalWriter)1