private ConfigChangeType getChangeType(ConfigChange change) { if (change.getChangeType() == PropertyChangeType.DELETED) { return ConfigChangeType.DELETED; } return ConfigChangeType.MODIFIED; }
@Override public String apply(ConfigChange input) { return input.getPropertyName(); } });
@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()); } } };
@Override public void onChange(com.ctrip.framework.apollo.model.ConfigChangeEvent changeEvent) { for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); if ("".equals(change.getNewValue())) { logger.warn("an empty rule is received for " + key + ", the current working rule is " + change.getOldValue() + ", the empty rule will not take effect."); return; } ConfigChangeEvent event = new ConfigChangeEvent(key, change.getNewValue(), getChangeType(change)); listeners.forEach(listener -> listener.process(event)); } }
/** * Check whether we should trigger the auto update or not. * <br /> * For added or modified keys, we should trigger auto update if the current value in Spring equals to the new value. * <br /> * For deleted keys, we will trigger auto update anyway. */ private boolean shouldTriggerAutoUpdate(ConfigChangeEvent changeEvent, String changedKey) { ConfigChange configChange = changeEvent.getChange(changedKey); if (configChange.getChangeType() == PropertyChangeType.DELETED) { return true; } return Objects.equals(environment.getProperty(changedKey), configChange.getNewValue()); }
change.setOldValue(this.getProperty(change.getPropertyName(), change.getOldValue())); change.setNewValue(this.getProperty(change.getPropertyName(), change.getNewValue())); switch (change.getChangeType()) { case ADDED: if (Objects.equals(change.getOldValue(), change.getNewValue())) { break; if (change.getOldValue() != null) { change.setChangeType(PropertyChangeType.MODIFIED); actualChanges.put(change.getPropertyName(), change); break; case MODIFIED: if (!Objects.equals(change.getOldValue(), change.getNewValue())) { actualChanges.put(change.getPropertyName(), change); if (Objects.equals(change.getOldValue(), change.getNewValue())) { break; if (change.getNewValue() != null) { change.setChangeType(PropertyChangeType.MODIFIED); actualChanges.put(change.getPropertyName(), change); break; default:
@Override public void onChange(ConfigChangeEvent changeEvent) { ConfigChange change = changeEvent.getChange(group + "-" + serviceId); String config = change.getNewValue(); subscribeCallback.callback(config); } };
@Override public void onChange(ConfigChangeEvent changeEvent) { ConfigChange change = changeEvent.getChange(flowRulesKey); //change is never null because the listener will only notify for this key if (change != null) { RecordLog.info("[ApolloDataSource] Received config changes: " + change.toString()); } loadAndUpdateRules(); } }, Sets.newHashSet(flowRulesKey));
@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. check whether the value is really changed or not (since spring property sources have hierarchies) if (!shouldTriggerAutoUpdate(changeEvent, key)) { continue; } // 3. update the value for (SpringValue val : targetValues) { updateSpringValue(val); } } }
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; }
@Override public synchronized void onRepositoryChange(String namespace, Properties newProperties) { if (newProperties.equals(m_configProperties.get())) { return; } ConfigSourceType sourceType = m_configRepository.getSourceType(); Properties newConfigProperties = new Properties(); newConfigProperties.putAll(newProperties); Map<String, ConfigChange> actualChanges = updateAndCalcConfigChanges(newConfigProperties, sourceType); //check double checked result if (actualChanges.isEmpty()) { return; } this.fireConfigChange(new ConfigChangeEvent(m_namespace, actualChanges)); Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace); }
@Override public void onChange(ConfigFileChangeEvent changeEvent) { logger.info(changeEvent.toString()); } });
changes.add(new ConfigChange(namespace, newKey, null, current.getProperty(newKey), PropertyChangeType.ADDED)); changes.add(new ConfigChange(namespace, removedKey, previous.getProperty(removedKey), null, PropertyChangeType.DELETED)); continue; changes.add(new ConfigChange(namespace, commonKey, previousValue, currentValue, PropertyChangeType.MODIFIED));
@Override public synchronized void onRepositoryChange(String namespace, Properties newProperties) { if (newProperties.equals(m_configProperties.get())) { return; } Properties newConfigProperties = new Properties(); newConfigProperties.putAll(newProperties); String oldValue = getContent(); update(newProperties); m_sourceType = m_configRepository.getSourceType(); String newValue = getContent(); PropertyChangeType changeType = PropertyChangeType.MODIFIED; if (oldValue == null) { changeType = PropertyChangeType.ADDED; } else if (newValue == null) { changeType = PropertyChangeType.DELETED; } this.fireConfigChange(new ConfigFileChangeEvent(m_namespace, oldValue, newValue, changeType)); Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace); }
@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()); } } };
@Override public void onChange(com.ctrip.framework.apollo.model.ConfigChangeEvent changeEvent) { for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); if ("".equals(change.getNewValue())) { logger.warn("an empty rule is received for " + key + ", the current working rule is " + change.getOldValue() + ", the empty rule will not take effect."); return; } ConfigChangeEvent event = new ConfigChangeEvent(key, change.getNewValue(), getChangeType(change)); listeners.forEach(listener -> listener.process(event)); } }
@Override public void onChange(ConfigChangeEvent changeEvent) { ConfigChange change = changeEvent.getChange(flowRulesKey); //change is never null because the listener will only notify for this key if (change != null) { RecordLog.info("[ApolloDataSource] Received config changes: " + change.toString()); } loadAndUpdateRules(); } }, Sets.newHashSet(flowRulesKey));
@ApolloConfigChangeListener public void onChange(ConfigChangeEvent changeEvent) { boolean redisCacheKeysChanged = false; for (String changedKey : changeEvent.changedKeys()) { if (changedKey.startsWith("redis.cache")) { redisCacheKeysChanged = true; break; } } if (!redisCacheKeysChanged) { return; } logger.info("before refresh {}", sampleRedisConfig.toString()); refreshScope.refresh("sampleRedisConfig"); logger.info("after refresh {}", sampleRedisConfig.toString()); } }
private ConfigChangeType getChangeType(ConfigChange change) { if (change.getChangeType() == PropertyChangeType.DELETED) { return ConfigChangeType.DELETED; } return ConfigChangeType.MODIFIED; }
@Override public synchronized void onRepositoryChange(String namespace, Properties newProperties) { if (newProperties.equals(m_configProperties)) { return; } Properties newConfigProperties = new Properties(); newConfigProperties.putAll(newProperties); List<ConfigChange> changes = calcPropertyChanges(namespace, m_configProperties, newConfigProperties); Map<String, ConfigChange> changeMap = Maps.uniqueIndex(changes, new Function<ConfigChange, String>() { @Override public String apply(ConfigChange input) { return input.getPropertyName(); } }); updateConfig(newConfigProperties, m_configRepository.getSourceType()); clearConfigCache(); this.fireConfigChange(new ConfigChangeEvent(m_namespace, changeMap)); Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace); }