List of usage examples for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy
FileChangedReloadingStrategy
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.opennms.pris.config.InstanceApacheConfiguration.java
private static org.apache.commons.configuration.Configuration createConfig(final Path basePath) { final Path path = basePath.resolve("requisition.properties"); // Raise wrapped file not found exception if the config file does not exist if (!Files.exists(path)) { throw new RuntimeException("Config file not found: " + path); }/*from w w w. ja v a 2 s . c o m*/ // Load system and file properties try { return new org.apache.commons.configuration.PropertiesConfiguration(path.toFile()) { { setThrowExceptionOnMissing(true); setReloadingStrategy(new FileChangedReloadingStrategy()); } }; } catch (final ConfigurationException ex) { throw new RuntimeException(ex); } }
From source file:org.osbo.configuration.OsboConfigurationFiles.java
public OsboConfigurationFiles(String ruta, long tiempo) { // Exists only to defeat instantiation. file = ruta;/* ww w . j a va2 s . c o m*/ config = null; try { config = new PropertiesConfiguration(file); } catch (ConfigurationException ex) { ex.printStackTrace(); } FileChangedReloadingStrategy conf = new FileChangedReloadingStrategy(); conf.setRefreshDelay(tiempo); config.setReloadingStrategy(conf); }
From source file:org.overlord.commons.config.configurator.AbstractPropertiesFileConfigurator.java
/** * @see org.overlord.commons.config.configurator.Configurator#provideConfiguration(java.lang.String, java.lang.Long) *///from w w w. ja va 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.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 {/*from w w w .j a v a2 s . c o 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 {/*from w w w . j ava 2 s. co m*/ 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.soaplab.services.Config.java
/************************************************************************** * Add given XML files as a new configuration to 'cfg' composite * configuration. Return true on success. **************************************************************************/ private static boolean addXMLConfiguration(CompositeConfiguration cfg, String configFilename) { try {//from w w w . ja va 2 s. co m XMLConfiguration xmlConfig = new XMLConfiguration(configFilename); if (isExistingConfig(xmlConfig)) return true; xmlConfig.setReloadingStrategy(new FileChangedReloadingStrategy()); cfg.addConfiguration(xmlConfig); return true; } catch (ConfigurationException e) { log.error("Loading XML configuration from '" + configFilename + "' failed: " + e.getMessage()); return false; } }
From source file:org.soaplab.services.DefaultAnalysisInventory.java
/************************************************************************** * Check if the property containing filename with an analysis list * (or filenames, actually) has changed since the last time we saw * it. If yes, reload analysis list(s) defined in this property. *************************************************************************/ protected synchronized void reloadConfig() { // find the filename(s) with our analysis list(s) String[] fileNames = Config.get().getStringArray(Config.PROP_APPLIST_FILENAME); if (fileNames == null || fileNames.length == 0) { if (!warningIssued) { log.warn("Property '" + Config.PROP_APPLIST_FILENAME + "' not found."); warningIssued = true;// ww w . j a va 2 s .c o m } configs = null; lastUsedFileNames = null; appList = new Hashtable<String, Vector<AnalysisInstallation>>(); return; } // has PROP_APPLIST_FILENAME changed since last visit? String joined = StringUtils.join(fileNames, ","); if (!joined.equals(lastUsedFileNames)) { warningIssued = false; List<XMLConfiguration> configsList = new ArrayList<XMLConfiguration>(); for (int i = 0; i < fileNames.length; i++) { try { XMLConfiguration config = new XMLConfiguration(fileNames[i]); config.setReloadingStrategy(new FileChangedReloadingStrategy() { public void reloadingPerformed() { super.reloadingPerformed(); // because of updateLastModified(); readConfigs(); } }); configsList.add(config); log.info("Using analysis list file '" + fileNames[i] + "'"); } catch (ConfigurationException e) { log.error("Loading analysis list from '" + fileNames[i] + "' failed: " + e.getMessage()); } } if (configsList.size() > 0) { configs = configsList.toArray(new XMLConfiguration[] {}); readConfigs(); lastUsedFileNames = joined; } else { configs = null; lastUsedFileNames = null; appList = new Hashtable<String, Vector<AnalysisInstallation>>(); } } // try to trigger reloading of individual XML file names (if // they changed) if (configs != null) { for (int i = 0; i < configs.length; i++) configs[i].isEmpty(); } }
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 www . ja v a2 s . co 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; }