Java源码示例:org.apache.commons.configuration.event.ConfigurationListener
示例1
public DynamicRequestLimiter(DynamicDistributedLogConfiguration dynConf,
StatsLogger statsLogger,
Feature rateLimitDisabledFeature) {
final StatsLogger limiterStatsLogger = statsLogger.scope("dynamic");
this.dynConf = dynConf;
this.rateLimitDisabledFeature = rateLimitDisabledFeature;
this.listener = new ConfigurationListener() {
@Override
public void configurationChanged(ConfigurationEvent event) {
// Note that this method may be called several times if several config options
// are changed. The effect is harmless except that we create and discard more
// objects than we need to.
LOG.debug("Config changed callback invoked with event {} {} {} {}", new Object[] {
event.getPropertyName(), event.getPropertyValue(), event.getType(),
event.isBeforeUpdate()});
if (!event.isBeforeUpdate()) {
limiterStatsLogger.getCounter("config_changed").inc();
LOG.debug("Rebuilding limiter");
limiter = build();
}
}
};
LOG.debug("Registering config changed callback");
dynConf.addConfigurationListener(listener);
}
示例2
@Override
protected PropertyUtil initialValue() {
PropertyUtil p = new PropertyUtil(
System.getProperty("application.properties.file",
"resources/application.properties"));
p.setProperty("isfw.build.info", getBuildInfo());
p.setEncoding(p.getString(ApplicationProperties.LOCALE_CHAR_ENCODING.key, "UTF-8"));
p.setProperty("execution.start.ts", System.currentTimeMillis());
File prjDir = new File(".").getAbsoluteFile().getParentFile();
p.setProperty("project.path", prjDir.getAbsolutePath());
if(!p.containsKey("project.name"))
p.setProperty("project.name", prjDir.getName());
log.info("ISFW build info: " + p.getProperty("isfw.build.info"));
String[] resources = p.getStringArray("env.resources", "resources");
for (String resource : resources) {
addBundle(p, resource);
}
ConfigurationListener cl = new PropertyConfigurationListener();
p.addConfigurationListener(cl);
return p;
}
示例3
public DynamicRequestLimiter(DynamicDistributedLogConfiguration dynConf,
StatsLogger statsLogger, Feature rateLimitDisabledFeature) {
final StatsLogger limiterStatsLogger = statsLogger.scope("dynamic");
this.dynConf = dynConf;
this.rateLimitDisabledFeature = rateLimitDisabledFeature;
this.listener = new ConfigurationListener() {
@Override
public void configurationChanged(ConfigurationEvent event) {
// Note that this method may be called several times if several config options
// are changed. The effect is harmless except that we create and discard more
// objects than we need to.
LOG.debug("Config changed callback invoked with event {} {} {} {}", new Object[] {
event.getPropertyName(), event.getPropertyValue(), event.getType(),
event.isBeforeUpdate()});
if (!event.isBeforeUpdate()) {
limiterStatsLogger.getCounter("config_changed").inc();
LOG.debug("Rebuilding limiter");
limiter = build();
}
}
};
LOG.debug("Registering config changed callback");
dynConf.addConfigurationListener(listener);
}
示例4
@Override
protected PropertyUtil childValue(PropertyUtil parentValue) {
PropertyUtil cp = new PropertyUtil(parentValue);
ConfigurationListener cl = new PropertyConfigurationListener();
cp.addConfigurationListener(cl);
return cp;
}
示例5
private void addConfigurationListener() {
final MetricsCloudWatchConfiguration springConfig = this;
ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() {
@Override
public synchronized void configurationChanged(ConfigurationEvent event) {
if (!(event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY ||
event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY)) {
return;
}
if (event.isBeforeUpdate()) {
return;
}
String name = event.getPropertyName();
if (!(name.equals(METRICS_AWS_ENABLED) ||
name.equals(METRICS_AWS_FILTER) ||
name.equals(METRICS_AWS_PUBLISH_INTERVAL) ||
name.equals(METRICS_AWS_PUBLISH_INTERVAL_UNIT))) {
return;
}
springConfig.enabled = name.equals(METRICS_AWS_ENABLED) ? Boolean.parseBoolean(event.getPropertyValue() + "") : springConfig.enabled;
destroyReporter();
if (springConfig.enabled) {
createReporter();
}
}
});
}
示例6
private void addConfigurationListener() {
final MetricsGraphiteConfiguration springConfig = this;
ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() {
@Override
public synchronized void configurationChanged(ConfigurationEvent event) {
if (!(event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY ||
event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY)) {
return;
}
if (event.isBeforeUpdate()) {
return;
}
String name = event.getPropertyName();
if (!(name.equals(METRICS_GRAPHITE_ENABLED) ||
name.equals(METRICS_GRAPHITE_SERVER) ||
name.equals(METRICS_GRAPHITE_PORT) ||
name.equals(METRICS_GRAPHITE_FILTER) ||
name.equals(METRICS_GRAPHITE_PUBLISH_INTERVAL) ||
name.equals(METRICS_GRAPHITE_PUBLISH_INTERVAL_UNIT))) {
return;
}
springConfig.enabled = name.equals(METRICS_GRAPHITE_ENABLED) ? Boolean.parseBoolean(event.getPropertyValue() + "") : springConfig.enabled;
destroyReporterLoader();
if (springConfig.enabled) {
createReporterLoader();
}
}
});
}
示例7
private ArchaiusPropertyResolver() {
this.config = ConfigurationManager.getConfigInstance();
ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() {
@Override
public void configurationChanged(ConfigurationEvent event) {
if (!event.isBeforeUpdate()) {
actions.forEach(ArchaiusPropertyResolver::invokeAction);
}
}
});
}
示例8
@Test(timeout = 60000)
public void testExceptionInConfigLoad() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
writer.setProperty("prop1", "1");
writer.save();
DeterministicScheduler mockScheduler = new DeterministicScheduler();
FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
ConfigurationSubscription confSub =
new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
final AtomicInteger count = new AtomicInteger(1);
conf.addConfigurationListener(new ConfigurationListener() {
@Override
public void configurationChanged(ConfigurationEvent event) {
LOG.info("config changed {}", event);
// Throw after so we actually see the update anyway.
if (!event.isBeforeUpdate()) {
count.getAndIncrement();
throw new RuntimeException("config listener threw and exception");
}
}
});
int i = 0;
int initial = 0;
while (count.get() == initial) {
writer.setProperty("prop1", Integer.toString(i++));
writer.save();
mockScheduler.tick(100, TimeUnit.MILLISECONDS);
}
initial = count.get();
while (count.get() == initial) {
writer.setProperty("prop1", Integer.toString(i++));
writer.save();
mockScheduler.tick(100, TimeUnit.MILLISECONDS);
}
}
示例9
@Test(timeout = 60000)
public void testExceptionInConfigLoad() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
writer.setProperty("prop1", "1");
writer.save();
DeterministicScheduler mockScheduler = new DeterministicScheduler();
FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
ConfigurationSubscription confSub =
new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
final AtomicInteger count = new AtomicInteger(1);
conf.addConfigurationListener(new ConfigurationListener() {
@Override
public void configurationChanged(ConfigurationEvent event) {
LOG.info("config changed {}", event);
// Throw after so we actually see the update anyway.
if (!event.isBeforeUpdate()) {
count.getAndIncrement();
throw new RuntimeException("config listener threw and exception");
}
}
});
int i = 0;
int initial = 0;
while (count.get() == initial) {
writer.setProperty("prop1", Integer.toString(i++));
writer.save();
mockScheduler.tick(100, TimeUnit.MILLISECONDS);
}
initial = count.get();
while (count.get() == initial) {
writer.setProperty("prop1", Integer.toString(i++));
writer.save();
mockScheduler.tick(100, TimeUnit.MILLISECONDS);
}
}
示例10
@Override
public void addConfigurationListener(ConfigurationListener l) {
eventSource.addConfigurationListener(l);
}
示例11
@Override
public boolean removeConfigurationListener(ConfigurationListener l) {
return eventSource.removeConfigurationListener(l);
}
示例12
@Override
public Collection<ConfigurationListener> getConfigurationListeners() {
return eventSource.getConfigurationListeners();
}
示例13
public void setConfigurationListener( ConfigurationListener listener ){
this.listener = listener;
}