use of org.apache.commons.configuration.event.ConfigurationEvent in project chassis by Kixeye.
the class MetricsGraphiteConfiguration method addConfigurationListener.
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();
}
}
});
}
use of org.apache.commons.configuration.event.ConfigurationEvent in project chassis by Kixeye.
the class LoggingConfiguration method initialize.
@PostConstruct
public void initialize() {
AbstractConfiguration config = ConfigurationManager.getConfigInstance();
if (config.containsKey(LOGBACK_CONFIG_NAME)) {
System.out.println("Loading logging config.");
reloadLogging(config.getString(LOGBACK_CONFIG_NAME));
}
config.addConfigurationListener(new ConfigurationListener() {
@Override
public synchronized void configurationChanged(ConfigurationEvent event) {
if ((event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY || event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY) && StringUtils.equalsIgnoreCase(LOGBACK_CONFIG_NAME, event.getPropertyName()) && event.getPropertyValue() != null && !event.isBeforeUpdate()) {
System.out.println("Reloading logging config.");
reloadLogging((String) event.getPropertyValue());
}
}
});
ConfigurationListener flumeConfigListener = new ConfigurationListener() {
private FlumeLoggerLoader loggerLoader = null;
public synchronized void configurationChanged(ConfigurationEvent event) {
if (!(event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY || event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY || event.getType() == AbstractConfiguration.EVENT_CLEAR_PROPERTY)) {
return;
}
if (FlumeLoggerLoader.FLUME_LOGGER_ENABLED_PROPERTY.equals(event.getPropertyName())) {
if ("true".equals(event.getPropertyValue())) {
if (loggerLoader == null) {
// construct the bean
loggerLoader = (FlumeLoggerLoader) applicationContext.getBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, "chassis");
}
// else we already have one so we're cool
} else {
if (loggerLoader != null) {
// delete the bean
ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) applicationContext.getParentBeanFactory();
beanFactory.destroyBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, loggerLoader);
loggerLoader = null;
}
// else we don't have any so we're cool
}
} else if (FlumeLoggerLoader.RELOAD_PROPERTIES.contains(event.getPropertyValue())) {
// only reload if we're already running - otherwise ignore
if (loggerLoader != null) {
// delete the bean
ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) applicationContext.getParentBeanFactory();
beanFactory.destroyBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, loggerLoader);
loggerLoader = null;
// construct the bean
loggerLoader = (FlumeLoggerLoader) applicationContext.getBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, "chassis");
}
// else we don't have any so we're cool
}
}
};
config.addConfigurationListener(flumeConfigListener);
flumeConfigListener.configurationChanged(new ConfigurationEvent(this, AbstractConfiguration.EVENT_SET_PROPERTY, FlumeLoggerLoader.FLUME_LOGGER_ENABLED_PROPERTY, config.getProperty(FlumeLoggerLoader.FLUME_LOGGER_ENABLED_PROPERTY), false));
}
use of org.apache.commons.configuration.event.ConfigurationEvent 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.ConfigurationEvent in project archaius by Netflix.
the class ListenerTest method testEventsTriggered.
@Test
public void testEventsTriggered() {
config1.addProperty("abc", "foo");
ConfigurationEvent event = listener.getLastEvent(true);
assertTrue(event.isBeforeUpdate());
assertEquals("foo", event.getPropertyValue());
event = listener.getLastEvent(false);
assertFalse(event.isBeforeUpdate());
assertEquals("foo", event.getPropertyValue());
}
use of org.apache.commons.configuration.event.ConfigurationEvent in project bookkeeper by apache.
the class TestConfigurationSubscription method testExceptionInConfigLoad.
@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);
}
}
Aggregations