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());
}
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;
}
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;
}
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());
}
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();
}
Aggregations