Search in sources :

Example 1 with CharSink

use of com.questdb.std.str.CharSink in project questdb by bluestreak01.

the class StaticContentHandler method sendRange.

private void sendRange(IOContext context, CharSequence range, LPSZ path, CharSequence contentType, boolean asAttachment) throws IOException {
    RangeParser rangeParser = tlRangeParser.get();
    if (rangeParser.of(range)) {
        FileDescriptorHolder h = lvFd.get(context);
        if (h == null) {
            lvFd.set(context, h = new FileDescriptorHolder());
        }
        h.fd = Files.openRO(path);
        if (h.fd == -1) {
            LOG.info().$("Cannot open file: ").$(path).$();
            context.simpleResponse().send(404);
            return;
        }
        h.bytesSent = 0;
        final long length = Files.length(path);
        final long lo = rangeParser.getLo();
        final long hi = rangeParser.getHi();
        if (lo > length || (hi != Long.MAX_VALUE && hi > length) || lo > hi) {
            context.simpleResponse().send(416);
        } else {
            h.bytesSent = lo;
            h.sendMax = hi == Long.MAX_VALUE ? length : hi;
            final FixedSizeResponse r = context.fixedSizeResponse();
            r.status(206, contentType, h.sendMax - lo);
            final CharSink sink = r.headers();
            if (asAttachment) {
                sink.put("Content-Disposition: attachment; filename=\"").put(FileNameExtractorCharSequence.get(path)).put('\"').put(Misc.EOL);
            }
            sink.put("Accept-Ranges: bytes").put(Misc.EOL);
            sink.put("Content-Range: bytes ").put(lo).put('-').put(h.sendMax).put('/').put(length).put(Misc.EOL);
            sink.put("ETag: ").put(Files.getLastModified(path)).put(Misc.EOL);
            r.sendHeader();
            resume(context);
        }
    } else {
        context.simpleResponse().send(416);
    }
}
Also used : CharSink(com.questdb.std.str.CharSink)

Example 2 with CharSink

use of com.questdb.std.str.CharSink 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 3 with CharSink

use of com.questdb.std.str.CharSink in project questdb by bluestreak01.

the class Chars method toUtf8String.

public static String toUtf8String(long lo, long hi) {
    if (hi == lo) {
        return "";
    }
    CharSink b = Misc.getThreadLocalBuilder();
    utf8Decode(lo, hi, b);
    return b.toString();
}
Also used : CharSink(com.questdb.std.str.CharSink)

Example 4 with CharSink

use of com.questdb.std.str.CharSink in project questdb by bluestreak01.

the class DirectLongList method toString.

@Override
public String toString() {
    CharSink sb = Misc.getThreadLocalBuilder();
    sb.put('{');
    for (int i = 0; i < size(); i++) {
        if (i > 0) {
            sb.put(',').put(' ');
        }
        sb.put(get(i));
    }
    sb.put('}');
    return sb.toString();
}
Also used : CharSink(com.questdb.std.str.CharSink)

Example 5 with CharSink

use of com.questdb.std.str.CharSink in project questdb by bluestreak01.

the class IntList method toString.

/**
 * {@inheritDoc}
 */
@Override
public String toString() {
    CharSink b = Misc.getThreadLocalBuilder();
    b.put('[');
    for (int i = 0, k = size(); i < k; i++) {
        if (i > 0) {
            b.put(',');
        }
        b.put(get(i));
    }
    b.put(']');
    return b.toString();
}
Also used : CharSink(com.questdb.std.str.CharSink)

Aggregations

CharSink (com.questdb.std.str.CharSink)9 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 TypeProbeCollection (com.questdb.parser.typeprobe.TypeProbeCollection)1 DateFormatFactory (com.questdb.std.time.DateFormatFactory)1 DateLocaleFactory (com.questdb.std.time.DateLocaleFactory)1 Factory (com.questdb.store.factory.Factory)1 File (java.io.File)1 Date (java.util.Date)1 Signal (sun.misc.Signal)1