Example usage for org.apache.commons.configuration.reloading FileChangedReloadingStrategy setRefreshDelay

List of usage examples for org.apache.commons.configuration.reloading FileChangedReloadingStrategy setRefreshDelay

Introduction

In this page you can find the example usage for org.apache.commons.configuration.reloading FileChangedReloadingStrategy setRefreshDelay.

Prototype

public void setRefreshDelay(long refreshDelay) 

Source Link

Document

Set the minimal time between two reloadings.

Usage

From source file:com.pse.fotoz.helpers.Configuration.ConfigurationManager.java

public static void initConfig() {
    try {/*ww w.jav a  2 s  . com*/
        config = new XMLConfiguration("application.cfg.xml");
        configPasswords = new XMLConfiguration("passwords.cfg.xml");
    } catch (ConfigurationException ex) {
        Logger.getLogger(ConfigurationManager.class.getName()).log(Level.SEVERE, null, ex);
    }
    FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
    strategy.setRefreshDelay(reloadDelayMS);
    config.setReloadingStrategy(strategy);
    config.setValidating(true); //valideer de xml
}

From source file:com.dc.gameserver.baseConfig.Config.java

/**
 * ??//from   w w w.  ja va 2s .c  o  m
 * @throws org.apache.commons.configuration.ConfigurationException
 */
