Search in sources :

Example 6 with ConfigurationEvent

use of org.apache.commons.configuration.event.ConfigurationEvent 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();
            }
        }
    });
}
Also used : ConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener) ConfigurationEvent(org.apache.commons.configuration.event.ConfigurationEvent)

Aggregations

ConfigurationEvent (org.apache.commons.configuration.event.ConfigurationEvent)6 ConfigurationListener (org.apache.commons.configuration.event.ConfigurationListener)5 Test (org.junit.Test)3 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 PostConstruct (javax.annotation.PostConstruct)1 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)1 DeterministicScheduler (org.jmock.lib.concurrent.DeterministicScheduler)1 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)1