Java源码示例:org.apache.commons.configuration.reloading.FileChangedReloadingStrategy
示例1
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();
}
示例2
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();
}
示例3
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();
}
}
示例4
private PlatformConfiguration(){
try {
config = new PropertiesConfiguration("platform.properties");
config.setReloadingStrategy(new FileChangedReloadingStrategy());
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
示例5
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);
}
}
示例6
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;
}
示例7
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();
}
示例8
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();
}
示例9
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;
}
示例10
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);
}
}
示例11
@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;
}