public class ConcurrentCompositeConfiguration extends ConcurrentMapConfiguration implements AggregatedConfiguration, org.apache.commons.configuration.event.ConfigurationListener, Cloneable
getProperty(String)
will return any properties defined by Configuration1.
Only if Configuration1 doesn't have the property, then
Configuration2 will be checked.
There are two internal configurations for properties that are programmatically set:
addProperty(String, Object)
or setProperty(String, Object)
called directly on this class. This configuration will be called "container configuration" as it serves as the container of
such properties. By default, this configuration remains at the last of the configurations list. It can be treated as
a "base line" configuration that holds hard-coded parameters that can be overridden by any of other configurations added at runtime.
You can replace this configuration by your own and change the position of the configuration in the list by calling
setContainerConfiguration(AbstractConfiguration, String, int)
.
setOverrideProperty(String, Object)
) to override values from any other
configurations on the list. As contrast to container configuration, this configuration is always consulted first in
getProperty(String)
.
ConcurrentMapConfiguration
or ConcurrentCompositeConfiguration using
ConfigurationUtils
to achieve
maximal performance and thread safety.
Example:
// configuration from local properties file String fileName = "..."; ConcurrentMapConfiguration configFromPropertiesFile = new ConcurrentMapConfiguration(new PropertiesConfiguration(fileName)); // configuration from system properties ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration()); // configuration from a dynamic source PolledConfigurationSource source = createMyOwnSource(); AbstractPollingScheduler scheduler = createMyOwnScheduler(); DynamicConfiguration dynamicConfiguration = new DynamicConfiguration(source, scheduler); // create a hierarchy of configuration that makes // 1) dynamic configuration source override system properties and, // 2) system properties override properties file ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration(); finalConfig.add(dynamicConfiguration, "dynamicConfig"); finalConfig.add(configFromSystemProperties, "systemConfig"); finalConfig.add(configFromPropertiesFile, "fileConfig"); // register with DynamicPropertyFactory so that finalConfig // becomes the source of dynamic properties DynamicPropertyFactory.initWithConfigurationSource(finalConfig);
Modifier and Type | Field and Description |
---|---|
static int |
EVENT_CONFIGURATION_SOURCE_CHANGED |
map
Constructor and Description |
---|
ConcurrentCompositeConfiguration()
Creates an empty CompositeConfiguration object which can then
be added some other Configuration files
|
ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration)
Creates a ConcurrentCompositeConfiguration object with a specified container
configuration.
|
ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration,
Collection<? extends org.apache.commons.configuration.AbstractConfiguration> configurations)
Creates a ConcurrentCompositeConfiguration with a specified container
configuration, and then adds the given collection of configurations.
|
Modifier and Type | Method and Description |
---|---|
void |
addConfiguration(org.apache.commons.configuration.AbstractConfiguration config)
Add a child configuration without a name.
|
void |
addConfiguration(org.apache.commons.configuration.AbstractConfiguration config,
String name)
Adds a new child configuration to this configuration with an optional
name.
|
void |
addConfigurationAtFront(org.apache.commons.configuration.AbstractConfiguration config,
String name) |
void |
addConfigurationAtIndex(org.apache.commons.configuration.AbstractConfiguration config,
String name,
int index)
Add a configuration with a name at a particular index.
|
void |
addProperty(String key,
Object value)
Add the property with the container configuration.
|
void |
clear()
Removes all child configurations and reinitializes the container
configuration.
|
void |
clearOverrideProperty(String key)
Remove the overriding property set by
setOverrideProperty(String, Object) |
void |
clearProperty(String key)
Clear the property with the container configuration.
|
Object |
clone()
Returns a copy of this object.
|
void |
configurationChanged(org.apache.commons.configuration.event.ConfigurationEvent event)
Event listener call back for configuration update events.
|
boolean |
containsKey(String key)
Check if the any of the sub configurations contains the specified key.
|
org.apache.commons.configuration.Configuration |
getConfiguration(int index)
Return the configuration at the specified index.
|
org.apache.commons.configuration.Configuration |
getConfiguration(String name)
Returns the configuration with the given name.
|
List<String> |
getConfigurationNameList() |
Set<String> |
getConfigurationNames()
Returns a set with the names of all configurations contained in this
configuration.
|
List<org.apache.commons.configuration.AbstractConfiguration> |
getConfigurations()
Get the configurations added.
|
org.apache.commons.configuration.Configuration |
getContainerConfiguration()
Returns the container configuration In this configuration
changes are stored.
|
int |
getIndexOfConfiguration(org.apache.commons.configuration.AbstractConfiguration config) |
int |
getIndexOfContainerConfiguration() |
Iterator<String> |
getKeys()
Get all the keys contained by sub configurations.
|
Iterator<String> |
getKeys(String prefix)
Get the list of the keys contained in the sub configurations that match the
specified prefix.
|
List |
getList(String key,
List defaultValue)
Get a List of objects associated with the given configuration key.
|
int |
getNumberOfConfigurations()
Return the number of configurations.
|
Object |
getProperty(String key)
Read property from underlying composite.
|
org.apache.commons.configuration.Configuration |
getSource(String key)
Returns the configuration source, in which the specified key is defined.
|
String[] |
getStringArray(String key)
Get an array of strings associated with the given configuration key.
|
void |
invalidate() |
boolean |
isEmpty() |
boolean |
isPropagateEventFromSubConfigurations()
Return whether sub configurations should propagate events to
listeners to this configuration.
|
boolean |
removeConfiguration(org.apache.commons.configuration.Configuration config)
Remove a configuration.
|
org.apache.commons.configuration.Configuration |
removeConfiguration(String name)
Removes the configuration with the specified name.
|
org.apache.commons.configuration.AbstractConfiguration |
removeConfigurationAt(int index) |
void |
setContainerConfiguration(org.apache.commons.configuration.AbstractConfiguration config,
String name,
int index)
Adds a child configuration and makes it the container
configuration.
|
void |
setContainerConfigurationIndex(int newIndex)
Change the position of the container configuration to a new index.
|
void |
setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
Sets a flag whether added values for string properties should be checked
for the list delimiter.
|
void |
setListDelimiter(char listDelimiter)
Sets the character that is used as list delimiter.
|
void |
setOverrideProperty(String key,
Object finalValue)
Override the same property in any other configurations in the list.
|
void |
setPropagateEventFromSubConfigurations(boolean propagateEventToParent)
Set whether sub configurations should propagate events to
listeners to this configuration.
|
void |
setProperty(String key,
Object value)
Set the property with the container configuration.
|
addConfigurationListener, addErrorListener, addPropertyDirect, addPropertyImpl, clearConfigurationListeners, clearErrorListeners, clearPropertyDirect, copy, fireError, fireEvent, getConfigurationListeners, getErrorListeners, getProperties, loadProperties, removeConfigurationListener, removeErrorListener, setPropertyImpl
addErrorLogListener, append, createInterpolator, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getList, getListDelimiter, getLogger, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getSubstitutor, interpolate, interpolate, interpolatedConfiguration, interpolateHelper, isDelimiterParsingDisabled, isScalarValue, isThrowExceptionOnMissing, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setLogger, setThrowExceptionOnMissing, subset
createErrorEvent, createEvent, isDetailEvents, setDetailEvents
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getList, getLong, getLong, getLong, getProperties, getShort, getShort, getShort, getString, getString, subset
public static final int EVENT_CONFIGURATION_SOURCE_CHANGED
public ConcurrentCompositeConfiguration()
public ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration)
setProperty(String, Object)
and addProperty(String, Object)
.containerConfiguration
- the configuration to use as container configurationpublic ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration, Collection<? extends org.apache.commons.configuration.AbstractConfiguration> configurations)
containerConfiguration
- container configuration to useconfigurations
- the collection of configurations to addpublic void configurationChanged(org.apache.commons.configuration.event.ConfigurationEvent event)
configurationChanged
in interface org.apache.commons.configuration.event.ConfigurationListener
event
- the update eventpublic void invalidate()
public final void addConfiguration(org.apache.commons.configuration.AbstractConfiguration config)
addConfiguration(AbstractConfiguration, String)
with the name being null.addConfiguration
in interface AggregatedConfiguration
config
- the configuration to addpublic void addConfiguration(org.apache.commons.configuration.AbstractConfiguration config, String name)
addConfiguration
in interface AggregatedConfiguration
config
- the configuration to add (must not be null)name
- the name of this configuration (can be null)public List<org.apache.commons.configuration.AbstractConfiguration> getConfigurations()
getConfigurations
in interface AggregatedConfiguration
public List<String> getConfigurationNameList()
getConfigurationNameList
in interface AggregatedConfiguration
public int getIndexOfConfiguration(org.apache.commons.configuration.AbstractConfiguration config)
public int getIndexOfContainerConfiguration()
public void setContainerConfiguration(org.apache.commons.configuration.AbstractConfiguration config, String name, int index) throws IndexOutOfBoundsException
config
- the configuration to be addedname
- the name of the configuration to be addedindex
- index to add this configurationIndexOutOfBoundsException
public void setContainerConfigurationIndex(int newIndex) throws IndexOutOfBoundsException
IndexOutOfBoundsException
public void addConfigurationAtIndex(org.apache.commons.configuration.AbstractConfiguration config, String name, int index) throws IndexOutOfBoundsException
IndexOutOfBoundsException
public void addConfigurationAtFront(org.apache.commons.configuration.AbstractConfiguration config, String name)
public boolean removeConfiguration(org.apache.commons.configuration.Configuration config)
removeConfiguration
in interface AggregatedConfiguration
config
- The configuration to removepublic org.apache.commons.configuration.AbstractConfiguration removeConfigurationAt(int index)
removeConfigurationAt
in interface AggregatedConfiguration
public org.apache.commons.configuration.Configuration removeConfiguration(String name)
removeConfiguration
in interface AggregatedConfiguration
name
- the name of the configuration to be removedpublic int getNumberOfConfigurations()
getNumberOfConfigurations
in interface AggregatedConfiguration
public final void clear()
clear
in interface org.apache.commons.configuration.Configuration
clear
in class ConcurrentMapConfiguration
public void setOverrideProperty(String key, Object finalValue)
public void clearOverrideProperty(String key)
setOverrideProperty(String, Object)
public void setProperty(String key, Object value)
getProperty(String)
on this key may not return the same value set by this method
if there is any other configuration that contain the same property and is in front of the
container configuration in the configurations list.setProperty
in interface org.apache.commons.configuration.Configuration
setProperty
in class ConcurrentMapConfiguration
public void addProperty(String key, Object value)
getProperty(String)
on this key may not return the same value set by this method
if there is any other configuration that contain the same property and is in front of the
container configuration in the configurations list.addProperty
in interface org.apache.commons.configuration.Configuration
addProperty
in class ConcurrentMapConfiguration
public void clearProperty(String key)
getProperty(String)
on this key may still return some value
if there is any other configuration that contain the same property and is in front of the
container configuration in the configurations list.clearProperty
in interface org.apache.commons.configuration.Configuration
clearProperty
in class org.apache.commons.configuration.AbstractConfiguration
public Object getProperty(String key)
setOverrideProperty(String, Object)
and if so return the overriding value.
Otherwise, it iterates through the list of sub configurations until it finds one that contains the
property and return the value from that sub configuration. It returns null of the property does
not exist.getProperty
in interface org.apache.commons.configuration.Configuration
getProperty
in class ConcurrentMapConfiguration
key
- key to use for mappingpublic Iterator<String> getKeys()
getKeys
in interface org.apache.commons.configuration.Configuration
getKeys
in class ConcurrentMapConfiguration
public Iterator<String> getKeys(String prefix)
getKeys
in interface org.apache.commons.configuration.Configuration
getKeys
in class org.apache.commons.configuration.AbstractConfiguration
public Set<String> getConfigurationNames()
getConfigurationNames
in interface AggregatedConfiguration
public boolean isEmpty()
isEmpty
in interface org.apache.commons.configuration.Configuration
isEmpty
in class ConcurrentMapConfiguration
public boolean containsKey(String key)
containsKey
in interface org.apache.commons.configuration.Configuration
containsKey
in class ConcurrentMapConfiguration
key
- the key whose presence in this configuration is to be testedtrue
if the configuration contains a value for this
key, false
otherwisepublic List getList(String key, List defaultValue)
getList
in interface org.apache.commons.configuration.Configuration
getList
in class org.apache.commons.configuration.AbstractConfiguration
key
- The configuration key.defaultValue
- The default value.public String[] getStringArray(String key)
getStringArray
in interface org.apache.commons.configuration.Configuration
getStringArray
in class org.apache.commons.configuration.AbstractConfiguration
key
- The configuration key.public org.apache.commons.configuration.Configuration getConfiguration(int index)
getConfiguration
in interface AggregatedConfiguration
index
- The index of the configuration to retrievepublic org.apache.commons.configuration.Configuration getConfiguration(String name)
getConfiguration
in interface AggregatedConfiguration
name
- the name of the configurationpublic org.apache.commons.configuration.Configuration getContainerConfiguration()
public Object clone()
clone
in class org.apache.commons.configuration.event.EventSource
public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
setDelimiterParsingDisabled
in class org.apache.commons.configuration.AbstractConfiguration
delimiterParsingDisabled
- the new value of the flagpublic void setListDelimiter(char listDelimiter)
setListDelimiter
in class org.apache.commons.configuration.AbstractConfiguration
listDelimiter
- the new list delimiter characterpublic org.apache.commons.configuration.Configuration getSource(String key)
key
- the key to be checkedpublic final boolean isPropagateEventFromSubConfigurations()
public final void setPropagateEventFromSubConfigurations(boolean propagateEventToParent)
DynamicPropertyFactory
.propagateEventToParent
- value to setCopyright © 2020. All Rights Reserved.