Search in sources :

Example 11 with Factory

use of com.questdb.store.factory.Factory 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 12 with Factory

use of com.questdb.store.factory.Factory 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 13 with Factory

use of com.questdb.store.factory.Factory 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 14 with Factory

use of com.questdb.store.factory.Factory 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 15 with Factory

use of com.questdb.store.factory.Factory in project questdb by bluestreak01.

the class BootstrapMain method main.

public static void main(String[] args) throws Exception {
    System.err.printf("QuestDB HTTP Server %s%nCopyright (C) Appsicle 2014-2018, all rights reserved.%n%n", getVersion());
    if (args.length < 1) {
        System.err.println("Root directory name expected");
        return;
    }
    if (Os.type == Os._32Bit) {
        System.err.println("QuestDB requires 64-bit JVM");
        return;
    }
    final CharSequenceObjHashMap<String> optHash = hashArgs(args);
    // expected flags:
    // -d <root dir> = sets root directory
    // -f = forces copy of site to root directory even if site exists
    // -n = disables handling of HUP signal
    String dir = optHash.get("-d");
    extractSite(dir, optHash.get("-f") != null);
    File conf = new File(dir, "conf/questdb.conf");
    if (!conf.exists()) {
        System.err.println("Configuration file does not exist: " + conf);
        return;
    }
    BootstrapEnv env = new BootstrapEnv();
    // main configuration
    env.configuration = new ServerConfiguration(conf);
    configureLoggers(env.configuration);
    env.dateFormatFactory = new DateFormatFactory();
    env.dateLocaleFactory = DateLocaleFactory.INSTANCE;
    env.typeProbeCollection = new TypeProbeCollection(new File(dir, "conf/date.formats").getAbsolutePath(), env.dateFormatFactory, env.dateLocaleFactory);
    // reader/writer factory and cache
    env.factory = new Factory(env.configuration.getDbPath().getAbsolutePath(), env.configuration.getDbPoolIdleTimeout(), env.configuration.getDbReaderPoolSize(), env.configuration.getDbPoolIdleCheckInterval());
    // URL matcher configuration
    env.matcher = new SimpleUrlMatcher();
    env.matcher.put("/imp", new ImportHandler(env));
    env.matcher.put("/exec", new QueryHandler(env));
    env.matcher.put("/exp", new CsvHandler(env));
    env.matcher.put("/chk", new ExistenceCheckHandler(env));
    env.matcher.setDefaultHandler(new StaticContentHandler(env));
    // server configuration
    // add all other jobs to server as it will be scheduling workers to do them
    final HttpServer server = new HttpServer(env);
    // monitoring setup
    final FactoryEventLogger factoryEventLogger = new FactoryEventLogger(env.factory, 10000000, 5000, MicrosecondClockImpl.INSTANCE);
    ObjHashSet<Job> jobs = server.getJobs();
    jobs.addAll(LogFactory.INSTANCE.getJobs());
    jobs.add(factoryEventLogger);
    env.factory.exportJobs(jobs);
    // welcome message
    CharSink welcome = Misc.getThreadLocalBuilder();
    if (!server.start()) {
        welcome.put("Could not bind socket ").put(env.configuration.getHttpIP()).put(':').put(env.configuration.getHttpPort());
        welcome.put(". Already running?");
        System.err.println(welcome);
        System.out.println(new Date() + " QuestDB failed to start");
    } else {
        welcome.put("Listening on ").put(env.configuration.getHttpIP()).put(':').put(env.configuration.getHttpPort());
        if (env.configuration.getSslConfig().isSecure()) {
            welcome.put(" [HTTPS]");
        } else {
            welcome.put(" [HTTP plain]");
        }
        System.err.println(welcome);
        System.out.println(new Date() + " QuestDB is running");
        if (Os.type != Os.WINDOWS && optHash.get("-n") == null) {
            // suppress HUP signal
            Signal.handle(new Signal("HUP"), signal -> {
            });
        }
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println(new Date() + " QuestDB is shutting down");
            server.halt();
            factoryEventLogger.close();
            env.factory.close();
        }));
    }
}
Also used : CharSink(com.questdb.std.str.CharSink) DateFormatFactory(com.questdb.std.time.DateFormatFactory) Factory(com.questdb.store.factory.Factory) LogFactory(com.questdb.log.LogFactory) DateFormatFactory(com.questdb.std.time.DateFormatFactory) DateLocaleFactory(com.questdb.std.time.DateLocaleFactory) Date(java.util.Date) Signal(sun.misc.Signal) TypeProbeCollection(com.questdb.parser.typeprobe.TypeProbeCollection) HttpServer(com.questdb.net.http.HttpServer) SimpleUrlMatcher(com.questdb.net.http.SimpleUrlMatcher) Job(com.questdb.mp.Job) File(java.io.File)

Aggregations

Factory (com.questdb.store.factory.Factory)27 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)13 JournalConfiguration (com.questdb.store.factory.configuration.JournalConfiguration)11 Price (org.questdb.examples.support.Price)8 File (java.io.File)6 QueryCompiler (com.questdb.parser.sql.QueryCompiler)5 JournalWriter (com.questdb.store.JournalWriter)5 Quote (org.questdb.examples.support.Quote)5 LogFactory (com.questdb.log.LogFactory)4 JournalClient (com.questdb.net.ha.JournalClient)4 RecordSource (com.questdb.ql.RecordSource)4 Rnd (com.questdb.std.Rnd)4 JournalListener (com.questdb.store.JournalListener)4 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)4 AbstractTest (com.questdb.test.tools.AbstractTest)4 Test (org.junit.Test)4 JournalServer (com.questdb.net.ha.JournalServer)3 ClientConfig (com.questdb.net.ha.config.ClientConfig)3 JournalException (com.questdb.std.ex.JournalException)3 JournalEntryWriter (com.questdb.store.JournalEntryWriter)3