List of usage examples for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy
FileChangedReloadingStrategy
From source file:com.github.technosf.posterer.transports.commons.CommonsConfiguratorPropertiesImpl.java
/** * @param prefix/* ww w . j a va 2 s . c o m*/ * @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.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 w w w .j a v a 2 s .c o m return properties; }
From source file:com.twitter.distributedlog.config.ConfigurationSubscription.java
private boolean initConfig() { if (fileConfigs.isEmpty()) { try {/*from www . j a v a 2 s. 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:cross.datastructures.pipeline.ResultAwareCommandPipeline.java
/** * * @param workflow//from ww w . j ava2s .c o m * @return */ protected PropertiesConfiguration getHashes(IWorkflow workflow) { File hashesFile = getHashesFile(workflow); if (hashes == null) { try { hashes = new PropertiesConfiguration(hashesFile); hashes.setAutoSave(true); hashes.setReloadingStrategy(new FileChangedReloadingStrategy()); log.debug("Hashes: {}", ConfigurationUtils.toString(hashes)); return hashes; } catch (ConfigurationException ex) { log.error("Could not load configuration at " + hashesFile, ex); throw new ExitVmException(ex); } } else { return hashes; } }
From source file:com.intuit.tank.proxy.config.CommonsProxyConfiguration.java
/** * Constructor pulls file out of the jar or reads from disk and sets up refresh policy. * /*w w w .j a va2 s. c o m*/ * @param expressionEngine * the expression engine to use. Null results in default expression engine */ private void readConfig() { try { XPathExpressionEngine expressionEngine = new XPathExpressionEngine(); if (reloadingStrategy == null) { reloadingStrategy = new FileChangedReloadingStrategy(); reloadingStrategy.setRefreshDelay(0); } File configFile = new File(configPath); System.out.println(configFile.getAbsolutePath()); if (configFile.exists() && configFile.isFile()) { try { config = new XMLConfiguration(configFile); } catch (Exception e) { LOG.error("Error parsing configFile " + configFile.getAbsolutePath() + ": " + e, e); } } if (config == null) { // Load a default from the classpath: LOG.info("Reading default configuration " + DEFAULT_CONFIG + " from classpath..."); // Note: we don't let new XMLConfiguration() lookup the resource // url directly because it may not be able to find the desired // classloader to load the URL from. URL configResourceUrl = this.getClass().getClassLoader().getResource(DEFAULT_CONFIG); if (configResourceUrl == null) { throw new RuntimeException("unable to load resource: " + configPath); } config = new XMLConfiguration(configResourceUrl); // // Copy over a default configuration since none exists: // // Ensure data dir location exists: // configFile = new File(DEFAULT_CONFIG); // // if (!configFile.getParentFile().exists() && !configFile.getParentFile().mkdirs()) { // // throw new RuntimeException("could not create directories."); // // } // LOG.info("Saving default configuration to file " + configFile.getAbsolutePath()); // config.save(configFile); } if (expressionEngine != null) { config.setExpressionEngine(expressionEngine); } // reload at most once per thirty seconds on configuration queries. config.setReloadingStrategy(reloadingStrategy); initConfig(); } catch (ConfigurationException e) { throw new RuntimeException(e); } }
From source file:com.manydesigns.portofino.i18n.ResourceBundleManager.java
public ResourceBundle getBundle(Locale locale) { ConfigurationResourceBundle bundle = resourceBundles.get(locale); if (bundle == null) { CompositeConfiguration configuration = new CompositeConfiguration(); Iterator<String> iterator = searchPaths.descendingIterator(); while (iterator.hasNext()) { String path = iterator.next(); int index = path.lastIndexOf('/') + 1; String basePath = path.substring(0, index); int suffixIndex = path.length() - ".properties".length(); String resourceBundleBaseName = path.substring(index, suffixIndex); String bundleName = getBundleFileName(resourceBundleBaseName, locale); PropertiesConfiguration conf; try { conf = new PropertiesConfiguration(); conf.setFileName(basePath + bundleName); conf.setDelimiterParsingDisabled(true); conf.load();//from w w w . jav a 2 s . com } catch (ConfigurationException e) { logger.debug("Couldn't load resource bundle for locale " + locale + " from " + basePath, e); //Fall back to default .properties without _locale try { String defaultBundleName = basePath + resourceBundleBaseName + ".properties"; conf = new PropertiesConfiguration(); conf.setFileName(defaultBundleName); conf.setDelimiterParsingDisabled(true); conf.load(); } catch (ConfigurationException e1) { logger.debug("Couldn't load default resource bundle from " + basePath, e1); conf = null; } } if (conf != null) { FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy(); conf.setReloadingStrategy(reloadingStrategy); configuration.addConfiguration(conf); } } bundle = new ConfigurationResourceBundle(configuration, locale); //TODO setParent? resourceBundles.put(locale, bundle); } return bundle; }
From source file:cz.mzk.editor.server.config.EditorConfigurationImpl.java
public EditorConfigurationImpl() { File dir = new File(WORKING_DIR); if (!dir.exists()) { boolean mkdirs = dir.mkdirs(); if (!mkdirs) { LOGGER.error("cannot create directory '" + dir.getAbsolutePath() + "'"); throw new RuntimeException("cannot create directory '" + dir.getAbsolutePath() + "'"); }//from w w w .j a va 2 s.c o m } File confFile = new File(CONFIGURATION); if (!confFile.exists()) { try { confFile.createNewFile(); } catch (IOException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } FileOutputStream confFos; try { confFos = new FileOutputStream(confFile); } catch (FileNotFoundException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } try { try { new Properties().store(confFos, "configuration file for module metadata editor"); } catch (IOException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException( "cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } } finally { try { if (confFos != null) confFos.close(); } catch (IOException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException( "cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } finally { confFos = null; } } } CompositeConfiguration constconf = new CompositeConfiguration(); PropertiesConfiguration file = null; try { file = new PropertiesConfiguration(confFile); } catch (ConfigurationException e) { LOGGER.error(e.getMessage(), e); new RuntimeException("cannot read configuration"); } file.setReloadingStrategy(new FileChangedReloadingStrategy()); constconf.addConfiguration(file); constconf.setProperty(ServerConstants.EDITOR_HOME, WORKING_DIR); this.configuration = constconf; String hostname = configuration.getString(EditorClientConfiguration.Constants.HOSTNAME, "editor.mzk.cz"); if (hostname.contains("://")) { hostname = hostname.substring(hostname.indexOf("://") + "://".length()); } File imagesDir = new File(ServerConstants.DEFAULT_IMAGES_LOCATION + hostname + File.separator); if (!imagesDir.exists()) { boolean mkdirs = imagesDir.mkdirs(); if (!mkdirs) { LOGGER.error("cannot create directory '" + imagesDir.getAbsolutePath() + "'"); throw new RuntimeException("cannot create directory '" + imagesDir.getAbsolutePath() + "'"); } } constconf.setProperty(ServerConstants.IMAGES_LOCATION, ServerConstants.DEFAULT_IMAGES_LOCATION + hostname + File.separator); EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration(); for (Iterator it = environmentConfiguration.getKeys(); it.hasNext();) { String key = (String) it.next(); Object value = environmentConfiguration.getProperty(key); key = key.replaceAll("_", "."); key = key.replaceAll("\\.\\.", "__"); constconf.addProperty(key, value); } }
From source file:cz.fi.muni.xkremser.editor.server.config.EditorConfigurationImpl.java
public EditorConfigurationImpl() { File dir = new File(WORKING_DIR); if (!dir.exists()) { boolean mkdirs = dir.mkdirs(); if (!mkdirs) { LOGGER.error("cannot create directory '" + dir.getAbsolutePath() + "'"); throw new RuntimeException("cannot create directory '" + dir.getAbsolutePath() + "'"); }/*from ww w . ja v a2s . c o m*/ } File confFile = new File(CONFIGURATION); if (!confFile.exists()) { try { confFile.createNewFile(); } catch (IOException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } FileOutputStream confFos; try { confFos = new FileOutputStream(confFile); } catch (FileNotFoundException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException("cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } try { try { new Properties().store(confFos, "configuration file for module metadata editor"); } catch (IOException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException( "cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } } finally { try { if (confFos != null) confFos.close(); } catch (IOException e) { LOGGER.error("cannot create configuration file '" + confFile.getAbsolutePath() + "'", e); throw new RuntimeException( "cannot create configuration file '" + confFile.getAbsolutePath() + "'"); } finally { confFos = null; } } } File imagesDir = new File(DEFAULT_IMAGES_LOCATION); if (!imagesDir.exists()) { boolean mkdirs = imagesDir.mkdirs(); if (!mkdirs) { LOGGER.error("cannot create directory '" + imagesDir.getAbsolutePath() + "'"); throw new RuntimeException("cannot create directory '" + imagesDir.getAbsolutePath() + "'"); } } CompositeConfiguration constconf = new CompositeConfiguration(); PropertiesConfiguration file = null; try { file = new PropertiesConfiguration(confFile); } catch (ConfigurationException e) { LOGGER.error(e.getMessage(), e); new RuntimeException("cannot read configuration"); } file.setReloadingStrategy(new FileChangedReloadingStrategy()); constconf.addConfiguration(file); constconf.setProperty(ServerConstants.EDITOR_HOME, WORKING_DIR); this.configuration = constconf; }
From source file:com.jkoolcloud.tnt4j.repository.FileTokenRepository.java
@Override public void open() throws IOException { if (isOpen() || (configName == null)) return;/*w ww .j av a 2s . c o 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.mirth.connect.server.controllers.DefaultExtensionController.java
private void initialize() { try {//from ww w .ja v a2 s . 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); } }