Example usage for org.apache.commons.configuration SubsetConfiguration getStringArray

List of usage examples for org.apache.commons.configuration SubsetConfiguration getStringArray

Introduction

In this page you can find the example usage for org.apache.commons.configuration SubsetConfiguration getStringArray.

Prototype

public String[] getStringArray(String key) 

Source Link

Document

Get an array of strings associated with the given configuration key.

Usage

From source file:com.zavakid.mushroom.filter.AbstractPatternFilter.java

@Override
public void init(SubsetConfiguration conf) {
    String patternString = conf.getString(INCLUDE_KEY);
    if (patternString != null && !patternString.isEmpty()) {
        LOG.debug("got include pattern: " + patternString);
        setIncludePattern(compile(patternString));
    }/*from  w w w. j ava  2 s.com*/
    patternString = conf.getString(EXCLUDE_KEY);
    if (patternString != null && !patternString.isEmpty()) {
        LOG.debug("got include pattern: " + patternString);
        setExcludePattern(compile(patternString));
    }
    String[] patternStrings = conf.getStringArray(INCLUDE_TAGS_KEY);
    if (patternStrings != null && patternStrings.length != 0) {
        LOG.debug("got include tags pattern: " + patternStrings);
        for (String pstr : patternStrings) {
            Matcher matcher = tagPattern.matcher(pstr);
            if (!matcher.matches()) {
                throw new MetricsException("Illegal tag pattern: " + pstr);
            }
            setIncludeTagPattern(matcher.group(1), compile(matcher.group(2)));
        }
    }
    patternStrings = conf.getStringArray(EXCLUDE_TAGS_KEY);
    if (patternStrings != null && patternStrings.length != 0) {
        LOG.debug("got exclude tags pattern: " + patternStrings);
        for (String pstr : patternStrings) {
            Matcher matcher = tagPattern.matcher(pstr);
            if (!matcher.matches()) {
                throw new MetricsException("Illegal tag pattern: " + pstr);
            }
            setExcludeTagPattern(matcher.group(1), compile(matcher.group(2)));
        }
    }
}

From source file:org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink.java

@Override
public void init(SubsetConfiguration conf) {
    LOG.info("Initializing Timeline metrics sink.");

    // Take the hostname from the DNS class.
    if (conf.getString("slave.host.name") != null) {
        hostName = conf.getString("slave.host.name");
    } else {/*from  w w  w.  ja  v a  2 s . c om*/
        try {
            hostName = DNS.getDefaultHost(conf.getString("dfs.datanode.dns.interface", "default"),
                    conf.getString("dfs.datanode.dns.nameserver", "default"));
        } catch (UnknownHostException uhe) {
            LOG.error(uhe);
            hostName = "UNKNOWN.example.com";
        }
    }

    serviceName = getServiceName(conf);

    LOG.info("Identified hostname = " + hostName + ", serviceName = " + serviceName);

    // Load collector configs
    metricsServers = Servers.parse(conf.getString(COLLECTOR_HOST_PROPERTY), 6188);

    if (metricsServers == null || metricsServers.isEmpty()) {
        LOG.error("No Metric collector configured.");
    } else {
        collectorUri = "http://" + conf.getString(COLLECTOR_HOST_PROPERTY).trim() + "/ws/v1/timeline/metrics";
    }

    LOG.info("Collector Uri: " + collectorUri);

    int maxRowCacheSize = conf.getInt(MAX_METRIC_ROW_CACHE_SIZE,
            TimelineMetricsCache.MAX_RECS_PER_NAME_DEFAULT);
    int metricsSendInterval = conf.getInt(METRICS_SEND_INTERVAL, TimelineMetricsCache.MAX_EVICTION_TIME_MILLIS); // ~ 1 min
    metricsCache = new TimelineMetricsCache(maxRowCacheSize, metricsSendInterval);

    conf.setListDelimiter(',');
    Iterator<String> it = (Iterator<String>) conf.getKeys();
    while (it.hasNext()) {
        String propertyName = it.next();
        if (propertyName != null && propertyName.startsWith(TAGS_FOR_PREFIX_PROPERTY_PREFIX)) {
            String contextName = propertyName.substring(TAGS_FOR_PREFIX_PROPERTY_PREFIX.length());
            String[] tags = conf.getStringArray(propertyName);
            boolean useAllTags = false;
            Set<String> set = null;
            if (tags.length > 0) {
                set = new HashSet<String>();
                for (String tag : tags) {
                    tag = tag.trim();
                    useAllTags |= tag.equals("*");
                    if (tag.length() > 0) {
                        set.add(tag);
                    }
                }
                if (useAllTags) {
                    set = null;
                }
            }
            useTagsMap.put(contextName, set);
        }
    }
}

From source file:org.apache.hadoop.metrics2.sink.timeline.TimelineMetricsSink.java

@Override
public void init(SubsetConfiguration conf) {
    super.init(conf);

    int maxRowCacheSize = conf.getInt(MAX_METRIC_ROW_CACHE_SIZE,
            TimelineMetricsCache.MAX_RECS_PER_NAME_DEFAULT);
    int metricsSendInterval = conf.getInt(METRICS_SEND_INTERVAL, TimelineMetricsCache.MAX_EVICTION_TIME_MILLIS); // ~ 1 min
    metricsCache = new TimelineMetricsCache(maxRowCacheSize, metricsSendInterval);

    conf.setListDelimiter(',');
    Iterator<String> it = (Iterator<String>) conf.getKeys();
    while (it.hasNext()) {
        String propertyName = it.next();
        if (propertyName != null && propertyName.startsWith(TAGS_FOR_PREFIX_PROPERTY_PREFIX)) {
            String contextName = propertyName.substring(TAGS_FOR_PREFIX_PROPERTY_PREFIX.length());
            String[] tags = conf.getStringArray(propertyName);
            boolean useAllTags = false;
            Set<String> set = null;
            if (tags.length > 0) {
                set = new HashSet<String>();
                for (String tag : tags) {
                    tag = tag.trim();/*from  w  ww  .  ja va2s .  co m*/
                    useAllTags |= tag.equals("*");
                    if (tag.length() > 0) {
                        set.add(tag);
                    }
                }
                if (useAllTags) {
                    set = null;
                }
            }
            useTagsMap.put(contextName, set);
        }
    }
}