Example usage for org.apache.commons.configuration FileConfiguration setReloadingStrategy

List of usage examples for org.apache.commons.configuration FileConfiguration setReloadingStrategy

Introduction

In this page you can find the example usage for org.apache.commons.configuration FileConfiguration setReloadingStrategy.

Prototype

void setReloadingStrategy(ReloadingStrategy strategy);

Source Link

Document

Set the reloading strategy.

Usage

From source file:com.twitter.distributedlog.config.ConfigurationSubscription.java

private boolean initConfig() {
    if (fileConfigs.isEmpty()) {
        try {//from www. j  a v  a 2s  .c o  m
            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();
}

From source file:com.germinus.easyconf.AggregatedProperties.java

private Configuration addFileProperties(String fileName, CompositeConfiguration loadedConf)
        throws ConfigurationException {
    try {//from www .j  a v a  2  s.  co  m
        FileConfiguration newConf = new PropertiesConfiguration(fileName);
        URL fileURL = newConf.getURL();
        log.debug("Adding file: " + fileURL);

        Long delay = getReloadDelay(loadedConf, newConf);
        if (delay != null) {
            FileChangedReloadingStrategy reloadingStrategy = new FileConfigurationChangedReloadingStrategy();
            if (log.isDebugEnabled()) {
                log.debug("File " + fileURL + " will be reloaded every " + delay + " seconds");
            }
            long milliseconds = delay.longValue() * 1000;
            reloadingStrategy.setRefreshDelay(milliseconds);
            newConf.setReloadingStrategy(reloadingStrategy);
        }

        addIncludedPropertiesSources(newConf, loadedConf);
        return newConf;
    } catch (org.apache.commons.configuration.ConfigurationException e) {
        if (log.isDebugEnabled()) {
            log.debug("Configuration source " + fileName + " ignored");
        }
        return null;
    }
}

From source file:com.liferay.portal.configuration.easyconf.ClassLoaderAggregateProperties.java

private Configuration _addURLProperties(URL url, CompositeConfiguration loadedCompositeConfiguration)
        throws ConfigurationException {

    try {/*from   w w w  .j a  v a  2  s  .  com*/
        FileConfiguration newFileConfiguration = new PropertiesConfiguration(url);

        if (_log.isDebugEnabled()) {
            _log.debug("Adding resource " + url);
        }

        Long delay = _getReloadDelay(loadedCompositeConfiguration, newFileConfiguration);

        if (delay != null) {
            FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileConfigurationChangedReloadingStrategy();

            if (_log.isDebugEnabled()) {
                _log.debug("Resource " + url + " will be reloaded every " + delay + " seconds");
            }

            long milliseconds = delay.longValue() * 1000;

            fileChangedReloadingStrategy.setRefreshDelay(milliseconds);

            newFileConfiguration.setReloadingStrategy(fileChangedReloadingStrategy);
        }

        _addIncludedPropertiesSources(newFileConfiguration, loadedCompositeConfiguration);

        return newFileConfiguration;
    } catch (org.apache.commons.configuration.ConfigurationException ce) {
        if (_log.isDebugEnabled()) {
            _log.debug("Configuration source " + url + " ignored");
        }

        return null;
    }
}

From source file:com.liferay.portal.configuration.easyconf.ClassLoaderAggregateProperties.java

private Configuration _addFileProperties(String fileName, CompositeConfiguration loadedCompositeConfiguration)
        throws ConfigurationException {

    try {/*w  w w  .  j  ava 2  s  . com*/
        FileConfiguration newFileConfiguration = new PropertiesConfiguration(fileName);

        URL url = newFileConfiguration.getURL();

        if (_log.isDebugEnabled()) {
            _log.debug("Adding file " + url);
        }

        Long delay = _getReloadDelay(loadedCompositeConfiguration, newFileConfiguration);

        if (delay != null) {
            FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileConfigurationChangedReloadingStrategy();

            if (_log.isDebugEnabled()) {
                _log.debug("File " + url + " will be reloaded every " + delay + " seconds");
            }

            long milliseconds = delay.longValue() * 1000;

            fileChangedReloadingStrategy.setRefreshDelay(milliseconds);

            newFileConfiguration.setReloadingStrategy(fileChangedReloadingStrategy);
        }

        _addIncludedPropertiesSources(newFileConfiguration, loadedCompositeConfiguration);

        return newFileConfiguration;
    } catch (org.apache.commons.configuration.ConfigurationException ce) {
        if (_log.isDebugEnabled()) {
            _log.debug("Configuration source " + fileName + " ignored");
        }

        return null;
    }
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

@Test
public void testConcurrentGetAndReload() throws Exception {
    // final FileConfiguration config = new
    // PropertiesConfiguration("test.properties");
    final FileConfiguration config = new XMLConfiguration("test.xml");
    config.setReloadingStrategy(new FileAlwaysReloadingStrategy());

    assertTrue("Property not found", config.getProperty("test.short") != null);

    Thread testThreads[] = new Thread[THREAD_COUNT];

    for (int i = 0; i < testThreads.length; ++i) {
        testThreads[i] = new ReloadThread(config);
        testThreads[i].start();//w  w w . j a  v a2s . co m
    }

    for (int i = 0; i < LOOP_COUNT; i++) {
        assertTrue("Property not found", config.getProperty("test.short") != null);
    }

    for (int i = 0; i < testThreads.length; ++i) {
        testThreads[i].join();
    }
}