Search in sources :

Example 1 with DefaultListDelimiterHandler

use of org.apache.commons.configuration2.convert.DefaultListDelimiterHandler in project hadoop by apache.

the class GangliaSink30 method init.

@Override
@SuppressWarnings("unchecked")
public void init(SubsetConfiguration conf) {
    super.init(conf);
    conf.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    Iterator<String> it = (Iterator<String>) conf.getKeys();
    while (it.hasNext()) {
        String propertyName = it.next();
        if (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 = new HashSet<>();
            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);
        }
    }
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 2 with DefaultListDelimiterHandler

use of org.apache.commons.configuration2.convert.DefaultListDelimiterHandler in project hadoop by apache.

the class MetricsConfig method loadFirst.

/**
   * Load configuration from a list of files until the first successful load
   * @param conf  the configuration object
   * @param files the list of filenames to try
   * @return  the configuration object
   */
static MetricsConfig loadFirst(String prefix, String... fileNames) {
    for (String fname : fileNames) {
        try {
            Configuration cf = new Configurations().propertiesBuilder(fname).configure(new Parameters().properties().setFileName(fname).setListDelimiterHandler(new DefaultListDelimiterHandler(','))).getConfiguration().interpolatedConfiguration();
            LOG.info("loaded properties from " + fname);
            LOG.debug(toString(cf));
            MetricsConfig mc = new MetricsConfig(cf, prefix);
            LOG.debug(mc);
            return mc;
        } catch (ConfigurationException e) {
            // Commons Configuration defines the message text when file not found
            if (e.getMessage().startsWith("Could not locate")) {
                continue;
            }
            throw new MetricsConfigException(e);
        }
    }
    LOG.warn("Cannot locate configuration: tried " + Joiner.on(",").join(fileNames));
    // default to an empty configuration
    return new MetricsConfig(new PropertiesConfiguration(), prefix);
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) Configurations(org.apache.commons.configuration2.builder.fluent.Configurations) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Aggregations

DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Configuration (org.apache.commons.configuration2.Configuration)1 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)1 SubsetConfiguration (org.apache.commons.configuration2.SubsetConfiguration)1 Configurations (org.apache.commons.configuration2.builder.fluent.Configurations)1 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1