Java Code Examples for com.ctrip.framework.apollo.model.ConfigChangeEvent#changedKeys()
The following examples show how to use
com.ctrip.framework.apollo.model.ConfigChangeEvent#changedKeys() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoUpdateConfigChangeListener.java From apollo with Apache License 2.0 | 6 votes |
@Override public void onChange(ConfigChangeEvent changeEvent) { Set<String> keys = changeEvent.changedKeys(); if (CollectionUtils.isEmpty(keys)) { return; } for (String key : keys) { // 1. check whether the changed key is relevant Collection<SpringValue> targetValues = springValueRegistry.get(beanFactory, key); if (targetValues == null || targetValues.isEmpty()) { continue; } // 2. update the value for (SpringValue val : targetValues) { updateSpringValue(val); } } }
Example 2
Source File: SimpleApolloConfigDemo.java From apollo with Apache License 2.0 | 6 votes |
public SimpleApolloConfigDemo() { ConfigChangeListener changeListener = new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { logger.info("Changes for namespace {}", changeEvent.getNamespace()); for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); logger.info("Change - key: {}, oldValue: {}, newValue: {}, changeType: {}", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType()); } } }; config = ConfigService.getAppConfig(); config.addChangeListener(changeListener); }
Example 3
Source File: ApolloConfigLoader.java From tunnel with Apache License 2.0 | 5 votes |
@Override public void onChange(ConfigChangeEvent changeEvent) { Set<String> keys = changeEvent.changedKeys(); for (String key : keys) { ConfigChange change = changeEvent.getChange(key); if (change == null) { continue; } String oldValue = change.getOldValue(); String newValue = change.getNewValue(); configListener.onChange(key, oldValue, newValue); } }
Example 4
Source File: ApolloConfigLoader.java From tunnel with Apache License 2.0 | 5 votes |
@Override public void onChange(ConfigChangeEvent changeEvent) { Set<String> keys = changeEvent.changedKeys(); for (String key : keys) { ConfigChange change = changeEvent.getChange(key); if (change == null) { continue; } String oldValue = change.getOldValue(); String newValue = change.getNewValue(); configListener.onChange(key, oldValue, newValue); } }
Example 5
Source File: ApolloConfig.java From java-tutorial with MIT License | 5 votes |
@ApolloConfigChangeListener(ConfigConsts.NAMESPACE_APPLICATION) public void onChange(ConfigChangeEvent changeEvent) { logger.info("before refresh"); for (String changedKey : changeEvent.changedKeys()) { logger.info("==============================================================="); logger.info("changedKey:{} value:{}", changedKey, changeEvent.getChange(changedKey)); ConfigChange configChange = changeEvent.getChange(changedKey); configChange.getOldValue(); } refreshScope.refreshAll(); logger.info("after refresh"); }
Example 6
Source File: AbstractConfig.java From apollo with Apache License 2.0 | 5 votes |
private boolean isConfigChangeListenerInterested(ConfigChangeListener configChangeListener, ConfigChangeEvent configChangeEvent) { Set<String> interestedKeys = m_interestedKeys.get(configChangeListener); Set<String> interestedKeyPrefixes = m_interestedKeyPrefixes.get(configChangeListener); if ((interestedKeys == null || interestedKeys.isEmpty()) && (interestedKeyPrefixes == null || interestedKeyPrefixes.isEmpty())) { return true; // no interested keys means interested in all keys } if (interestedKeys != null) { for (String interestedKey : interestedKeys) { if (configChangeEvent.isChanged(interestedKey)) { return true; } } } if (interestedKeyPrefixes != null) { for (String prefix : interestedKeyPrefixes) { for (final String changedKey : configChangeEvent.changedKeys()) { if (changedKey.startsWith(prefix)) { return true; } } } } return false; }