Search in sources :

Example 1 with FileChangedReloadingStrategy

use of org.apache.commons.configuration.reloading.FileChangedReloadingStrategy in project distributedlog by twitter.

the class ConfigurationSubscription method initConfig.

private boolean initConfig() {
    if (fileConfigs.isEmpty()) {
        try {
            for (FileConfigurationBuilder fileConfigBuilder : fileConfigBuilders) {
                FileConfiguration fileConfig = fileConfigBuilder.getConfiguration();
                FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
                reloadingStrategy.setRefreshDelay(0);
                fileConfig.setReloadingStrategy(reloadingStrategy);
                fileConfigs.add(fileConfig);
            }
        } catch (ConfigurationException ex) {
            if (!fileNotFound(ex)) {
                LOG.error("Config init failed {}", ex);
            }
        }
    }
    return !fileConfigs.isEmpty();
}
Also used : FileConfiguration(org.apache.commons.configuration.FileConfiguration) FileChangedReloadingStrategy(org.apache.commons.configuration.reloading.FileChangedReloadingStrategy) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 2 with FileChangedReloadingStrategy

use of org.apache.commons.configuration.reloading.FileChangedReloadingStrategy in project bookkeeper by apache.

the class ConfigurationSubscription method initConfig.

private boolean initConfig() {
    if (fileConfigs.isEmpty()) {
        try {
            for (FileConfigurationBuilder fileConfigBuilder : fileConfigBuilders) {
                FileConfiguration fileConfig = fileConfigBuilder.getConfiguration();
                FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
                reloadingStrategy.setRefreshDelay(0);
                fileConfig.setReloadingStrategy(reloadingStrategy);
                fileConfigs.add(fileConfig);
            }
        } catch (ConfigurationException ex) {
            if (!fileNotFound(ex)) {
                LOG.error("Config init failed {}", ex);
            }
        }
    }
    return !fileConfigs.isEmpty();
}
Also used : FileConfiguration(org.apache.commons.configuration.FileConfiguration) FileChangedReloadingStrategy(org.apache.commons.configuration.reloading.FileChangedReloadingStrategy) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 3 with FileChangedReloadingStrategy

use of org.apache.commons.configuration.reloading.FileChangedReloadingStrategy in project accumulo by apache.

the class MetricsConfiguration method loadConfiguration.

private void loadConfiguration() {
    URL metricsUrl = MetricsConfiguration.class.getClassLoader().getResource("accumulo-metrics.xml");
    if (metricsUrl == null) {
        if (!alreadyWarned)
            log.warn("accumulo-metrics.xml was not found on classpath. Metrics collection will be disabled.");
        alreadyWarned = true;
        notFound = true;
        return;
    }
    try {
        xConfig = new XMLConfiguration(metricsUrl);
        xConfig.append(getEnvironmentConfiguration());
        xConfig.addConfigurationListener(new MetricsConfigListener());
        xConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
        // every so often to force the FileChangedReloadingStrategy to fire.
        if (null == watcher || !watcher.isAlive()) {
            watcher = new MetricsConfigWatcher();
            watcher.start();
        }
        notFound = false;
        alreadyWarned = false;
    } catch (ConfigurationException ce) {
        log.error("Error reading accumulo-metrics.xml file.");
        notFound = true;
        return;
    }
    if (xConfig != null) {
        config = xConfig.interpolatedConfiguration();
        // set the enabled boolean from the configuration
        enabled = config.getBoolean(enabledName);
        if (log.isDebugEnabled())
            log.debug("Metrics collection enabled={}", enabled);
    } else {
        enabled = false;
    }
}
Also used : FileChangedReloadingStrategy(org.apache.commons.configuration.reloading.FileChangedReloadingStrategy) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) URL(java.net.URL)

Example 4 with FileChangedReloadingStrategy

use of org.apache.commons.configuration.reloading.FileChangedReloadingStrategy in project ninja by ninjaframework.

the class MessagesImpl method loadLanguageConfiguration.

/**
 * Attempts to load a message file and sets the file changed reloading
 * strategy on the configuration if the runtime mode is Dev.
 */
private PropertiesConfiguration loadLanguageConfiguration(String fileOrUrl) {
    PropertiesConfiguration configuration = SwissKnife.loadConfigurationInUtf8(fileOrUrl);
    if (configuration != null && ninjaProperties.isDev()) {
        // enable runtime reloading of translations in dev mode
        FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
        configuration.setReloadingStrategy(strategy);
    }
    return configuration;
}
Also used : FileChangedReloadingStrategy(org.apache.commons.configuration.reloading.FileChangedReloadingStrategy) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Aggregations

FileChangedReloadingStrategy (org.apache.commons.configuration.reloading.FileChangedReloadingStrategy)4 ConfigurationException (org.apache.commons.configuration.ConfigurationException)3 FileConfiguration (org.apache.commons.configuration.FileConfiguration)2 URL (java.net.URL)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)1