public static void IntiConfig() throws ConfigurationException {
    PropertiesConfiguration server_config = new PropertiesConfiguration(DEFAULT_VALUE.FILE_PATH.SERVER);
    PropertiesConfiguration game_config = new PropertiesConfiguration(DEFAULT_VALUE.FILE_PATH.GAME);
    FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); //default 5000
    if (server_config.getBoolean("autoReload")) {
        strategy.setRefreshDelay(server_config.getInt("refreshDelay", 5000));
        server_config.setReloadingStrategy(strategy);
        game_config.setReloadingStrategy(strategy);
    }
    /*********************************************************************************/
    //   ??
    /*********************************************************************************/
    DEFAULT_VALUE.SERVER_VALUE.gameserverPort = server_config.getInt("gameserverPort", 8888);

    DEFAULT_VALUE.SERVER_VALUE.readTimeOut = server_config.getInt("readTimeOut");
    DEFAULT_VALUE.SERVER_VALUE.writeTimeOut = server_config.getInt("writeTimeOut");
    DEFAULT_VALUE.SERVER_VALUE.connect_timeout = server_config.getInt("connect_timeout");
    DEFAULT_VALUE.SERVER_VALUE.maxConnection = server_config.getInt("maxConnection");
    DEFAULT_VALUE.SERVER_VALUE.checkInterval = server_config.getInt("checkInterval");

    //????
    DEFAULT_VALUE.SERVER_VALUE.maxFrameLength = server_config.getInt("maxFrameLength", 1048576);
    DEFAULT_VALUE.SERVER_VALUE.lengthFieldOffset = server_config.getInt("lengthFieldOffset", 0);
    DEFAULT_VALUE.SERVER_VALUE.lengthFieldLength = server_config.getInt("lengthFieldLength", 2);
    DEFAULT_VALUE.SERVER_VALUE.lengthAdjustment = server_config.getInt("lengthAdjustment", 0);
    DEFAULT_VALUE.SERVER_VALUE.initialBytesToStrip = server_config.getInt("initialBytesToStrip", 2);

    DEFAULT_VALUE.SERVER_VALUE.useMultleThread = server_config.getBoolean("useMultleThread", false);

    //??
    DEFAULT_VALUE.SERVER_VALUE.RoundIntervalTimerNum = server_config.getInt("RoundIntervalTimerNum");
    DEFAULT_VALUE.SERVER_VALUE.RoundTimeOutTimerNum = server_config.getInt("RoundTimeOutTimerNum");
    DEFAULT_VALUE.SERVER_VALUE.buffTimerNum = server_config.getInt("buffTimerNum");
    DEFAULT_VALUE.SERVER_VALUE.calculateThreads = server_config.getInt("calculateThreads");
    DEFAULT_VALUE.SERVER_VALUE.purgeTaskNum = server_config.getInt("purgeTaskNum");
    DEFAULT_VALUE.SERVER_VALUE.AIthreadNum = server_config.getInt("AIthreadNum");

    /*********************************************************************************/
    /*   ???
    /*********************************************************************************/
    DEFAULT_VALUE.GAME_VALUE.rulePoint = game_config.getBoolean("rulePoint", false);
    DEFAULT_VALUE.GAME_VALUE.DizzinessTimes = game_config.getInt("DizzinessTimes");
    DEFAULT_VALUE.GAME_VALUE.roundOutCardIntervalTimeOut = game_config.getLong("roundOutCardIntervalTimeOut",
            30000);
    DEFAULT_VALUE.GAME_VALUE.roundInterval = game_config.getLong("roundInterval");

    /**   ->  ->  ->    1,2,3,4 */
    DEFAULT_VALUE.GAME_VALUE.soualProbability = game_config.getFloat("soualProbability");
    DEFAULT_VALUE.GAME_VALUE.defenceProbability = game_config.getFloat("defenceProbability");
    DEFAULT_VALUE.GAME_VALUE.attackProbability = game_config.getFloat("attackProbability");
    DEFAULT_VALUE.GAME_VALUE.magicProbability = game_config.getFloat("magicProbability");

    DEFAULT_VALUE.GAME_VALUE.cardBoxNum = game_config.getInt("cardBoxNum");
    DEFAULT_VALUE.GAME_VALUE.cardNum = game_config.getInt("cardNum");
    DEFAULT_VALUE.GAME_VALUE.PrograssPageSize = game_config.getInt("PrograssPageSize", 5);
    DEFAULT_VALUE.GAME_VALUE.MAX_ROUND = game_config.getInt("MAX_ROUND", 10);

    DEFAULT_VALUE.GAME_VALUE.useItemLog = game_config.getBoolean("useItemLog", true);
    DEFAULT_VALUE.GAME_VALUE.defenceRecoverySheild = game_config.getInt("defenceRecoverySheild");
    DEFAULT_VALUE.GAME_VALUE.hurt = game_config.getInt("hurt");
    DEFAULT_VALUE.GAME_VALUE.equipAndBooksAttrRandomRange = game_config
            .getDouble("equipAndBooksAttrRandomRange");

    DEFAULT_VALUE.GAME_VALUE.PinJieModulus = game_config.getDouble("PinJieModulus");
    DEFAULT_VALUE.GAME_VALUE.PinZhiModulus = game_config.getDouble("PinZhiModulus");

    DEFAULT_VALUE.GAME_VALUE.minDizziness = game_config.getInt("minDizziness");
    DEFAULT_VALUE.GAME_VALUE.maxDizziness = game_config.getInt("maxDizziness");
    DEFAULT_VALUE.GAME_VALUE.minHurtSoul = game_config.getInt("minHurtSoul");
    DEFAULT_VALUE.GAME_VALUE.maxHurtSoul = game_config.getInt("maxHurtSoul");
    DEFAULT_VALUE.GAME_VALUE.minSpike = game_config.getInt("minSpike");
    DEFAULT_VALUE.GAME_VALUE.maxSpike = game_config.getInt("maxSpike");

    //?
    //??
    //?
    //?
    //???
    //??
    //?
    DEFAULT_VALUE.GAME_VALUE.dizinnessCardNum = game_config.getInt("dizinnessCardNum");
    DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjuryCardNum = game_config.getInt("InotherInjuryToInjuryCardNum");
    DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjurySoulValue = game_config
            .getInt("InotherInjuryToInjurySoulValue");
    DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjuryHurtPercent = game_config
            .getDouble("InotherInjuryToInjuryHurtPercent");
    DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjuryReservedHurtPercent = game_config
            .getDouble("InotherInjuryToInjuryReservedHurtPercent");
    DEFAULT_VALUE.GAME_VALUE.SpikeCardNum = game_config.getInt("SpikeCardNum");
    DEFAULT_VALUE.GAME_VALUE.SpikeValue = game_config.getInt("SpikeValue");
    DEFAULT_VALUE.GAME_VALUE.soulRecoveryInitial = game_config.getLong("soulRecoveryInitial");
    DEFAULT_VALUE.GAME_VALUE.GongPercent = game_config.getDouble("GongPercent", 0.02);

    //?
    DEFAULT_VALUE.GAME_VALUE.spriteFullInitial = game_config.getLong("spriteFullInitial");
    DEFAULT_VALUE.GAME_VALUE.getSpriteInitial = game_config.getLong("getSpriteInitial");

    DEFAULT_VALUE.GAME_VALUE.ItemCellNum = game_config.getInt("ItemCellNum");
}

