public class ConcurrentMapConfiguration
extends org.apache.commons.configuration.AbstractConfiguration
getProperty(String)
and setProperty(String, Object)
, but has some synchronization cost for
addProperty(String, Object)
if the object to add is not a String or the key already exists.
The methods from AbstractConfiguration related to listeners and event generation are overridden so that adding/deleting listeners and firing events are no longer synchronized. Also, it catches Throwable when it invokes the listeners, making it more robust.
This configuration does not allow null as key or value and will throw NullPointerException when trying to add or set properties with empty key or value.
Modifier and Type | Field and Description |
---|---|
protected ConcurrentHashMap<String,Object> |
map |
Constructor and Description |
---|
ConcurrentMapConfiguration()
Create an instance with an empty map.
|
ConcurrentMapConfiguration(org.apache.commons.configuration.Configuration config)
Create an instance by copying the properties from an existing Configuration.
|
ConcurrentMapConfiguration(Map<String,Object> mapToCopy) |
Modifier and Type | Method and Description |
---|---|
void |
addConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener l) |
void |
addErrorListener(org.apache.commons.configuration.event.ConfigurationErrorListener l) |
void |
addProperty(String key,
Object value) |
protected void |
addPropertyDirect(String key,
Object value) |
protected void |
addPropertyImpl(String key,
Object value) |
void |
clear()
Clear the map and fire corresonding events.
|
void |
clearConfigurationListeners() |
void |
clearErrorListeners() |
protected void |
clearPropertyDirect(String key) |
boolean |
containsKey(String key) |
void |
copy(org.apache.commons.configuration.Configuration c)
Copy properties of a configuration into this configuration.
|
protected void |
fireError(int type,
String propName,
Object propValue,
Throwable ex)
Creates an error event and calls
ConfigurationErrorListener.configurationError(ConfigurationErrorEvent)
for all listeners while catching Throwable. |
protected void |
fireEvent(int type,
String propName,
Object propValue,
boolean beforeUpdate)
Creates an event and calls
ConfigurationListener.configurationChanged(ConfigurationEvent)
for all listeners while catching Throwable. |
Collection<org.apache.commons.configuration.event.ConfigurationListener> |
getConfigurationListeners() |
Collection<org.apache.commons.configuration.event.ConfigurationErrorListener> |
getErrorListeners() |
Iterator |
getKeys() |
Properties |
getProperties()
Utility method to get a Properties object from this Configuration
|
Object |
getProperty(String key) |
boolean |
isEmpty() |
void |
loadProperties(Properties props)
Load properties into the configuration.
|
boolean |
removeConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener l) |
boolean |
removeErrorListener(org.apache.commons.configuration.event.ConfigurationErrorListener l) |
void |
setProperty(String key,
Object value)
Override the same method in
AbstractConfiguration to simplify the logic
to avoid multiple events being generated. |
protected void |
setPropertyImpl(String key,
Object value) |
addErrorLogListener, append, clearProperty, createInterpolator, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getList, getList, getListDelimiter, getLogger, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, getSubstitutor, interpolate, interpolate, interpolatedConfiguration, interpolateHelper, isDelimiterParsingDisabled, isScalarValue, isThrowExceptionOnMissing, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter, setLogger, setThrowExceptionOnMissing, subset
protected ConcurrentHashMap<String,Object> map
public ConcurrentMapConfiguration()
public ConcurrentMapConfiguration(org.apache.commons.configuration.Configuration config)
config
- Configuration to be copiedprotected void addPropertyDirect(String key, Object value)
addPropertyDirect
in class org.apache.commons.configuration.AbstractConfiguration
public boolean isEmpty()
public boolean containsKey(String key)
protected void clearPropertyDirect(String key)
clearPropertyDirect
in class org.apache.commons.configuration.AbstractConfiguration
public Iterator getKeys()
public void addProperty(String key, Object value)
addProperty
in interface org.apache.commons.configuration.Configuration
addProperty
in class org.apache.commons.configuration.AbstractConfiguration
public void setProperty(String key, Object value)
AbstractConfiguration
to simplify the logic
to avoid multiple events being generated. It calls clearPropertyDirect(String)
followed by logic to add the property including calling addPropertyDirect(String, Object)
.setProperty
in interface org.apache.commons.configuration.Configuration
setProperty
in class org.apache.commons.configuration.AbstractConfiguration
public void loadProperties(Properties props)
setProperty(String, Object)
for
non-null key/value.public void copy(org.apache.commons.configuration.Configuration c)
setProperty(String, Object)
for non-null key/value.copy
in class org.apache.commons.configuration.AbstractConfiguration
public void clear()
clear
in interface org.apache.commons.configuration.Configuration
clear
in class org.apache.commons.configuration.AbstractConfiguration
public Properties getProperties()
protected void fireEvent(int type, String propName, Object propValue, boolean beforeUpdate)
ConfigurationListener.configurationChanged(ConfigurationEvent)
for all listeners while catching Throwable.fireEvent
in class org.apache.commons.configuration.event.EventSource
public void addConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener l)
addConfigurationListener
in class org.apache.commons.configuration.event.EventSource
public void addErrorListener(org.apache.commons.configuration.event.ConfigurationErrorListener l)
addErrorListener
in class org.apache.commons.configuration.event.EventSource
public void clearConfigurationListeners()
clearConfigurationListeners
in class org.apache.commons.configuration.event.EventSource
public void clearErrorListeners()
clearErrorListeners
in class org.apache.commons.configuration.event.EventSource
public Collection<org.apache.commons.configuration.event.ConfigurationListener> getConfigurationListeners()
getConfigurationListeners
in class org.apache.commons.configuration.event.EventSource
public Collection<org.apache.commons.configuration.event.ConfigurationErrorListener> getErrorListeners()
getErrorListeners
in class org.apache.commons.configuration.event.EventSource
public boolean removeConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener l)
removeConfigurationListener
in class org.apache.commons.configuration.event.EventSource
public boolean removeErrorListener(org.apache.commons.configuration.event.ConfigurationErrorListener l)
removeErrorListener
in class org.apache.commons.configuration.event.EventSource
protected void fireError(int type, String propName, Object propValue, Throwable ex)
ConfigurationErrorListener.configurationError(ConfigurationErrorEvent)
for all listeners while catching Throwable.fireError
in class org.apache.commons.configuration.event.EventSource
Copyright © 2015. All Rights Reserved.