Search in sources :

Example 1 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration in project archaius by Netflix.

the class SampleApplicationWithDefaultConfiguration method main.

public static void main(String[] args) {
    new SampleApplication();
    ConcurrentCompositeConfiguration myConfiguration = (ConcurrentCompositeConfiguration) DynamicPropertyFactory.getInstance().getBackingConfigurationSource();
    ConcurrentMapConfiguration subConfig = new ConcurrentMapConfiguration();
    subConfig.setProperty("com.netflix.config.samples.SampleApp.SampleBean.name", "A Coffee Bean from Cuba");
    myConfiguration.setProperty("com.netflix.config.samples.sampleapp.prop1", "value1");
    myConfiguration.addConfiguration(subConfig);
    System.out.println("Started SampleApplication. Launch JConsole to inspect and update properties.");
    System.out.println("To see how callback work, update property com.netflix.config.samples.SampleApp.SampleBean.sensitiveBeanData from BaseConfigBean in JConsole");
    SampleBean sampleBean = new SampleBean();
    // this should show the bean taking properties from two different sources
    // property "com.netflix.config.samples.SampleApp.SampleBean.numSeeds" is from sampleapp.properites
    // property "com.netflix.config.samples.SampleApp.SampleBean.name" is from subConfig added above 
    System.out.println("SampleBean:" + sampleBean);
    System.out.println(sampleBean.getName());
}
Also used : ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 2 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration in project archaius by Netflix.

the class OverridingPropertiesConfiguration method convertToConcurrentCompositeConfiguration.

/**
     * Convert CombinedConfiguration into {@link ConcurrentCompositeConfiguration} as the later has better performance
     * and thread safety. 
     * 
     * @param config Configuration to be converted
     */
public static ConcurrentCompositeConfiguration convertToConcurrentCompositeConfiguration(CombinedConfiguration config) {
    ConcurrentCompositeConfiguration root = new ConcurrentCompositeConfiguration();
    IdentityHashMap<Configuration, String> reverseMap = new IdentityHashMap<Configuration, String>();
    for (String name : (Set<String>) config.getConfigurationNames()) {
        Configuration child = config.getConfiguration(name);
        reverseMap.put(child, name);
    }
    for (int i = 0; i < config.getNumberOfConfigurations(); i++) {
        Configuration child = config.getConfiguration(i);
        String name = reverseMap.get(child);
        if (child instanceof CombinedConfiguration) {
            CombinedConfiguration combinedConf = (CombinedConfiguration) child;
            ConcurrentCompositeConfiguration newConf = convertToConcurrentCompositeConfiguration(combinedConf);
            root.addConfiguration(newConf, name);
        } else {
            Configuration conf = new ConcurrentMapConfiguration(child);
            root.addConfiguration((AbstractConfiguration) conf, name);
        }
    }
    return root;
}
Also used : Set(java.util.Set) Configuration(org.apache.commons.configuration.Configuration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) IdentityHashMap(java.util.IdentityHashMap) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 3 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration in project archaius by Netflix.

the class OverridingPropertiesConfiguration method getNextLoad.

private static String getNextLoad(Configuration propConfig, String... nextLoadPropertyKeys) {
    String nextLoadKeyToUse = null;
    for (String key : nextLoadPropertyKeys) {
        if (propConfig.getProperty(key) != null) {
            nextLoadKeyToUse = key;
            break;
        }
    }
    // there is no next load for this properties file
    if (nextLoadKeyToUse == null) {
        return null;
    }
    // make a copy of current existing properties
    ConcurrentMapConfiguration config = new ConcurrentMapConfiguration();
    // need to have all the properties to interpolate next load property value
    copyProperties(ConfigurationManager.getConfigInstance(), config);
    copyProperties(propConfig, config);
    // In case this is a list of files to load, always treat the value as a list
    List<Object> list = config.getList(nextLoadKeyToUse);
    StringBuilder sb = new StringBuilder();
    for (Object value : list) {
        sb.append(value).append(",");
    }
    String nextLoad = sb.toString();
    propConfig.clearProperty(nextLoadKeyToUse);
    return nextLoad;
}
Also used : ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration)

