use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class ConcurrentCompositeConfiguration method clone.
/**
* Returns a copy of this object. This implementation will create a deep
* clone, i.e. all configurations contained in this composite will also be
* cloned. This only works if all contained configurations support cloning;
* otherwise a runtime exception will be thrown. Registered event handlers
* won't get cloned.
*/
@Override
public Object clone() {
try {
ConcurrentCompositeConfiguration copy = (ConcurrentCompositeConfiguration) super.clone();
copy.clearConfigurationListeners();
copy.configList = new LinkedList<AbstractConfiguration>();
copy.containerConfiguration = (AbstractConfiguration) ConfigurationUtils.cloneConfiguration(getContainerConfiguration());
copy.configList.add(copy.containerConfiguration);
for (Configuration config : configList) {
if (config != getContainerConfiguration()) {
copy.addConfiguration((AbstractConfiguration) ConfigurationUtils.cloneConfiguration(config));
}
}
return copy;
} catch (CloneNotSupportedException cnex) {
// cannot happen
throw new ConfigurationRuntimeException(cnex);
}
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class DynamicPropertyFactory method initWithConfigurationSource.
/**
* Initialize the factory with a {@link DynamicPropertySupport}.
* <p/>
* The initialization will register a {@link PropertyListener} with the DynamicPropertySupport so that DynamicProperty
* will receives a callback and refresh its value when a property is changed.
* <p/>
* If the factory is already initialized with a default configuration source (see {@link #getInstance()}), it will re-register
* itself with the new configuration source passed to this method. Otherwise, this method will throw IllegalArgumentException
* if it has been initialized with a non-default configuration source. This method should be only called once.
*
* @param dynamicPropertySupport DynamicPropertySupport to be associated with the DynamicProperty
* @return the instance of DynamicPropertyFactory
* @throws IllegalArgumentException if the factory has already been initialized with a different and non-default configuration source
*/
public static DynamicPropertyFactory initWithConfigurationSource(DynamicPropertySupport dynamicPropertySupport) {
synchronized (ConfigurationManager.class) {
if (dynamicPropertySupport == null) {
throw new IllegalArgumentException("dynamicPropertySupport is null");
}
AbstractConfiguration configuration = null;
if (dynamicPropertySupport instanceof AbstractConfiguration) {
configuration = (AbstractConfiguration) dynamicPropertySupport;
} else if (dynamicPropertySupport instanceof ConfigurationBackedDynamicPropertySupportImpl) {
configuration = ((ConfigurationBackedDynamicPropertySupportImpl) dynamicPropertySupport).getConfiguration();
}
if (initializedWithDefaultConfig) {
config = null;
} else if (config != null && config != dynamicPropertySupport) {
throw new IllegalStateException("DynamicPropertyFactory is already initialized with a diffrerent configuration source: " + config);
}
if (ConfigurationManager.isConfigurationInstalled() && (configuration != null && configuration != ConfigurationManager.instance)) {
throw new IllegalStateException("ConfigurationManager is already initialized with configuration " + ConfigurationManager.getConfigInstance());
}
if (configuration != null && configuration != ConfigurationManager.instance) {
ConfigurationManager.setDirect(configuration);
}
setDirect(dynamicPropertySupport);
return instance;
}
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class DynamicPropertyFactory method getInstance.
/**
* Get the instance to create dynamic properties. If the factory is not initialized with a configuration source
* (see {@link #initWithConfigurationSource(AbstractConfiguration)} and {@link #initWithConfigurationSource(DynamicPropertySupport)}),
* it will fist try to initialize itself with a default {@link ConcurrentCompositeConfiguration}, with the following two
* sub configurations:
* <ul>
* <li>A SystemConfiguration, which contains all the system properties. You can disable adding this Configuration by setting
* system property {@value #DISABLE_DEFAULT_SYS_CONFIG} to <code>true</code>
* <li>A {@link DynamicURLConfiguration}, which at a fixed interval polls
* a configuration file (see {@link URLConfigurationSource#DEFAULT_CONFIG_FILE_NAME}) on classpath and a set of URLs specified via a system property
* (see {@link URLConfigurationSource#CONFIG_URL}).
* </ul>
* Between the two sub-configurations, the SystemConfiguration will take the precedence when determining property values.
* <p/>
* You can disable the initialization with the default configuration by setting system property {@value #DISABLE_DEFAULT_CONFIG} to "true".
*/
public static DynamicPropertyFactory getInstance() {
if (config == null) {
synchronized (ConfigurationManager.class) {
if (config == null) {
AbstractConfiguration configFromManager = ConfigurationManager.getConfigInstance();
if (configFromManager != null) {
initWithConfigurationSource(configFromManager);
initializedWithDefaultConfig = !ConfigurationManager.isConfigurationInstalled();
logger.info("DynamicPropertyFactory is initialized with configuration sources: " + configFromManager);
}
}
}
}
return instance;
}
use of org.apache.commons.configuration.AbstractConfiguration in project java-chassis by ServiceComb.
the class ConfigurationSpringInitializer method mergeProperties.
@Override
protected Properties mergeProperties() throws IOException {
Properties properties = super.mergeProperties();
if (isExternalInit()) {
return properties;
}
AbstractConfiguration config = ConfigurationManager.getConfigInstance();
Iterator<String> iterator = config.getKeys();
while (iterator.hasNext()) {
String key = iterator.next();
Object value = config.getProperty(key);
properties.put(key, value);
}
return properties;
}
use of org.apache.commons.configuration.AbstractConfiguration in project java-chassis by ServiceComb.
the class TestInstancePropertyDiscoveryFilter method beforeCls.
@BeforeClass
public static void beforeCls() {
AbstractConfiguration configuration = new BaseConfiguration();
configuration.addProperty("servicecomb.loadbalance.test.flowsplitFilter.policy", "org.apache.servicecomb.loadbalance.filter.SimpleFlowsplitFilter");
configuration.addProperty("servicecomb.loadbalance.test.flowsplitFilter.options.tag0", "value0");
}
Aggregations