public void activate()

in appender/influxdb/src/main/java/org/apache/karaf/decanter/appender/influxdb/InfluxDbAppender.java [57:108]


    public void activate(Dictionary<String, Object> config) {
        this.config = config;
        if (config.get("url") == null) {
            throw new IllegalArgumentException("url property is mandatory");
        }
        String url = (String) config.get("url");
        String username = null;
        if (config.get("username") != null) {
            username = (String) config.get("username");
        }
        String password = null;
        if (config.get("password") != null) {
            password = (String) config.get("password");
        }
        if (username != null) {
            this.influxDB = InfluxDBFactory.connect(url, username, password);
        } else {
            this.influxDB = InfluxDBFactory.connect(url);
        }
        String database = "decanter";
        if (config.get("database") != null) {
            database = (String) config.get("database");
        }

        BatchOptions batchOptions = BatchOptions.DEFAULTS;
        if (config.get("batchActionsLimit") != null) {
            int batchActionsLimit = Integer.parseInt((String) config.get("batchActionsLimit"));
            batchOptions = batchOptions.actions(batchActionsLimit);
        }
        if (config.get("precision") != null) {
            TimeUnit timeUnit = TimeUnit.valueOf((String) config.get("precision"));
            batchOptions = batchOptions.precision(timeUnit);
        }

        if (config.get("flushDuration") != null) {
            int flushDuration = Integer.parseInt((String) config.get("flushDuration"));
            batchOptions = batchOptions.flushDuration(flushDuration);
        }

        String prefix = "tag.";
        for (Enumeration<String> e = config.keys(); e.hasMoreElements(); ) {
            String key = e.nextElement();
            if( key.startsWith(prefix)) {
                Object value = this.config.get(key);
                if (value != null)
                    globalTags.put(key.substring(4),value.toString());
            }
        }

        this.influxDB.enableBatch(batchOptions);
        this.influxDB.setDatabase(database);
    }