|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.commons.configuration.event.EventSource
org.apache.commons.configuration.AbstractConfiguration
com.netflix.config.ConcurrentMapConfiguration
com.netflix.config.ConcurrentCompositeConfiguration
public class ConcurrentCompositeConfiguration
This class maintains a hierarchy of configurations in a list structure. The order of the list stands for the descending
priority of the configurations when a property value is to be determined.
For example, if you add Configuration1, and then Configuration2,
getProperty(String) will return any properties defined by Configuration1.
Only if Configuration1 doesn't have the property, then
Configuration2 will be checked.
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);
| Field Summary | |
|---|---|
static int |
EVENT_CONFIGURATION_SOURCE_CHANGED
|
| Fields inherited from class com.netflix.config.ConcurrentMapConfiguration |
|---|
map |
| Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
|---|
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN |
| Constructor Summary | |
|---|---|
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,
java.util.Collection<? extends org.apache.commons.configuration.AbstractConfiguration> configurations)
Creates a ConcurrentCompositeConfiguration with a specified container configuration, and then adds the given collection of configurations. |
|
| Method Summary | |
|---|---|
void |
addConfiguration(org.apache.commons.configuration.AbstractConfiguration config)
Add a child configuration without a name. |
void |
addConfiguration(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name)
Adds a new child configuration to this configuration with an optional name. |
void |
addConfigurationAtFront(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name)
|
void |
addConfigurationAtIndex(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name,
int index)
Add a configuration with a name at a particular index. |
void |
addProperty(java.lang.String key,
java.lang.Object value)
Add the property with the container configuration. |
void |
clear()
Removes all child configurations and reinitializes the container configuration. |
void |
clearOverrideProperty(java.lang.String key)
Remove the overriding property set by setOverrideProperty(String, Object) |
void |
clearProperty(java.lang.String key)
Clear the property with the container configuration. |
java.lang.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(java.lang.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(java.lang.String name)
Returns the configuration with the given name. |
java.util.List<java.lang.String> |
getConfigurationNameList()
|
java.util.Set<java.lang.String> |
getConfigurationNames()
Returns a set with the names of all configurations contained in this configuration. |
java.util.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()
|
java.util.Iterator<java.lang.String> |
getKeys()
Get all the keys contained by sub configurations. |
java.util.Iterator<java.lang.String> |
getKeys(java.lang.String prefix)
Get the list of the keys contained in the sub configurations that match the specified prefix. |
java.util.List |
getList(java.lang.String key,
java.util.List defaultValue)
Get a List of objects associated with the given configuration key. |
int |
getNumberOfConfigurations()
Return the number of configurations. |
java.lang.Object |
getProperty(java.lang.String key)
Read property from underlying composite. |
org.apache.commons.configuration.Configuration |
getSource(java.lang.String key)
Returns the configuration source, in which the specified key is defined. |
java.lang.String[] |
getStringArray(java.lang.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(java.lang.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,
java.lang.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(java.lang.String key,
java.lang.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(java.lang.String key,
java.lang.Object value)
Set the property with the container configuration. |
| Methods inherited from class com.netflix.config.ConcurrentMapConfiguration |
|---|
addConfigurationListener, addErrorListener, addPropertyDirect, addPropertyImpl, clearConfigurationListeners, clearErrorListeners, clearPropertyDirect, copy, fireError, fireEvent, getConfigurationListeners, getErrorListeners, getProperties, loadProperties, removeConfigurationListener, removeErrorListener, setPropertyImpl |
| Methods inherited from class org.apache.commons.configuration.AbstractConfiguration |
|---|
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 |
| Methods inherited from class org.apache.commons.configuration.event.EventSource |
|---|
createErrorEvent, createEvent, isDetailEvents, setDetailEvents |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.apache.commons.configuration.Configuration |
|---|
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 |
| Field Detail |
|---|
public static final int EVENT_CONFIGURATION_SOURCE_CHANGED
| Constructor Detail |
|---|
public ConcurrentCompositeConfiguration()
public ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration)
setProperty(String, Object)
and addProperty(String, Object).
containerConfiguration - the configuration to use as container configuration
public ConcurrentCompositeConfiguration(org.apache.commons.configuration.AbstractConfiguration containerConfiguration,
java.util.Collection<? extends org.apache.commons.configuration.AbstractConfiguration> configurations)
containerConfiguration - container configuration to useconfigurations - the collection of configurations to add| Method Detail |
|---|
public void configurationChanged(org.apache.commons.configuration.event.ConfigurationEvent event)
configurationChanged in interface org.apache.commons.configuration.event.ConfigurationListenerevent - 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 AggregatedConfigurationconfig - the configuration to add
public void addConfiguration(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name)
addConfiguration in interface AggregatedConfigurationconfig - the configuration to add (must not be null)name - the name of this configuration (can be null)public java.util.List<org.apache.commons.configuration.AbstractConfiguration> getConfigurations()
getConfigurations in interface AggregatedConfigurationpublic java.util.List<java.lang.String> getConfigurationNameList()
getConfigurationNameList in interface AggregatedConfigurationpublic int getIndexOfConfiguration(org.apache.commons.configuration.AbstractConfiguration config)
public int getIndexOfContainerConfiguration()
public void setContainerConfiguration(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name,
int index)
throws java.lang.IndexOutOfBoundsException
config - the configuration to be addedname - the name of the configuration to be addedindex - index to add this configuration
java.lang.IndexOutOfBoundsException
public void setContainerConfigurationIndex(int newIndex)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
public void addConfigurationAtIndex(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name,
int index)
throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
public void addConfigurationAtFront(org.apache.commons.configuration.AbstractConfiguration config,
java.lang.String name)
public boolean removeConfiguration(org.apache.commons.configuration.Configuration config)
removeConfiguration in interface AggregatedConfigurationconfig - The configuration to removepublic org.apache.commons.configuration.AbstractConfiguration removeConfigurationAt(int index)
removeConfigurationAt in interface AggregatedConfigurationpublic org.apache.commons.configuration.Configuration removeConfiguration(java.lang.String name)
removeConfiguration in interface AggregatedConfigurationname - the name of the configuration to be removed
public int getNumberOfConfigurations()
getNumberOfConfigurations in interface AggregatedConfigurationpublic final void clear()
clear in interface org.apache.commons.configuration.Configurationclear in class ConcurrentMapConfiguration
public void setOverrideProperty(java.lang.String key,
java.lang.Object finalValue)
public void clearOverrideProperty(java.lang.String key)
setOverrideProperty(String, Object)
public void setProperty(java.lang.String key,
java.lang.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.ConfigurationsetProperty in class ConcurrentMapConfiguration
public void addProperty(java.lang.String key,
java.lang.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.ConfigurationaddProperty in class ConcurrentMapConfigurationpublic void clearProperty(java.lang.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.ConfigurationclearProperty in class org.apache.commons.configuration.AbstractConfigurationpublic java.lang.Object getProperty(java.lang.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.ConfigurationgetProperty in class ConcurrentMapConfigurationkey - key to use for mapping
public java.util.Iterator<java.lang.String> getKeys()
getKeys in interface org.apache.commons.configuration.ConfigurationgetKeys in class ConcurrentMapConfigurationpublic java.util.Iterator<java.lang.String> getKeys(java.lang.String prefix)
getKeys in interface org.apache.commons.configuration.ConfigurationgetKeys in class org.apache.commons.configuration.AbstractConfigurationpublic java.util.Set<java.lang.String> getConfigurationNames()
getConfigurationNames in interface AggregatedConfigurationpublic boolean isEmpty()
isEmpty in interface org.apache.commons.configuration.ConfigurationisEmpty in class ConcurrentMapConfigurationpublic boolean containsKey(java.lang.String key)
containsKey in interface org.apache.commons.configuration.ConfigurationcontainsKey in class ConcurrentMapConfigurationkey - the key whose presence in this configuration is to be tested
true if the configuration contains a value for this
key, false otherwise
public java.util.List getList(java.lang.String key,
java.util.List defaultValue)
getList in interface org.apache.commons.configuration.ConfigurationgetList in class org.apache.commons.configuration.AbstractConfigurationkey - The configuration key.defaultValue - The default value.
public java.lang.String[] getStringArray(java.lang.String key)
getStringArray in interface org.apache.commons.configuration.ConfigurationgetStringArray in class org.apache.commons.configuration.AbstractConfigurationkey - The configuration key.
public org.apache.commons.configuration.Configuration getConfiguration(int index)
getConfiguration in interface AggregatedConfigurationindex - The index of the configuration to retrieve
public org.apache.commons.configuration.Configuration getConfiguration(java.lang.String name)
getConfiguration in interface AggregatedConfigurationname - the name of the configuration
public org.apache.commons.configuration.Configuration getContainerConfiguration()
public java.lang.Object clone()
clone in class org.apache.commons.configuration.event.EventSourcepublic void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
setDelimiterParsingDisabled in class org.apache.commons.configuration.AbstractConfigurationdelimiterParsingDisabled - the new value of the flagpublic void setListDelimiter(char listDelimiter)
setListDelimiter in class org.apache.commons.configuration.AbstractConfigurationlistDelimiter - the new list delimiter characterpublic org.apache.commons.configuration.Configuration getSource(java.lang.String key)
key - the key to be checked
public final boolean isPropagateEventFromSubConfigurations()
public final void setPropagateEventFromSubConfigurations(boolean propagateEventToParent)
DynamicPropertyFactory.
propagateEventToParent - value to set
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||