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.liferay.portal.configuration.easyconf.ClassLoaderAggregateProperties.java

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

    try {//from   ww w .  ja  v  a2 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.mirth.connect.server.controllers.DefaultExtensionController.java

private void initialize() {
    try {/* ww w  . j a v a2s.c  o  m*/
        extensionProperties = new PropertiesConfiguration(
                new File(configurationController.getApplicationDataDir(), "extension.properties"));
        extensionProperties.setDelimiterParsingDisabled(true);

        // Auto reload changes
        FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
        fileChangedReloadingStrategy.setRefreshDelay(1000);
        extensionProperties.setReloadingStrategy(fileChangedReloadingStrategy);
    } catch (ConfigurationException e) {
        logger.error("There was an error loading extension.properties", e);
    }
}

From source file:com.nridge.core.app.mgr.AppMgr.java

/**
 * Loads the default property files ("application.properties" and
 * "logback.xml") from the file system and assigns default application
 * properties.//from   www  .ja v  a  2 s . co m
 * <p>
 * <b>Note:</b>&nbsp;This method will establish a default 5 minute reloading
 * policy for the "application.properties" file.  Therefore, any
 * changes to this property file while the application is running
 * will be recognized within a 5 minute period.
 * </p>
 *
 * @throws NSException Typically thrown for I/O related issues.
 */
public void loadPropertyFiles() throws NSException {
    String logFileName;

    try {

        // First, we will read our application properties.

        mConfiguration = new CompositeConfiguration();
        mConfiguration.setDelimiterParsingDisabled(true);
        mConfiguration.addConfiguration(new SystemConfiguration());
        mConfiguration.addConfiguration(new EnvironmentConfiguration());
        PropertiesConfiguration propertyCfg = new PropertiesConfiguration(deriveCfgPathFileName());
        FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
        reloadingStrategy.setRefreshDelay(DateUtils.MILLIS_PER_MINUTE * 2L);
        propertyCfg.setReloadingStrategy(reloadingStrategy);
        mConfiguration.addConfiguration(propertyCfg);

        // Next, we will load our Logback properties file and configure our application logger.

        if (mCmdLine == null)
            logFileName = LOG_PROPERTY_FILE_NAME;
        else
            logFileName = mCmdLine.getOptionValue("logfile", LOG_PROPERTY_FILE_NAME);
        File logFile = new File(logFileName);
        if (!logFile.exists()) {
            String logPathFileName = String.format("%s%c%s", deriveCfgPathName(), File.separatorChar,
                    logFileName);
            logFile = new File(logPathFileName);
            if (logFile.exists())
                logFileName = logPathFileName;
            else
                throw new NSException("Unable to locate logging properties file: " + logFileName);
        }

        if (StringUtils.isEmpty(getString(APP_PROPERTY_INS_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_INS_PATH, getInsPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_CFG_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_CFG_PATH, deriveCfgPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_LOG_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_LOG_PATH, deriveLogPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_DS_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_DS_PATH, deriveDSPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_RDB_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_RDB_PATH, deriveRDBMSPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_GDB_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_GDB_PATH, deriveGraphPathName());

        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        JoranConfigurator joranConfigurator = new JoranConfigurator();
        joranConfigurator.setContext(loggerContext);
        loggerContext.reset();
        joranConfigurator.doConfigure(logFileName);
    } catch (ConfigurationException e) {
        throw new NSException("Configuration parsing error: " + e.getMessage());
    } catch (JoranException e) {
        throw new NSException("Logback parsing error: " + e.getMessage());
    } catch (ClassCastException ignored) {

        /* Note that a WARNING related to java.lang.ClassCastException will trigger due to
        Smart GWT and NSD being dependent on different releases of the same logging
        framework.  http://www.slf4j.org/codes.html */

    }
}

From source file:org.apache.falcon.regression.core.util.Config.java

private void initConfig(String propFileName) throws ConfigurationException {
    CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
    LOGGER.info("Going to add properties from system properties.");
    compositeConfiguration.addConfiguration(new SystemConfiguration());

    LOGGER.info("Going to read properties from: " + propFileName);
    final PropertiesConfiguration merlinConfig = new PropertiesConfiguration(
            Config.class.getResource("/" + propFileName));
    //if changed configuration will be reloaded within 2 min
    final FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
    reloadingStrategy.setRefreshDelay(2 * 60 * 1000);
    merlinConfig.setReloadingStrategy(reloadingStrategy);
    compositeConfiguration.addConfiguration(merlinConfig);
    this.confObj = compositeConfiguration;
}

From source file:org.apache.juddi.config.AppConfig.java

/**
 * Does the actual work of reading the configuration from System
 * Properties and/or juddiv3.properties file. When the juddiv3.properties
 * file is updated the file will be reloaded. By default the reloadDelay is
 * set to 1 second to prevent excessive date stamp checking.
 *//*from   w  w  w  .  j av a 2 s. c  o  m*/
private void loadConfiguration() throws ConfigurationException {
    //Properties from system properties
    CompositeConfiguration compositeConfig = new CompositeConfiguration();
    compositeConfig.addConfiguration(new SystemConfiguration());
    //Properties from file
    //changed 7-19-2013 AO for JUDDI-627
    XMLConfiguration propConfig = null;
    final String filename = System.getProperty(JUDDI_CONFIGURATION_FILE_SYSTEM_PROPERTY);
    if (filename != null) {
        propConfig = new XMLConfiguration(filename);
        try {
            loadedFrom = new File(filename).toURI().toURL();
            //   propConfig = new PropertiesConfiguration(filename);
        } catch (MalformedURLException ex) {
            try {
                loadedFrom = new URL("file://" + filename);
            } catch (MalformedURLException ex1) {
                log.warn("unable to get an absolute path to " + filename
                        + ". This may be ignorable if everything works properly.", ex1);
            }
        }
    } else {
        //propConfig = new PropertiesConfiguration(JUDDI_PROPERTIES);
        propConfig = new XMLConfiguration(JUDDI_PROPERTIES);
        loadedFrom = ClassUtil.getResource(JUDDI_PROPERTIES, this.getClass());
    }
    //Hey! this may break things
    propConfig.setAutoSave(true);

    log.info("Reading from properties file:  " + loadedFrom);
    long refreshDelay = propConfig.getLong(Property.JUDDI_CONFIGURATION_RELOAD_DELAY, 1000l);
    log.debug("Setting refreshDelay to " + refreshDelay);
    FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
    fileChangedReloadingStrategy.setRefreshDelay(refreshDelay);
    propConfig.setReloadingStrategy(fileChangedReloadingStrategy);
    compositeConfig.addConfiguration(propConfig);

    Properties properties = new Properties();
    if ("Hibernate".equals(propConfig.getString(Property.PERSISTENCE_PROVIDER))) {
        if (propConfig.containsKey(Property.DATASOURCE))
            properties.put("hibernate.connection.datasource", propConfig.getString(Property.DATASOURCE));
        if (propConfig.containsKey(Property.HBM_DDL_AUTO))
            properties.put("hibernate.hbm2ddl.auto", propConfig.getString(Property.HBM_DDL_AUTO));
        if (propConfig.containsKey(Property.DEFAULT_SCHEMA))
            properties.put("hibernate.default_schema", propConfig.getString(Property.DEFAULT_SCHEMA));
        if (propConfig.containsKey(Property.HIBERNATE_DIALECT))
            properties.put("hibernate.dialect", propConfig.getString(Property.HIBERNATE_DIALECT));
    }
    // initialize the entityManagerFactory.
    PersistenceManager.initializeEntityManagerFactory(propConfig.getString(Property.JUDDI_PERSISTENCEUNIT_NAME),
            properties);
    // Properties from the persistence layer 
    MapConfiguration persistentConfig = new MapConfiguration(getPersistentConfiguration(compositeConfig));

    compositeConfig.addConfiguration(persistentConfig);
    //Making the new configuration globally accessible.
    config = compositeConfig;
}

From source file:org.apache.juddi.v3.client.config.ClientConfig.java

/**
 * Does the actual work of reading the configuration from System
 * Properties and/or uddi.xml file. When the uddi.xml
 * file is updated the file will be reloaded. By default the reloadDelay is
 * set to 1 second to prevent excessive date stamp checking.
 *///from   w w  w  .j av a2 s  .c  o m
private void loadConfiguration(String configurationFile, Properties properties) throws ConfigurationException {
    //Properties from system properties
    CompositeConfiguration compositeConfig = new CompositeConfiguration();
    compositeConfig.addConfiguration(new SystemConfiguration());
    //Properties from XML file
    if (System.getProperty(UDDI_CONFIG_FILENAME_PROPERTY) != null) {
        log.info("Using system property config override");
        configurationFile = System.getProperty(UDDI_CONFIG_FILENAME_PROPERTY);
    }
    XMLConfiguration xmlConfig = null;
    if (configurationFile != null) {
        xmlConfig = new XMLConfiguration(configurationFile);
    } else {
        final String filename = System.getProperty(UDDI_CONFIG_FILENAME_PROPERTY);
        if (filename != null) {
            xmlConfig = new XMLConfiguration(filename);
        } else {
            xmlConfig = new XMLConfiguration(DEFAULT_UDDI_CONFIG);
        }
    }
    log.info("Reading UDDI Client properties file " + xmlConfig.getBasePath() + " use -D"
            + UDDI_CONFIG_FILENAME_PROPERTY + " to override");
    this.configurationFile = xmlConfig.getBasePath();
    long refreshDelay = xmlConfig.getLong(Property.UDDI_RELOAD_DELAY, 1000l);
    log.debug("Setting refreshDelay to " + refreshDelay);
    FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
    fileChangedReloadingStrategy.setRefreshDelay(refreshDelay);
    xmlConfig.setReloadingStrategy(fileChangedReloadingStrategy);
    compositeConfig.addConfiguration(xmlConfig);
    //Making the new configuration globally accessible.
    config = compositeConfig;
    readConfig(properties);
}

From source file:org.apache.tajo.util.metrics.TajoSystemMetrics.java

public TajoSystemMetrics(TajoConf tajoConf, Class clazz, String hostAndPort) {
    super(MetricsUtil.getGroupName(clazz));

    this.hostAndPort = hostAndPort;
    try {/* ww  w .j  a v a2  s .  c  o  m*/
        this.metricsPropertyFileName = tajoConf.getVar(TajoConf.ConfVars.METRICS_PROPERTY_FILENAME);
        this.metricsProps = new PropertiesConfiguration(metricsPropertyFileName);
        this.metricsProps.addConfigurationListener(new MetricsReloadListener());
        FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
        reloadingStrategy.setRefreshDelay(5 * 1000);
        this.metricsProps.setReloadingStrategy(reloadingStrategy);
    } catch (ConfigurationException e) {
        LOG.warn(e.getMessage(), e);
    }

    // PropertiesConfiguration fire configurationChanged after getXXX()
    // So neeaded calling getXXX periodically
    propertyChangeChecker = new Thread() {
        public void run() {
            while (!stop.get()) {
                String value = metricsProps.getString("reporter.file");
                try {
                    Thread.sleep(10 * 1000);
                } catch (InterruptedException e) {
                }
            }
        }
    };

    propertyChangeChecker.start();
}

From source file:org.jboss.datavirt.commons.config.ConfigurationFactory.java

/**
 * Shared method used to locate and load configuration information from a number of
 * places, aggregated into a single {@link Configuration} instance.
 * @param configFileOverride//from  w  w w .j a v a 2  s .  c  om
 * @param standardConfigFileName
 * @param refreshDelay
 * @param defaultConfigPath
 * @param defaultConfigLoader
 * @throws ConfigurationException
 */
public static Configuration createConfig(String configFileOverride, String standardConfigFileName,
        Long refreshDelay, String defaultConfigPath, Class<?> defaultConfigLoader) {
    registerGlobalLookups();
    try {
        CompositeConfiguration config = new CompositeConfiguration();
        config.addConfiguration(new SystemPropertiesConfiguration());
        URL url = findConfig(configFileOverride, standardConfigFileName);
        if (url != null) {
            PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(url);
            FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
            fileChangedReloadingStrategy.setRefreshDelay(refreshDelay);
            propertiesConfiguration.setReloadingStrategy(fileChangedReloadingStrategy);
            config.addConfiguration(propertiesConfiguration);
        }
        if (defaultConfigPath != null) {
            config.addConfiguration(
                    new PropertiesConfiguration(defaultConfigLoader.getResource(defaultConfigPath)));
        }
        return config;
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.nibblesec.tools.SerialKiller.java

public SerialKiller(InputStream inputStream, String configFile) throws IOException, ConfigurationException {
    super(inputStream);
    config = new XMLConfiguration(configFile);
    FileChangedReloadingStrategy reloadStrategy = new FileChangedReloadingStrategy();
    reloadStrategy.setRefreshDelay(config.getLong("refresh"));
    config.setReloadingStrategy(reloadStrategy);
}

From source file:org.osbo.configuration.OsboConfigurationFiles.java

public OsboConfigurationFiles(String ruta, long tiempo) {
    // Exists only to defeat instantiation.
    file = ruta;//from w  ww. ja v  a 2  s  . co m
    config = null;
    try {
        config = new PropertiesConfiguration(file);
    } catch (ConfigurationException ex) {
        ex.printStackTrace();
    }
    FileChangedReloadingStrategy conf = new FileChangedReloadingStrategy();
    conf.setRefreshDelay(tiempo);
    config.setReloadingStrategy(conf);
}