Esempio n. 1
0
 private Configuration(String configPath) {
   logger.info("init...");
   try {
     propConfig = new PropertiesConfiguration(configPath);
     FileChangedReloadingStrategy reloadStrategy = new FileChangedReloadingStrategy();
     reloadStrategy.setRefreshDelay(refreshDelay);
     propConfig.setReloadingStrategy(reloadStrategy);
   } catch (ConfigurationException e) {
     logger.error("系统配置文件不存在!", e);
   }
 }
  private Configuration _addFileProperties(
      String fileName, CompositeConfiguration loadedCompositeConfiguration)
      throws ConfigurationException {

    try {
      FileConfiguration newFileConfiguration = new PropertiesConfiguration(fileName);

      URL url = newFileConfiguration.getURL();

      if (_log.isDebugEnabled()) {
        _log.debug("Adding file " + url);
      }

      Long delay = _getReloadDelay(loadedCompositeConfiguration, newFileConfiguration);

      if (delay != null) {
        FileChangedReloadingStrategy fileChangedReloadingStrategy =
            new FileConfigurationChangedReloadingStrategy();

        if (_log.isDebugEnabled()) {
          _log.debug("File " + url + " will be reloaded every " + delay + " seconds");
        }

        long milliseconds = delay.longValue() * 1000;

        fileChangedReloadingStrategy.setRefreshDelay(milliseconds);

        newFileConfiguration.setReloadingStrategy(fileChangedReloadingStrategy);
      }

      _addIncludedPropertiesSources(newFileConfiguration, loadedCompositeConfiguration);

      return newFileConfiguration;
    } catch (org.apache.commons.configuration.ConfigurationException ce) {
      if (_log.isDebugEnabled()) {
        _log.debug("Configuration source " + fileName + " ignored");
      }

      return null;
    }
  }
  private ConfigManager() {
    try {
      String configPath = this.getClass().getResource(ConstDef.SYSTEM_CONFIG).getFile();
      // String configPath2 =
      // "/D:/Program%20Files/apache-tomcat-6.0.32/webapps/SkyFormOpt/WEB-INF/classes/config.properties";
      configPath = java.net.URLDecoder.decode(configPath, "utf-8");
      log.info("get sysconfig file : " + configPath);

      config = new CompositeConfiguration();
      FileConfiguration pconfig = new PropertiesConfiguration(configPath);
      config.addConfiguration(pconfig);
      // pconfig.setAutoSave(true);
      // reload strategy
      FileChangedReloadingStrategy reloadStrategy = new FileChangedReloadingStrategy();
      reloadStrategy.setRefreshDelay(3000);
      // for performance tunning , remove this line
      pconfig.setReloadingStrategy(reloadStrategy);

      log.info("initialize sysconfig config file OK");
    } catch (Exception e) {
      log.error("initialize sysconfig config file error...");
      e.printStackTrace();
    }
  }