Search in sources :

Example 71 with AbstractConfiguration

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);
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConfigurationRuntimeException(org.apache.commons.configuration.ConfigurationRuntimeException) Configuration(org.apache.commons.configuration.Configuration) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration)

Example 72 with AbstractConfiguration

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;
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration)

Example 73 with AbstractConfiguration

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;
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration)

Example 74 with AbstractConfiguration

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;
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Properties(java.util.Properties)

Example 75 with AbstractConfiguration

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");
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) BeforeClass(org.junit.BeforeClass)

Aggregations

AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)80 Test (org.junit.Test)29 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)18 BeforeClass (org.junit.BeforeClass)10 Configuration (org.apache.commons.configuration.Configuration)9 URI (java.net.URI)6 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)6 HttpRequest (com.netflix.client.http.HttpRequest)5 ArrayList (java.util.ArrayList)5 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)4 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)4 HttpResponse (com.netflix.client.http.HttpResponse)3 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 LinkedHashMap (java.util.LinkedHashMap)3 Properties (java.util.Properties)3 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)2 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2