List of usage examples for org.apache.commons.configuration.event ConfigurationErrorListener ConfigurationErrorListener
ConfigurationErrorListener
From source file:eu.scape_project.planning.utils.ConfigurationLoader.java
/** * Loads the configuration with the provided name. * /*ww w. java2 s . co m*/ * @param name * the configuration name * @param ignoreBuffer * true to ignore the internal buffer, false otherwise * @return the configuration */ public Configuration load(String name, boolean ignoreBuffer) { CombinedConfiguration config = null; if (!ignoreBuffer) { config = buffer.get(name); if (config != null) { return config; } } try { DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(name); builder.clearErrorListeners(); builder.addErrorListener(new ConfigurationErrorListener() { @Override public void configurationError(ConfigurationErrorEvent event) { if (event.getType() == DefaultConfigurationBuilder.EVENT_ERR_LOAD_OPTIONAL) { LOG.debug("Could not load optional configuration file {}", event.getPropertyName(), event.getCause()); } else { LOG.warn("Configuration error on {}", event.getPropertyName(), event.getCause()); } } }); config = builder.getConfiguration(true); buffer.put(name, config); } catch (ConfigurationException e) { LOG.error("Cannot load configuration {}", e, name); } return config; }
From source file:org.finra.herd.dao.ReloadablePropertySource.java
/** * Constructs the object with all parameters specified. * * @param name the name of the property source. * @param source the properties.//from ww w. j a va2 s . c o m * @param configuration the configuration that knows how to read properties. * @param refreshIntervalSecs the refresh interval in seconds to wait before refreshing the properties when a property is requested. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public ReloadablePropertySource(String name, Properties source, Configuration configuration, long refreshIntervalSecs) { super(name, (Map) source); this.configuration = configuration; /* * Catches any errors and records it in the lastConfigurationErrorEvent variable. * It is safe to assume that all configurations are an instance of EventSource. * All concrete implementations of Configuration are an extension of AbstractConfiguration, which is an extension of EventSource. */ ((EventSource) configuration).addErrorListener(new ConfigurationErrorListener() { @Override public void configurationError(ConfigurationErrorEvent event) { lastConfigurationErrorEvent = event; } }); this.refreshIntervalMillis = refreshIntervalSecs * MILLISECONDS_IN_A_SECOND; updateLastRefreshTime(); updateRefreshInterval(); LOGGER.info("A refresh interval has been configured. propertiesRefreshIntervalInSeconds={}", refreshIntervalSecs); }