@Override public void updateConfiguration(WatchedUpdateResult watchedUpdateResult) { Map<String, Object> adds = watchedUpdateResult.getAdded(); if (adds != null) { for (String add : adds.keySet()) { if (add.startsWith(CONFIG_CSE_PREFIX)) { String key = CONFIG_SERVICECOMB_PREFIX + add.substring(add.indexOf(".") + 1); injectConfig.addProperty(key, adds.get(add)); } } } Map<String, Object> deletes = watchedUpdateResult.getDeleted(); if (deletes != null) { for (String delete : deletes.keySet()) { if (delete.startsWith(CONFIG_CSE_PREFIX)) { injectConfig.clearProperty(CONFIG_SERVICECOMB_PREFIX + delete.substring(delete.indexOf(".") + 1)); } } } Map<String, Object> changes = watchedUpdateResult.getChanged(); if (changes != null) { for (String change : changes.keySet()) { if (change.startsWith(CONFIG_CSE_PREFIX)) { String key = CONFIG_SERVICECOMB_PREFIX + change.substring(change.indexOf(".") + 1); injectConfig.setProperty(key, changes.get(change)); } } } } }
/** * Load properties into the configuration. This method iterates through * the entries of the properties and call {@link #setProperty(String, Object)} for * non-null key/value. */ public void loadProperties(Properties props) { for (Map.Entry<Object, Object> entry: props.entrySet()) { String key = (String) entry.getKey(); Object value = entry.getValue(); if (key != null && value != null) { setProperty(key, value); } } }
/** * Load properties into the configuration. This method iterates through * the entries of the properties and call {@link #setProperty(String, Object)} for * non-null key/value. */ public void loadProperties(Properties props) { for (Map.Entry<Object, Object> entry: props.entrySet()) { String key = (String) entry.getKey(); Object value = entry.getValue(); if (key != null && value != null) { setProperty(key, value); } } }
/** * Copy properties of a configuration into this configuration. This method simply * iterates the keys of the configuration to be copied and call {@link #setProperty(String, Object)} * for non-null key/value. */ @Override public void copy(Configuration c) { if (c != null) { for (Iterator it = c.getKeys(); it.hasNext();) { String key = (String) it.next(); Object value = c.getProperty(key); if (key != null && value != null) { setProperty(key, value); } } } }
/** * Copy properties of a configuration into this configuration. This method simply * iterates the keys of the configuration to be copied and call {@link #setProperty(String, Object)} * for non-null key/value. */ @Override public void copy(Configuration c) { if (c != null) { for (Iterator it = c.getKeys(); it.hasNext();) { String key = (String) it.next(); Object value = c.getProperty(key); if (key != null && value != null) { setProperty(key, value); } } } }
public EagleMailClient(AbstractConfiguration configuration) { try { ConcurrentMapConfiguration con = (ConcurrentMapConfiguration)configuration; velocityEngine = new VelocityEngine(); velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); velocityEngine.init(); con.setProperty("mail.transport.protocol", "smtp"); final Properties config = con.getProperties(); if(Boolean.parseBoolean(config.getProperty(AUTH_CONFIG))){ session = Session.getDefaultInstance(config, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(config.getProperty(USER_CONFIG), config.getProperty(PASSWORD_CONFIG)); } }); } else session = Session.getDefaultInstance(config, new Authenticator() {}); final String debugMode = config.getProperty(DEBUG_CONFIG, "false"); final boolean debug = Boolean.parseBoolean(debugMode); session.setDebug(debug); } catch (Exception e) { LOG.error("Failed connect to smtp server",e); } }
@Override public void updateConfiguration(WatchedUpdateResult watchedUpdateResult) { Map<String, Object> adds = watchedUpdateResult.getAdded(); if (adds != null) { for (String add : adds.keySet()) { if (add.startsWith(CONFIG_CSE_PREFIX)) { String key = CONFIG_SERVICECOMB_PREFIX + add.substring(add.indexOf(".") + 1); injectConfig.addProperty(key, adds.get(add)); } } } Map<String, Object> deletes = watchedUpdateResult.getDeleted(); if (deletes != null) { for (String delete : deletes.keySet()) { if (delete.startsWith(CONFIG_CSE_PREFIX)) { injectConfig.clearProperty(CONFIG_SERVICECOMB_PREFIX + delete.substring(delete.indexOf(".") + 1)); } } } Map<String, Object> changes = watchedUpdateResult.getChanged(); if (changes != null) { for (String change : changes.keySet()) { if (change.startsWith(CONFIG_CSE_PREFIX)) { String key = CONFIG_SERVICECOMB_PREFIX + change.substring(change.indexOf(".") + 1); injectConfig.setProperty(key, changes.get(change)); } } } } }
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()); } }
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()); } }