List of usage examples for org.apache.commons.configuration.event ConfigurationListener configurationChanged
void configurationChanged(ConfigurationEvent event);
From source file:com.netflix.config.ConcurrentMapConfiguration.java
/** * Creates an event and calls {@link ConfigurationListener#configurationChanged(ConfigurationEvent)} * for all listeners while catching Throwable. *///from w w w . ja v a 2 s . c om @Override protected void fireEvent(int type, String propName, Object propValue, boolean beforeUpdate) { if (listeners == null || listeners.size() == 0) { return; } ConfigurationEvent event = createEvent(type, propName, propValue, beforeUpdate); for (ConfigurationListener l : listeners) { try { l.configurationChanged(event); } catch (ValidationException e) { if (beforeUpdate) { throw e; } else { logger.error("Unexpected exception", e); } } catch (Throwable e) { logger.error("Error firing configuration event", e); } } }
From source file:com.kixeye.chassis.support.logging.LoggingConfiguration.java
@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)); }/*from ww w . ja v a2 s . co m*/ 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)); }
From source file:nz.co.senanque.madura.configuration.MaduraConfiguration.java
private void invokeListeners() { if (m_configurationListeners != null) { try {//from ww w . j a v a 2 s . c om ConfigurationEvent event = new ConfigurationEvent(this, AbstractConfiguration.EVENT_SET_PROPERTY, null, this, false); for (ConfigurationListener listener : m_configurationListeners) { listener.configurationChanged(event); } } catch (Exception e) { throw new RuntimeException(e); } } }