List of usage examples for org.apache.commons.configuration PropertiesConfiguration setReloadingStrategy
public void setReloadingStrategy(ReloadingStrategy strategy)
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/* w ww . ja va 2 s . c o m*/ * @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.jboss.forge.addon.configuration.ConfigurationFactoryImpl.java
private Configuration getConfiguration(File file) { try {//from w w w . j ava2 s. co m PropertiesConfiguration commonsConfig = new PropertiesConfiguration(file); commonsConfig.setEncoding("UTF-8"); commonsConfig.setReloadingStrategy(new FileChangedReloadingStrategy()); commonsConfig.setAutoSave(true); return new ConfigurationAdapter(commonsConfig); } catch (org.apache.commons.configuration.ConfigurationException e) { throw new ConfigurationException("Error while creating configuration from " + file, e); } }
From source file:org.kitodo.config.Config.java
/** * Returns the configuration.//from www .j ava 2s . c om * * @param configFile * file with configuration * @return the configuration */ static PropertiesConfiguration getConfig(String configFile) { if (Objects.isNull(config)) { synchronized (Config.class) { PropertiesConfiguration initialized = config; if (Objects.isNull(initialized)) { AbstractConfiguration.setDefaultListDelimiter('&'); try { initialized = new PropertiesConfiguration(configFile); } catch (ConfigurationException e) { logger.warn( "Loading of " + configFile + " failed. Trying to start with empty configuration.", e); initialized = new PropertiesConfiguration(); } initialized.setListDelimiter('&'); initialized.setReloadingStrategy(new FileChangedReloadingStrategy()); initialized.setThrowExceptionOnMissing(true); config = initialized; } } } return config; }
From source file:org.kitodo.config.ConfigMain.java
/** * Get properties from configuration file. * * @return PropertiesConfiguration object *//*w w w .j ava 2 s . c om*/ private static PropertiesConfiguration getConfig() { if (config == null) { synchronized (ConfigMain.class) { PropertiesConfiguration initialized = config; if (initialized == null) { PropertiesConfiguration.setDefaultListDelimiter('&'); try { initialized = new PropertiesConfiguration(CONFIG_FILE); } catch (ConfigurationException e) { logger.warn("Loading of {} failed. Trying to start with empty configuration. Exception: {}", CONFIG_FILE, e); initialized = new PropertiesConfiguration(); } initialized.setListDelimiter('&'); initialized.setReloadingStrategy(new FileChangedReloadingStrategy()); config = initialized; } } } return config; }
From source file:org.overlord.commons.config.configurator.AbstractPropertiesFileConfigurator.java
/** * @see org.overlord.commons.config.configurator.Configurator#provideConfiguration(java.lang.String, java.lang.Long) *///w ww .ja v a 2 s . c o m @Override public Configuration provideConfiguration(String configName, Long refreshDelay) throws ConfigurationException { URL url = findConfigUrl(configName); if (url != null) { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(url); FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy(); fileChangedReloadingStrategy.setRefreshDelay(refreshDelay); propertiesConfiguration.setReloadingStrategy(fileChangedReloadingStrategy); return propertiesConfiguration; } else { return null; } }
From source file:org.pentaho.hadoop.PropertiesConfigurationProperties.java
private static PropertiesConfiguration initPropertiesConfiguration(FileObject fileObject) throws FileSystemException, ConfigurationException { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(fileObject.getURL()); propertiesConfiguration.setAutoSave(true); FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy(); fileChangedReloadingStrategy.setRefreshDelay(1000L); propertiesConfiguration.setReloadingStrategy(fileChangedReloadingStrategy); return propertiesConfiguration; }
From source file:org.roda.core.RodaCoreFactory.java
public static Configuration getConfiguration(String configurationFile) throws ConfigurationException { Path config = RodaCoreFactory.getConfigPath().resolve(configurationFile); PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setDelimiterParsingDisabled(true); propertiesConfiguration.setEncoding(RodaConstants.DEFAULT_ENCODING); if (FSUtils.exists(config)) { LOGGER.trace("Loading configuration from file {}", config); propertiesConfiguration.load(config.toFile()); RodaPropertiesReloadStrategy rodaPropertiesReloadStrategy = new RodaPropertiesReloadStrategy(); rodaPropertiesReloadStrategy.setRefreshDelay(5000); propertiesConfiguration.setReloadingStrategy(rodaPropertiesReloadStrategy); } else {/*from ww w .ja va2 s . c om*/ InputStream inputStream = RodaCoreFactory.class .getResourceAsStream("/" + RodaConstants.CORE_CONFIG_FOLDER + "/" + configurationFile); if (inputStream != null) { LOGGER.trace("Loading configuration from classpath {}", configurationFile); propertiesConfiguration.load(inputStream); } else { LOGGER.trace("Configuration {} doesn't exist", configurationFile); } } return propertiesConfiguration; }
From source file:org.soaplab.clients.ClientConfig.java
/************************************************************************** * Add given property files as a new configuration to 'cfg' * composite configuration. Return true on success. **************************************************************************/ private static boolean addPropertiesConfiguration(CompositeConfiguration cfg, String configFilename) { try {// ww w . j a va2s. co m PropertiesConfiguration propsConfig = new PropertiesConfiguration(configFilename); propsConfig.setReloadingStrategy(new FileChangedReloadingStrategy()); cfg.addConfiguration(propsConfig); return true; } catch (ConfigurationException e) { log.error("Loading properties configuration from '" + configFilename + "' failed: " + e.getMessage()); return false; } }
From source file:org.soaplab.services.Config.java
/************************************************************************** * Add given property files as a new configuration to 'cfg' * composite configuration. Return true on success. **************************************************************************/ private static boolean addPropertiesConfiguration(CompositeConfiguration cfg, String configFilename) { try {// w w w .j ava 2 s . c om PropertiesConfiguration propsConfig = new PropertiesConfiguration(configFilename); if (isExistingConfig(propsConfig)) return true; propsConfig.setReloadingStrategy(new FileChangedReloadingStrategy()); cfg.addConfiguration(propsConfig); return true; } catch (ConfigurationException e) { log.error("Loading properties configuration from '" + configFilename + "' failed: " + e.getMessage()); return false; } }
From source file:org.unitime.timetable.util.MessageResources.java
private Configuration getConfiguration(String name) { Configuration configuration = null; URL url = Thread.currentThread().getContextClassLoader().getResource(name); if (url != null) { PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setURL(url);/*from w ww .j a v a2s. c o m*/ // Set reloading strategy String dynamicReload = ApplicationProperties.getProperty("tmtbl.properties.dynamic_reload", null); if (dynamicReload != null && dynamicReload.equalsIgnoreCase("true")) { long refreshDelay = Constants.getPositiveInteger( ApplicationProperties.getProperty("tmtbl.properties.dynamic_reload_interval"), 15000); FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); strategy.setRefreshDelay(refreshDelay); pc.setReloadingStrategy(strategy); pc.addConfigurationListener(new MessageResourcesCfgListener(pc.getBasePath())); } try { pc.load(); configuration = pc; } catch (ConfigurationException e) { Debug.error("Message Resources configuration exception: " + e.getMessage()); } } return configuration; }