org.apache.commons.configuration.reloading.FileChangedReloadingStrategy Java Examples

The following examples show how to use org.apache.commons.configuration.reloading.FileChangedReloadingStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurationSubscription.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private boolean initConfig() {
    if (fileConfigs.isEmpty()) {
        try {
            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();
}
 
Example #2
Source File: ConfigManagerUtil.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
private ConfigManagerUtil(String configFileName) {
    try {
        this.config = null;
        if (configFileName.toLowerCase().endsWith("xml")) {
            this.config = new XMLConfiguration(configFileName);
        } else if (configFileName.toLowerCase().endsWith("properties")) {
            this.config = new PropertiesConfiguration(configFileName);
        }
        this.config.setReloadingStrategy(new FileChangedReloadingStrategy());
        hashMap.put(configFileName, this);
    } catch (Exception e) {
    	e.printStackTrace();
    }
}
 
Example #3
Source File: PlatformConfiguration.java    From dpCms with Apache License 2.0 5 votes vote down vote up
private PlatformConfiguration(){
	try {
		config = new PropertiesConfiguration("platform.properties");
		config.setReloadingStrategy(new FileChangedReloadingStrategy());			
	} catch (ConfigurationException e) {
		e.printStackTrace();
	}  
}
 
Example #4
Source File: ConfigurationSubscription.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
private boolean initConfig() {
    if (fileConfigs.isEmpty()) {
        try {
            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();
}
 
Example #5
Source File: SerialKiller.java    From SerialKiller with Apache License 2.0 5 votes vote down vote up
Configuration(final String configPath) {
    try {
        config = new XMLConfiguration(configPath);

        FileChangedReloadingStrategy reloadStrategy = new FileChangedReloadingStrategy();
        reloadStrategy.setRefreshDelay(config.getLong("refresh", 6000));
        config.setReloadingStrategy(reloadStrategy);
        config.addConfigurationListener(event -> init(config));

        init(config);
    } catch (ConfigurationException | PatternSyntaxException e) {
        throw new IllegalStateException("SerialKiller not properly configured: " + e.getMessage(), e);
    }
}
 
Example #6
Source File: MessageResources.java    From unitime with Apache License 2.0 5 votes vote down vote up
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);
		
		// 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;
}
 
Example #7
Source File: TajoSystemMetrics.java    From tajo with Apache License 2.0 5 votes vote down vote up
public TajoSystemMetrics(TajoConf tajoConf, Class clazz, String hostAndPort) {
  super(MetricsUtil.getGroupName(clazz));

  this.hostAndPort = hostAndPort;
  try {
    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();
}
 
Example #8
Source File: TajoSystemMetrics.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
public TajoSystemMetrics(TajoConf tajoConf, String metricsGroupName, String hostAndPort) {
  super(metricsGroupName);

  this.hostAndPort = hostAndPort;
  try {
    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();
}
 
Example #9
Source File: PropertiesConfigurationProperties.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: ReloadablePropertySource.java    From tutorials with MIT License 5 votes vote down vote up
public ReloadablePropertySource(String name, String path) {
    super(StringUtils.isEmpty(name) ? path : name);
    try {
        this.propertiesConfiguration = new PropertiesConfiguration(path);
        FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
        strategy.setRefreshDelay(1000);
        this.propertiesConfiguration.setReloadingStrategy(strategy);
    } catch (Exception e) {
        throw new PropertiesException(e);
    }
}
 
Example #11
Source File: SpringBootPropertiesApplication.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnProperty(name = "spring.config.location", matchIfMissing = false)
public PropertiesConfiguration propertiesConfiguration(
  @Value("${spring.config.location}") String path,
  @Value("${spring.properties.refreshDelay}") long refreshDelay) throws Exception {
    String filePath = path.substring("file:".length());
    PropertiesConfiguration configuration = new PropertiesConfiguration(new File(filePath).getCanonicalPath());
    FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
    fileChangedReloadingStrategy.setRefreshDelay(refreshDelay);
    configuration.setReloadingStrategy(fileChangedReloadingStrategy);
    return configuration;
}