public class ConcurrentMapConfiguration
extends 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 |
---|---|
static java.lang.String |
DISABLE_DELIMITER_PARSING
System property to disable delimiter parsing Apache Commons configurations
|
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object> |
map |
Constructor and Description |
---|
ConcurrentMapConfiguration()
Create an instance with an empty map.
|
ConcurrentMapConfiguration(Configuration config)
Create an instance by copying the properties from an existing Configuration.
|
ConcurrentMapConfiguration(java.util.Map<java.lang.String,java.lang.Object> mapToCopy) |
Modifier and Type | Method and Description |
---|---|
void |
addConfigurationListener(ConfigurationListener l) |
void |
addErrorListener(ConfigurationErrorListener l) |
void |
addProperty(java.lang.String key,
java.lang.Object value) |
protected void |
addPropertyDirect(java.lang.String key,
java.lang.Object value) |
protected void |
addPropertyImpl(java.lang.String key,
java.lang.Object value) |
void |
clear()
Clear the map and fire corresonding events.
|
void |
clearConfigurationListeners() |
void |
clearErrorListeners() |
protected void |
clearPropertyDirect(java.lang.String key) |
boolean |
containsKey(java.lang.String key) |
void |
copy(Configuration c)
Copy properties of a configuration into this configuration.
|
protected void |
fireError(int type,
java.lang.String propName,
java.lang.Object propValue,
java.lang.Throwable ex)
Creates an error event and calls
ConfigurationErrorListener#configurationError(ConfigurationErrorEvent)
for all listeners while catching Throwable. |
protected void |
fireEvent(int type,
java.lang.String propName,
java.lang.Object propValue,
boolean beforeUpdate)
Creates an event and calls
ConfigurationListener#configurationChanged(ConfigurationEvent)
for all listeners while catching Throwable. |
java.util.Collection<ConfigurationListener> |
getConfigurationListeners() |
java.util.Collection<ConfigurationErrorListener> |
getErrorListeners() |
java.util.Iterator |
getKeys() |
java.util.Properties |
getProperties()
Utility method to get a Properties object from this Configuration
|
java.lang.Object |
getProperty(java.lang.String key) |
boolean |
isEmpty() |
void |
loadProperties(java.util.Properties props)
Load properties into the configuration.
|
boolean |
removeConfigurationListener(ConfigurationListener l) |
boolean |
removeErrorListener(ConfigurationErrorListener l) |
void |
setProperty(java.lang.String key,
java.lang.Object value)
Override the same method in
AbstractConfiguration to simplify the logic
to avoid multiple events being generated. |
protected void |
setPropertyImpl(java.lang.String key,
java.lang.Object value) |
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object> map
public static final java.lang.String DISABLE_DELIMITER_PARSING
public ConcurrentMapConfiguration()
public ConcurrentMapConfiguration(java.util.Map<java.lang.String,java.lang.Object> mapToCopy)
public ConcurrentMapConfiguration(Configuration config)
config
- Configuration to be copiedpublic java.lang.Object getProperty(java.lang.String key)
protected void addPropertyDirect(java.lang.String key, java.lang.Object value)
public boolean isEmpty()
public boolean containsKey(java.lang.String key)
protected void clearPropertyDirect(java.lang.String key)
public java.util.Iterator getKeys()
public void addProperty(java.lang.String key, java.lang.Object value) throws ValidationException
ValidationException
protected void addPropertyImpl(java.lang.String key, java.lang.Object value)
public void setProperty(java.lang.String key, java.lang.Object value) throws ValidationException
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)
.ValidationException
protected void setPropertyImpl(java.lang.String key, java.lang.Object value)
public void loadProperties(java.util.Properties props)
setProperty(String, Object)
for
non-null key/value.public void copy(Configuration c)
setProperty(String, Object)
for non-null key/value.public void clear()
public java.util.Properties getProperties()
protected void fireEvent(int type, java.lang.String propName, java.lang.Object propValue, boolean beforeUpdate)
ConfigurationListener#configurationChanged(ConfigurationEvent)
for all listeners while catching Throwable.public void addConfigurationListener(ConfigurationListener l)
public void addErrorListener(ConfigurationErrorListener l)
public void clearConfigurationListeners()
public void clearErrorListeners()
public java.util.Collection<ConfigurationListener> getConfigurationListeners()
public java.util.Collection<ConfigurationErrorListener> getErrorListeners()
public boolean removeConfigurationListener(ConfigurationListener l)
public boolean removeErrorListener(ConfigurationErrorListener l)
protected void fireError(int type, java.lang.String propName, java.lang.Object propValue, java.lang.Throwable ex)
ConfigurationErrorListener#configurationError(ConfigurationErrorEvent)
for all listeners while catching Throwable.