From source file:it.grid.storm.config.ConfigReader.java

public ConfigReader(String configurationPathname, int refresh) {

    if (configurationPathname != null) {
        if (refresh < 0)
            refresh = 0;/*from www .  j  a v  a 2 s.  c om*/
        this.refresh = refresh;
        this.configurationPathname = configurationPathname;
        log.info("Configuration file {}. Refresh rate: {} seconds", configurationPathname, refresh);

        try {
            FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
            strategy.setRefreshDelay(refresh);
            PropertiesConfiguration properties = new PropertiesConfiguration(configurationPathname);
            log.debug("Configuration properties:");
            String key;
            for (Iterator<?> i = properties.getKeys(); i.hasNext();) {
                key = (String) i.next();
                log.debug("{} = {}", key, properties.getProperty(key).toString());
            }
            properties.setReloadingStrategy(strategy);
            this.c = new CompositeConfiguration();
            ((CompositeConfiguration) this.c).addConfiguration(properties);
            log.info("Configuration read successfully.");
        } catch (ConfigurationException e) {
            this.c = makeEmptyConfiguration();
            log.error("Configuration parsing error: {}", e.getMessage(), e);
        }
    } else {
        throw new NullPointerException("Null configuration pathname.");
    }
}

From source file:com.bitcup.configurator.FileConfig.java

private FileChangedReloadingStrategy getReloadingStrategy() {
    final FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
    reloadingStrategy.setRefreshDelay(TimeUnit.SECONDS.toMillis(this.refreshDelaySecs));
    return reloadingStrategy;
}

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

private boolean initConfig() {
    if (fileConfigs.isEmpty()) {
        try {/*w  w  w  .j  av a  2s  .co  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.github.technosf.posterer.transports.commons.CommonsConfiguratorPropertiesImpl.java

/**
 * @param prefix//ww w.j  a  va  2 s  .  com
 * @throws IOException
 * @throws ConfigurationException
 */
@Inject
public CommonsConfiguratorPropertiesImpl(@Named("PropertiesPrefix") final String prefix)
        throws IOException, ConfigurationException {
    super(prefix);

    if (!propsFile.exists() || FileUtils.sizeOf(propsFile) < blankfile.length())
    // Touch the properties file
    {
        FileUtils.writeStringToFile(propsFile, blankfile);
    }

    FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
    strategy.setRefreshDelay(5000);

    config = new XMLConfiguration(propsFile);
    config.setExpressionEngine(new XPathExpressionEngine());
    config.setReloadingStrategy(strategy);

    initializeRequestSet();
}

From source file:com.jkoolcloud.tnt4j.repository.FileTokenRepository.java

@Override
public void open() throws IOException {
    if (isOpen() || (configName == null))
        return;/*from  ww w .j  a va 2  s. co m*/
    try {
        initConfig();
        if (refDelay > 0) {
            FileChangedReloadingStrategy reloadConfig = new FileChangedReloadingStrategy();
            reloadConfig.setRefreshDelay(refDelay);
            config.setReloadingStrategy(reloadConfig);
        }
    } catch (Throwable e) {
        IOException ioe = new IOException(e.toString());
        ioe.initCause(e);
        throw ioe;
    }
}

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

private Configuration addFileProperties(String fileName, CompositeConfiguration loadedConf)
        throws ConfigurationException {
    try {/*from  ww  w. j av a  2s.  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.mirth.connect.manager.ManagerController.java

private PropertiesConfiguration initializeProperties(String path, boolean alert) {
    PropertiesConfiguration properties = new PropertiesConfiguration();

    // Auto reload changes
    FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
    fileChangedReloadingStrategy.setRefreshDelay(1000);
    properties.setReloadingStrategy(fileChangedReloadingStrategy);
    properties.setFile(new File(path));

    if (properties.isEmpty() && alert) {
        alertErrorDialog("Could not load properties from file: " + path);
    }//from  ww  w .j ava 2 s  .  co  m

    return properties;
}

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

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

    try {//from   w w w  .j  a v  a2  s  .  c  o  m
        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;
    }
}