List of usage examples for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy
FileChangedReloadingStrategy
From source file:com.bitcup.configurator.FileConfig.java
private FileChangedReloadingStrategy getReloadingStrategy() { final FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy(); reloadingStrategy.setRefreshDelay(TimeUnit.SECONDS.toMillis(this.refreshDelaySecs)); return reloadingStrategy; }
From source file:cz.cas.lib.proarc.common.config.AppConfiguration.java
private void buildConfiguration(CompositeConfiguration cc, File cfgFile) { try {/* w w w . j a v a2 s . c o m*/ // envConfig contains interpolated properties PropertiesConfiguration envConfig = new PropertiesConfiguration(); envConfig.addProperty(PROPERTY_APP_HOME, configHome.getPath()); cc.addConfiguration(envConfig); // external configuration editable by users; UTF-8 expected PropertiesConfiguration external = new PropertiesConfiguration(); external.setEncoding("UTF-8"); FileChangedReloadingStrategy reloading = new FileChangedReloadingStrategy(); external.setReloadingStrategy(reloading); external.setFile(cfgFile); cc.addConfiguration(external); try { // bundled default configurations Enumeration<URL> resources = AppConfiguration.class.getClassLoader() .getResources(DEFAULT_PROPERTIES_RESOURCE); for (URL resource; resources.hasMoreElements();) { resource = resources.nextElement(); LOG.log(Level.FINE, "classpath config: {0}", resource); cc.addConfiguration(new PropertiesConfiguration(resource)); } } catch (IOException ex) { LOG.log(Level.SEVERE, null, ex); } } catch (ConfigurationException ex) { LOG.log(Level.SEVERE, null, ex); } }
From source file:com.dc.gameserver.baseConfig.Config.java
/** * ??//from www . jav a 2s. com * @throws org.apache.commons.configuration.ConfigurationException */ public static void IntiConfig() throws ConfigurationException { PropertiesConfiguration server_config = new PropertiesConfiguration(DEFAULT_VALUE.FILE_PATH.SERVER); PropertiesConfiguration game_config = new PropertiesConfiguration(DEFAULT_VALUE.FILE_PATH.GAME); FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); //default 5000 if (server_config.getBoolean("autoReload")) { strategy.setRefreshDelay(server_config.getInt("refreshDelay", 5000)); server_config.setReloadingStrategy(strategy); game_config.setReloadingStrategy(strategy); } /*********************************************************************************/ // ?? /*********************************************************************************/ DEFAULT_VALUE.SERVER_VALUE.gameserverPort = server_config.getInt("gameserverPort", 8888); DEFAULT_VALUE.SERVER_VALUE.readTimeOut = server_config.getInt("readTimeOut"); DEFAULT_VALUE.SERVER_VALUE.writeTimeOut = server_config.getInt("writeTimeOut"); DEFAULT_VALUE.SERVER_VALUE.connect_timeout = server_config.getInt("connect_timeout"); DEFAULT_VALUE.SERVER_VALUE.maxConnection = server_config.getInt("maxConnection"); DEFAULT_VALUE.SERVER_VALUE.checkInterval = server_config.getInt("checkInterval"); //???? DEFAULT_VALUE.SERVER_VALUE.maxFrameLength = server_config.getInt("maxFrameLength", 1048576); DEFAULT_VALUE.SERVER_VALUE.lengthFieldOffset = server_config.getInt("lengthFieldOffset", 0); DEFAULT_VALUE.SERVER_VALUE.lengthFieldLength = server_config.getInt("lengthFieldLength", 2); DEFAULT_VALUE.SERVER_VALUE.lengthAdjustment = server_config.getInt("lengthAdjustment", 0); DEFAULT_VALUE.SERVER_VALUE.initialBytesToStrip = server_config.getInt("initialBytesToStrip", 2); DEFAULT_VALUE.SERVER_VALUE.useMultleThread = server_config.getBoolean("useMultleThread", false); //?? DEFAULT_VALUE.SERVER_VALUE.RoundIntervalTimerNum = server_config.getInt("RoundIntervalTimerNum"); DEFAULT_VALUE.SERVER_VALUE.RoundTimeOutTimerNum = server_config.getInt("RoundTimeOutTimerNum"); DEFAULT_VALUE.SERVER_VALUE.buffTimerNum = server_config.getInt("buffTimerNum"); DEFAULT_VALUE.SERVER_VALUE.calculateThreads = server_config.getInt("calculateThreads"); DEFAULT_VALUE.SERVER_VALUE.purgeTaskNum = server_config.getInt("purgeTaskNum"); DEFAULT_VALUE.SERVER_VALUE.AIthreadNum = server_config.getInt("AIthreadNum"); /*********************************************************************************/ /* ??? /*********************************************************************************/ DEFAULT_VALUE.GAME_VALUE.rulePoint = game_config.getBoolean("rulePoint", false); DEFAULT_VALUE.GAME_VALUE.DizzinessTimes = game_config.getInt("DizzinessTimes"); DEFAULT_VALUE.GAME_VALUE.roundOutCardIntervalTimeOut = game_config.getLong("roundOutCardIntervalTimeOut", 30000); DEFAULT_VALUE.GAME_VALUE.roundInterval = game_config.getLong("roundInterval"); /** -> -> -> 1,2,3,4 */ DEFAULT_VALUE.GAME_VALUE.soualProbability = game_config.getFloat("soualProbability"); DEFAULT_VALUE.GAME_VALUE.defenceProbability = game_config.getFloat("defenceProbability"); DEFAULT_VALUE.GAME_VALUE.attackProbability = game_config.getFloat("attackProbability"); DEFAULT_VALUE.GAME_VALUE.magicProbability = game_config.getFloat("magicProbability"); DEFAULT_VALUE.GAME_VALUE.cardBoxNum = game_config.getInt("cardBoxNum"); DEFAULT_VALUE.GAME_VALUE.cardNum = game_config.getInt("cardNum"); DEFAULT_VALUE.GAME_VALUE.PrograssPageSize = game_config.getInt("PrograssPageSize", 5); DEFAULT_VALUE.GAME_VALUE.MAX_ROUND = game_config.getInt("MAX_ROUND", 10); DEFAULT_VALUE.GAME_VALUE.useItemLog = game_config.getBoolean("useItemLog", true); DEFAULT_VALUE.GAME_VALUE.defenceRecoverySheild = game_config.getInt("defenceRecoverySheild"); DEFAULT_VALUE.GAME_VALUE.hurt = game_config.getInt("hurt"); DEFAULT_VALUE.GAME_VALUE.equipAndBooksAttrRandomRange = game_config .getDouble("equipAndBooksAttrRandomRange"); DEFAULT_VALUE.GAME_VALUE.PinJieModulus = game_config.getDouble("PinJieModulus"); DEFAULT_VALUE.GAME_VALUE.PinZhiModulus = game_config.getDouble("PinZhiModulus"); DEFAULT_VALUE.GAME_VALUE.minDizziness = game_config.getInt("minDizziness"); DEFAULT_VALUE.GAME_VALUE.maxDizziness = game_config.getInt("maxDizziness"); DEFAULT_VALUE.GAME_VALUE.minHurtSoul = game_config.getInt("minHurtSoul"); DEFAULT_VALUE.GAME_VALUE.maxHurtSoul = game_config.getInt("maxHurtSoul"); DEFAULT_VALUE.GAME_VALUE.minSpike = game_config.getInt("minSpike"); DEFAULT_VALUE.GAME_VALUE.maxSpike = game_config.getInt("maxSpike"); //? //?? //? //? //??? //?? //? DEFAULT_VALUE.GAME_VALUE.dizinnessCardNum = game_config.getInt("dizinnessCardNum"); DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjuryCardNum = game_config.getInt("InotherInjuryToInjuryCardNum"); DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjurySoulValue = game_config .getInt("InotherInjuryToInjurySoulValue"); DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjuryHurtPercent = game_config .getDouble("InotherInjuryToInjuryHurtPercent"); DEFAULT_VALUE.GAME_VALUE.InotherInjuryToInjuryReservedHurtPercent = game_config .getDouble("InotherInjuryToInjuryReservedHurtPercent"); DEFAULT_VALUE.GAME_VALUE.SpikeCardNum = game_config.getInt("SpikeCardNum"); DEFAULT_VALUE.GAME_VALUE.SpikeValue = game_config.getInt("SpikeValue"); DEFAULT_VALUE.GAME_VALUE.soulRecoveryInitial = game_config.getLong("soulRecoveryInitial"); DEFAULT_VALUE.GAME_VALUE.GongPercent = game_config.getDouble("GongPercent", 0.02); //? DEFAULT_VALUE.GAME_VALUE.spriteFullInitial = game_config.getLong("spriteFullInitial"); DEFAULT_VALUE.GAME_VALUE.getSpriteInitial = game_config.getLong("getSpriteInitial"); DEFAULT_VALUE.GAME_VALUE.ItemCellNum = game_config.getInt("ItemCellNum"); }
From source file:gda.util.persistence.LocalParameters.java
/** * @param configDir/*from w w w . ja v a 2s .c o m*/ * @param configName * @param createIfMissing * @param createAlways true if existing config in the cache is to be thrown away - re-reads the underlying file * @return XMLConfiguration * @throws ConfigurationException * @throws IOException */ public synchronized static XMLConfiguration getXMLConfiguration(String configDir, String configName, Boolean createIfMissing, boolean createAlways) throws ConfigurationException, IOException { // Instantiate the Configuration if it has not been instantiated if (configDir == null || configDir.isEmpty()) throw new IllegalArgumentException("configDir is null or empty"); if (!configDir.endsWith(File.separator)) configDir += File.separator; final String fullName = getFullName(configDir, configName); if (createAlways && configList.containsKey(fullName)) { configList.remove(fullName); } if (configList.containsKey(fullName) == false) { XMLConfiguration config; // Try to open the file try { config = loadConfigurationFromFile(fullName); } catch (ConfigurationException e) // catch (NoClassDefFoundError e) { // Assume the error occured because the file does not exist // Throw exception if createIfMissing is false if (createIfMissing == false) { logger.error("Could not load " + configDir + configName + ".xml which will not be created"); throw new ConfigurationException(e); } // else try to make it... try { File dir = new File(configDir); if (!dir.exists()) if (!dir.mkdirs()) { throw new FileNotFoundException("Couldn't create directory: " + dir); } File file = new File(fullName); PrintWriter out = new PrintWriter(new FileWriter(file)); out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"?>"); out.println("<" + configName + ">"); out.println("</" + configName + ">"); out.close(); } catch (IOException ee) { logger.error("Failed trying to create non-existent file " + fullName); throw new IOException(ee); } // ... and read it again try { config = loadConfigurationFromFile(fullName); } catch (ConfigurationException ee) { logger.error("Failed trying to read newly-created file " + fullName); throw new ConfigurationException(e); } logger.debug("Created configuration file: " + fullName); } // endif - create a missing file config.setReloadingStrategy(new FileChangedReloadingStrategy()); configList.put(fullName, config); logger.debug("Loaded the configuration file: " + fullName); } // endif - instantiate a new configuration // return the configuration object return configList.get(fullName); }
From source file:de.suse.swamp.core.workflow.WorkflowTemplate.java
/** * @param wfProps The wfProps to set./* w ww . j av a2 s . co m*/ */ public void setWfProps(File wfProps) throws Exception { config = new PropertiesConfiguration(wfProps); config.setReloadingStrategy(new FileChangedReloadingStrategy()); this.wfProps = new PropertiesConfiguration(wfProps); }
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 ww w .j av a 2 s . c o m*/ * <p> * <b>Note:</b> 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:ninja.i18n.MessagesImpl.java
/** * Attempts to load a message file and sets the file changed reloading * strategy on the configuration if the runtime mode is Dev. *//* ww w . j av a2 s. c om*/ private PropertiesConfiguration loadLanguageConfiguration(String fileOrUrl) { PropertiesConfiguration configuration = SwissKnife.loadConfigurationInUtf8(fileOrUrl); if (configuration != null && ninjaProperties.isDev()) { // enable runtime reloading of translations in dev mode FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); configuration.setReloadingStrategy(strategy); } return configuration; }
From source file:ninja.utils.NinjaPropertiesImpl.java
public NinjaPropertiesImpl(NinjaMode ninjaMode, String externalConfigurationPath) { this.ninjaMode = ninjaMode; // This is our main configuration. // In the following we'll read the individual configurations and merge // them into the composite configuration at the end. compositeConfiguration = new CompositeConfiguration(); // That is the default config. PropertiesConfiguration defaultConfiguration = null; // Config of prefixed mode corresponding to current mode (eg. // %test.myproperty=...) Configuration prefixedDefaultConfiguration = null; // (Optional) Config set via a system property PropertiesConfiguration externalConfiguration = null; // (Optional) Config of prefixed mode corresponding to current mode (eg. // %test.myproperty=...) Configuration prefixedExternalConfiguration = null; // First step => load application.conf and also merge properties that // correspond to a mode into the configuration. defaultConfiguration = SwissKnife.loadConfigurationInUtf8(NinjaProperties.CONF_FILE_LOCATION_BY_CONVENTION); if (defaultConfiguration != null) { // Second step: // Copy special prefix of mode to parent configuration // By convention it will be something like %test.myproperty prefixedDefaultConfiguration = defaultConfiguration.subset("%" + ninjaMode.name()); // allow application.conf to be reloaded on changes in dev mode if (NinjaMode.dev == ninjaMode) { defaultConfiguration.setReloadingStrategy(new FileChangedReloadingStrategy()); }//from w w w . j a v a 2s . c o m } else { // If the property was set, but the file not found we emit // a RuntimeException String errorMessage = String.format( "Error reading configuration file. Make sure you got a default config file %s", NinjaProperties.CONF_FILE_LOCATION_BY_CONVENTION); logger.error(errorMessage); throw new RuntimeException(errorMessage); } // third step => load external configuration when a system property is defined. String ninjaExternalConf = externalConfigurationPath; if (ninjaExternalConf == null) { // if not set fallback to system property ninjaExternalConf = System.getProperty(NINJA_EXTERNAL_CONF); } if (ninjaExternalConf != null) { // only load it when the property is defined. externalConfiguration = SwissKnife.loadConfigurationInUtf8(ninjaExternalConf); // this should not happen: if (externalConfiguration == null) { String errorMessage = String.format( "Ninja was told to use an external configuration%n" + " %s = %s %n." + "But the corresponding file cannot be found.%n" + " Make sure it is visible to this application and on the classpath.", NINJA_EXTERNAL_CONF, ninjaExternalConf); logger.error(errorMessage); throw new RuntimeException(errorMessage); } else { // allow the external configuration to be reloaded at // runtime based on detected file changes final boolean shouldReload = Boolean.getBoolean(NINJA_EXTERNAL_RELOAD); if (shouldReload) { externalConfiguration.setReloadingStrategy(new FileChangedReloadingStrategy()); } // Copy special prefix of mode to parent configuration // By convention it will be something like %test.myproperty prefixedExternalConfiguration = externalConfiguration.subset("%" + ninjaMode.name()); } } // ///////////////////////////////////////////////////////////////////// // Finally add the stuff to the composite configuration // Note: Configurations added earlier will overwrite configurations // added later. // ///////////////////////////////////////////////////////////////////// if (prefixedExternalConfiguration != null) { compositeConfiguration.addConfiguration(prefixedExternalConfiguration); } if (externalConfiguration != null) { compositeConfiguration.addConfiguration(externalConfiguration); } if (prefixedDefaultConfiguration != null) { compositeConfiguration.addConfiguration(prefixedDefaultConfiguration); } if (defaultConfiguration != null) { compositeConfiguration.addConfiguration(defaultConfiguration); } // ///////////////////////////////////////////////////////////////////// // Check that the secret is set or generate a new one if the property // does not exist // ///////////////////////////////////////////////////////////////////// NinjaPropertiesImplTool.checkThatApplicationSecretIsSet(isProd(), new File("").getAbsolutePath(), defaultConfiguration, compositeConfiguration); }
From source file:org.apache.accumulo.server.metrics.MetricsConfiguration.java
private void loadConfiguration() { // Check to see if ACCUMULO_HOME environment variable is set. String ACUHOME = getEnvironmentConfiguration().getString("ACCUMULO_CONF_DIR"); if (null != ACUHOME) { // Try to load the metrics properties file File mFile = new File(ACUHOME, metricsFileName); if (mFile.exists()) { if (log.isDebugEnabled()) log.debug("Loading config file: " + mFile.getAbsolutePath()); try { xConfig = new XMLConfiguration(mFile); xConfig.append(getEnvironmentConfiguration()); xConfig.addConfigurationListener(new MetricsConfigListener()); xConfig.setReloadingStrategy(new FileChangedReloadingStrategy()); // Start a background Thread that checks a property from the XMLConfiguration // every so often to force the FileChangedReloadingStrategy to fire. if (null == watcher || !watcher.isAlive()) { watcher = new MetricsConfigWatcher(); watcher.start();/* w w w. j av a 2 s . c o m*/ } notFound = false; alreadyWarned = false; } catch (ConfigurationException ce) { log.error("Error reading accumulo-metrics.xml file."); notFound = true; return; } } else { if (!alreadyWarned) log.warn("Unable to find metrics file: " + mFile.getAbsolutePath()); alreadyWarned = true; notFound = true; return; } } else { if (!alreadyWarned) log.warn( "ACCUMULO_CONF_DIR variable not found in environment. Metrics collection will be disabled."); alreadyWarned = true; notFound = true; return; } if (xConfig != null) { config = xConfig.interpolatedConfiguration(); // set the enabled boolean from the configuration enabled = config.getBoolean(enabledName); if (log.isDebugEnabled()) log.debug("Metrics collection enabled=" + enabled); } else { enabled = false; } }
From source file:org.apache.ambari.view.hive.persistence.PersistentConfiguration.java
/** * Constructor//from w ww . j a va 2s . co m * @param fileName path to data file * @throws ConfigurationException */ public PersistentConfiguration(String fileName) throws ConfigurationException { super(); File config = new File(fileName); setFile(config); this.setAutoSave(true); this.setReloadingStrategy(new FileChangedReloadingStrategy()); this.setDelimiterParsingDisabled(true); this.setListDelimiter((char) 0); if (config.exists()) { this.load(); } }