List of usage examples for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy
FileChangedReloadingStrategy
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 ww w. ja v 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 .ja v a 2 s . co 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 {/*w w w .ja 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.betaconceptframework.astroboa.engine.definition.ContentDefinitionConfiguration.java
private void loadConfigurationFiles(CmsRepository associatedRepository, boolean logWarningIfNoXSDFileFound) { //Load BetaConcept Definition files from repository home directory //which exists in RepositoryContextImpl try {/*from www . j a v a2s . co m*/ File[] schemaFiles = retrieveXmlSchemaFiles(associatedRepository, logWarningIfNoXSDFileFound); //Create a file configuration for each xsd file //This is done in order to track any changes made at runtime to XSD //in order to reload definition definitionFileConfigurations.put(associatedRepository.getId(), new ArrayList<FileConfiguration>()); if (ArrayUtils.isEmpty(schemaFiles) && logWarningIfNoXSDFileFound) { logger.warn("Found no definition schema files for repository " + associatedRepository); } else { for (File defFile : schemaFiles) { try { logger.debug("Loading definition file {} for repository {}", defFile.getAbsolutePath(), associatedRepository.getId()); XMLConfiguration fileConfiguration = new XMLConfiguration(defFile); fileConfiguration.setReloadingStrategy(new FileChangedReloadingStrategy()); definitionFileConfigurations.get(associatedRepository.getId()).add(fileConfiguration); } catch (Exception e) { logger.error("Error loading definition file " + defFile.getAbsolutePath() + " for repository " + associatedRepository.getId() + "Most probably, it is not a valid XML file. All other definitions will be loaded", e); //Load an empty xml configuration XMLConfiguration fileConfiguration = new XMLConfiguration(); definitionFileConfigurations.get(associatedRepository.getId()).add(fileConfiguration); } } } } catch (Throwable e) { throw new CmsException(e); } }
From source file:org.betaconceptframework.astroboa.engine.definition.ContentDefinitionConfiguration.java
public void setConfigurationFile(String configurationFile) { if (configurationFile != null) try {/*from w w w. ja v a 2 s . com*/ configuration = new PropertiesConfiguration(configurationFile); configuration.setReloadingStrategy(new FileChangedReloadingStrategy()); final String cmsModeFromFile = configuration.getString(CmsConstants.CMS_MODE, CmsMode.production.toString()); //Set CmsMode if (cmsModeFromFile != null) cmsMode = CmsMode.valueOf(cmsModeFromFile.toLowerCase()); else cmsMode = CmsMode.production; } catch (Exception e) { logger.warn("Unable to load content definition properties file", e); } }
From source file:org.cesecore.config.ConfigurationHolder.java
public static synchronized Configuration instance() { if (config == null) { // Read in default values defaultValues = new CompositeConfiguration(); final URL defaultConfigUrl = ConfigurationHolder.class.getResource(DEFAULT_CONFIG_FILE); try {//from w ww . j a v a2s. c om defaultValues.addConfiguration(new PropertiesConfiguration(defaultConfigUrl)); } catch (ConfigurationException e) { log.error("Error encountered when loading default properties. Could not load configuration from " + defaultConfigUrl, e); } // read cesecore.properties, from config file built into jar, and see if we allow configuration by external files boolean allowexternal = false; try { final URL url = ConfigurationHolder.class.getResource("/conf/" + CONFIG_FILES[0]); if (url != null) { final PropertiesConfiguration pc = new PropertiesConfiguration(url); allowexternal = "true".equalsIgnoreCase(pc.getString(CONFIGALLOWEXTERNAL, "false")); log.info("Allow external re-configuration: " + allowexternal); } } catch (ConfigurationException e) { log.error("Error intializing configuration: ", e); } config = new CompositeConfiguration(); // Only add these config sources if we allow external configuration if (allowexternal) { // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo) config.addConfiguration(new SystemConfiguration()); log.info("Added system properties to configuration source (java -Dfoo.prop=bar)."); // Override with file in "application server home directory"/conf, this is prio 2 for (int i = 0; i < CONFIG_FILES.length; i++) { File f = null; try { f = new File("conf" + File.separator + CONFIG_FILES[i]); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); } } // Override with file in "/etc/cesecore/conf/, this is prio 3 for (int i = 0; i < CONFIG_FILES.length; i++) { File f = null; try { f = new File("/etc/cesecore/conf/" + CONFIG_FILES[i]); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); } } } // if (allowexternal) // Default values build into jar file, this is last prio used if no of the other sources override this for (int i = 0; i < CONFIG_FILES.length; i++) { addConfigurationResource("/conf/" + CONFIG_FILES[i]); } // Load internal.properties only from built in configuration file try { final URL url = ConfigurationHolder.class.getResource("/internal.properties"); if (url != null) { final PropertiesConfiguration pc = new PropertiesConfiguration(url); config.addConfiguration(pc); log.debug("Added url to configuration source: " + url); } } catch (ConfigurationException e) { log.error("Failed to load configuration from resource internal.properties", e); } } return config; }
From source file:org.cesecore.config.ConfigurationHolder.java
/** * Method used primarily for JUnit testing, where we can add a new properties file (in tmp directory) to the configuration. * //from ww w . ja v a2s . com * @param filename the full path to the properties file used for configuration. */ public static void addConfigurationFile(final String filename) { // Make sure the basic initialization has been done instance(); File f = null; try { f = new File(filename); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); } }
From source file:org.dspace.servicemanager.config.DSpacePropertiesConfiguration.java
public DSpacePropertiesConfiguration(File file) throws ConfigurationException { write = new PropertiesConfiguration(file); write.setAutoSave(true);/*from w w w .j a v a2 s . com*/ read = new PropertiesConfiguration(file); read.setAutoSave(false); FileChangedReloadingStrategy stretagy = new FileChangedReloadingStrategy(); read.setReloadingStrategy(stretagy); write.setReloadingStrategy(stretagy); }
From source file:org.dspace.servicemanager.config.DSpacePropertiesConfiguration.java
public DSpacePropertiesConfiguration(String fileName) throws ConfigurationException { write = new PropertiesConfiguration(fileName); write.setAutoSave(true);/*from w w w . j a v a 2s.c om*/ read = new PropertiesConfiguration(fileName); read.setAutoSave(false); FileChangedReloadingStrategy stretagy = new FileChangedReloadingStrategy(); read.setReloadingStrategy(stretagy); write.setReloadingStrategy(stretagy); }