use of org.apache.commons.configuration.event.ConfigurationListener in project archaius by Netflix.
the class ConcurrentMapConfigurationTest method testListeners.
@Test
public void testListeners() {
ConcurrentMapConfiguration conf = new ConcurrentMapConfiguration();
final AtomicReference<ConfigurationEvent> eventRef = new AtomicReference<ConfigurationEvent>();
conf.addConfigurationListener(new ConfigurationListener() {
@Override
public void configurationChanged(ConfigurationEvent arg0) {
eventRef.set(arg0);
}
});
conf.addProperty("key", "1");
assertEquals(1, conf.getInt("key"));
ConfigurationEvent event = eventRef.get();
assertEquals("key", event.getPropertyName());
assertEquals("1", event.getPropertyValue());
assertTrue(conf == event.getSource());
assertEquals(AbstractConfiguration.EVENT_ADD_PROPERTY, event.getType());
conf.setProperty("key", "2");
event = eventRef.get();
assertEquals("key", event.getPropertyName());
assertEquals("2", event.getPropertyValue());
assertTrue(conf == event.getSource());
assertEquals(AbstractConfiguration.EVENT_SET_PROPERTY, event.getType());
conf.clearProperty("key");
event = eventRef.get();
assertEquals("key", event.getPropertyName());
assertNull(event.getPropertyValue());
assertTrue(conf == event.getSource());
assertEquals(AbstractConfiguration.EVENT_CLEAR_PROPERTY, event.getType());
conf.clear();
assertFalse(conf.getKeys().hasNext());
event = eventRef.get();
assertTrue(conf == event.getSource());
assertEquals(AbstractConfiguration.EVENT_CLEAR, event.getType());
}
use of org.apache.commons.configuration.event.ConfigurationListener in project chassis by Kixeye.
the class MetricsCloudWatchConfiguration method addConfigurationListener.
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();
}
}
});
}
Aggregations