Search in sources :

Example 1 with DateFormatFactory

use of com.questdb.std.time.DateFormatFactory 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)

Example 2 with DateFormatFactory

use of com.questdb.std.time.DateFormatFactory in project questdb by bluestreak01.

the class TypeProbeCollectionTest method testTypeProbeCollectionInstantiation.

@Test
public void testTypeProbeCollectionInstantiation() throws Exception {
    String path = this.getClass().getResource("/date_test.formats").getFile();
    if (Os.type == Os.WINDOWS && path.startsWith("/")) {
        path = path.substring(1);
    }
    TypeProbeCollection typeProbeCollection = new TypeProbeCollection(path, new DateFormatFactory(), DateLocaleFactory.INSTANCE);
    Assert.assertEquals(7, typeProbeCollection.getProbeCount());
    Assert.assertTrue(typeProbeCollection.getProbe(0) instanceof IntProbe);
    Assert.assertTrue(typeProbeCollection.getProbe(1) instanceof LongProbe);
    Assert.assertTrue(typeProbeCollection.getProbe(2) instanceof DoubleProbe);
    Assert.assertTrue(typeProbeCollection.getProbe(3) instanceof BooleanProbe);
    Assert.assertTrue(typeProbeCollection.getProbe(4) instanceof DateProbe);
    Assert.assertTrue(typeProbeCollection.getProbe(5) instanceof DateProbe);
    Assert.assertTrue(typeProbeCollection.getProbe(6) instanceof DateProbe);
    DateLocale defaultLocale = DateLocaleFactory.INSTANCE.getDefaultDateLocale();
    Assert.assertEquals("dd/MM/y", typeProbeCollection.getProbe(4).getFormat());
    Assert.assertEquals(defaultLocale.getId(), typeProbeCollection.getProbe(4).getDateLocale().getId());
    Assert.assertEquals("yyyy-MM-dd HH:mm:ss", typeProbeCollection.getProbe(5).getFormat());
    Assert.assertEquals("es-PA", typeProbeCollection.getProbe(5).getDateLocale().getId());
    Assert.assertEquals("MM/dd/y", typeProbeCollection.getProbe(6).getFormat());
    Assert.assertEquals(defaultLocale.getId(), typeProbeCollection.getProbe(6).getDateLocale().getId());
}
Also used : DateLocale(com.questdb.std.time.DateLocale) DateFormatFactory(com.questdb.std.time.DateFormatFactory) Test(org.junit.Test)

Example 3 with DateFormatFactory

use of com.questdb.std.time.DateFormatFactory in project questdb by bluestreak01.

the class JsonSchemaParserTest method setUpClass.

@BeforeClass
public static void setUpClass() {
    BootstrapEnv env = new BootstrapEnv();
    env.dateFormatFactory = new DateFormatFactory();
    env.dateLocaleFactory = new DateLocaleFactory(new TimeZoneRuleFactory());
    defaultLocaleId = env.dateLocaleFactory.getDefaultDateLocale().getId();
    jsonSchemaParser = new JsonSchemaParser(env);
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) DateFormatFactory(com.questdb.std.time.DateFormatFactory) DateLocaleFactory(com.questdb.std.time.DateLocaleFactory) TimeZoneRuleFactory(com.questdb.std.time.TimeZoneRuleFactory)

Example 4 with DateFormatFactory

use of com.questdb.std.time.DateFormatFactory in project questdb by bluestreak01.

the class ImportManager method analyzeAndParse.

private static void analyzeAndParse(File file, PlainTextLexer parser, MetadataAwareTextParser listener, CharSequence schema, int sampleSize, boolean forceHeader) throws IOException {
    parser.clear();
    ObjList<ImportedColumnMetadata> metadata = null;
    if (schema != null) {
        BootstrapEnv env = new BootstrapEnv();
        env.dateLocaleFactory = new DateLocaleFactory(new TimeZoneRuleFactory());
        env.dateFormatFactory = new DateFormatFactory();
        JsonSchemaParser jsonSchemaParser = new JsonSchemaParser(env);
        int len = schema.length();
        long addr = Unsafe.malloc(len);
        try {
            Chars.strcpy(schema, len, addr);
            try (JsonLexer lexer = new JsonLexer(1024, 4096)) {
                lexer.parse(addr, len, jsonSchemaParser);
                lexer.parseLast();
            }
            metadata = jsonSchemaParser.getMetadata();
        } catch (JsonException e) {
            throw new IOException(e);
        } finally {
            Unsafe.free(addr, len);
        }
    }
    try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
        try (FileChannel channel = raf.getChannel()) {
            long size = channel.size();
            long bufSize = ByteBuffers.getMaxMappedBufferSize(size);
            long p = 0;
            while (p < size) {
                MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, p, size - p < bufSize ? size - p : bufSize);
                try {
                    if (p == 0) {
                        parser.analyseStructure(ByteBuffers.getAddress(buf), buf.remaining(), sampleSize, listener, forceHeader, metadata);
                    }
                    p += buf.remaining();
                    parser.parse(ByteBuffers.getAddress(buf), buf.remaining(), Integer.MAX_VALUE, listener);
                } finally {
                    ByteBuffers.release(buf);
                }
            }
            parser.parseLast();
        }
    }
}
Also used : JsonException(com.questdb.parser.json.JsonException) BootstrapEnv(com.questdb.BootstrapEnv) ImportedColumnMetadata(com.questdb.parser.ImportedColumnMetadata) FileChannel(java.nio.channels.FileChannel) DateFormatFactory(com.questdb.std.time.DateFormatFactory) IOException(java.io.IOException) TimeZoneRuleFactory(com.questdb.std.time.TimeZoneRuleFactory) JsonLexer(com.questdb.parser.json.JsonLexer) RandomAccessFile(java.io.RandomAccessFile) MappedByteBuffer(java.nio.MappedByteBuffer) JsonSchemaParser(com.questdb.parser.JsonSchemaParser) DateLocaleFactory(com.questdb.std.time.DateLocaleFactory)

Aggregations

DateFormatFactory (com.questdb.std.time.DateFormatFactory)4 DateLocaleFactory (com.questdb.std.time.DateLocaleFactory)3 BootstrapEnv (com.questdb.BootstrapEnv)2 TimeZoneRuleFactory (com.questdb.std.time.TimeZoneRuleFactory)2 LogFactory (com.questdb.log.LogFactory)1 Job (com.questdb.mp.Job)1 HttpServer (com.questdb.net.http.HttpServer)1 SimpleUrlMatcher (com.questdb.net.http.SimpleUrlMatcher)1 ImportedColumnMetadata (com.questdb.parser.ImportedColumnMetadata)1 JsonSchemaParser (com.questdb.parser.JsonSchemaParser)1 JsonException (com.questdb.parser.json.JsonException)1 JsonLexer (com.questdb.parser.json.JsonLexer)1 TypeProbeCollection (com.questdb.parser.typeprobe.TypeProbeCollection)1 CharSink (com.questdb.std.str.CharSink)1 DateLocale (com.questdb.std.time.DateLocale)1 Factory (com.questdb.store.factory.Factory)1 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 MappedByteBuffer (java.nio.MappedByteBuffer)1