Example 4 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration in project archaius by Netflix.

the class SampleBean method main.

/**
	 * SampleApplication entrypoint
	 * @param args
	 */
public static void main(String[] args) {
    //@SuppressWarnings(value = {"unused" })
    new SampleApplication();
    // Step 1.
    // Create a Source of Configuration
    // Here we use a simple ConcurrentMapConfiguration
    // You can use your own, or use of the pre built ones including JDBCConfigurationSource
    // which lets you load properties from any RDBMS
    AbstractConfiguration myConfiguration = new ConcurrentMapConfiguration();
    myConfiguration.setProperty("com.netflix.config.samples.sampleapp.prop1", "value1");
    myConfiguration.setProperty("com.netflix.config.samples.SampleApp.SampleBean.name", "A Coffee Bean from Gautemala");
    // STEP 2: Optional. Dynamic Runtime property change option
    // We would like to utilize the benefits of obtaining dynamic property
    // changes
    // initialize the DynamicPropertyFactory with our configuration source
    DynamicPropertyFactory.initWithConfigurationSource(myConfiguration);
    // STEP 3: Optional. Option to inspect and modify properties using JConsole
    // We would like to inspect properties via JMX JConsole and potentially
    // update
    // these properties too
    // Register the MBean
    //
    // This can be also achieved automatically by setting "true" to
    // system property "archaius.dynamicPropertyFactory.registerConfigWithJMX"
    configMBean = ConfigJMXManager.registerConfigMbean(myConfiguration);
    // once this application is launched, launch JConsole and navigate to
    // the
    // Config MBean (under the MBeans tab)
    System.out.println("Started SampleApplication. Launch JConsole to inspect and update properties");
    System.out.println("To see how callback work, update property com.netflix.config.samples.SampleApp.SampleBean.sensitiveBeanData from BaseConfigBean in JConsole");
    SampleBean sampleBean = new SampleBean();
    System.out.println("SampleBean:" + sampleBean);
    System.out.println(sampleBean.getName());
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration)

Example 5 with ConcurrentMapConfiguration

use of com.netflix.config.ConcurrentMapConfiguration in project java-chassis by ServiceComb.

the class SSLOptionTest method testSSLOptionYamlOption2.

@Test
public void testSSLOptionYamlOption2() throws Exception {
    System.setProperty("ssl.protocols", "TLSv1.2");
    YAMLConfigurationSource configSource = new YAMLConfigurationSource();
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(configSource, new NeverStartPollingScheduler());
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
    finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile");
    SSLOption option = SSLOption.buildFromYaml("server", finalConfig);
    String protocols = option.getProtocols();
    option.setProtocols(protocols);
    Assert.assertEquals("TLSv1.2", protocols);
    System.getProperties().clear();
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) YAMLConfigurationSource(io.servicecomb.config.archaius.sources.YAMLConfigurationSource) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) NeverStartPollingScheduler(io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Test(org.junit.Test)

Aggregations

ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)14 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)10 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)6 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 Test (org.junit.Test)4 NeverStartPollingScheduler (io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)3 YAMLConfigurationSource (io.servicecomb.config.archaius.sources.YAMLConfigurationSource)3 Map (java.util.Map)3 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)3 BootstrapException (com.kixeye.chassis.bootstrap.BootstrapException)2 ApplicationConfigurationNotFoundException (com.kixeye.chassis.bootstrap.BootstrapException.ApplicationConfigurationNotFoundException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 Configuration (org.apache.commons.configuration.Configuration)2 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)1 DynamicDoubleProperty (com.netflix.config.DynamicDoubleProperty)1 DynamicWatchedConfiguration (com.netflix.config.DynamicWatchedConfiguration)1