@Override public void eventReceived(Action action, ConfigMap configMap) { offer(WatchedUpdateResult.createFull(asObjectMap(configMap.getData()))); }
public void handle(String action, Map<String, Object> parseConfigs) { if (parseConfigs == null || parseConfigs.isEmpty()) { return; } Map<String, Object> configuration = ConfigMapping.getConvertedMap(parseConfigs); if ("create".equals(action)) { valueCache.putAll(configuration); updateConfiguration(createIncremental(ImmutableMap.<String, Object>copyOf(configuration), null, null)); } else if ("set".equals(action)) { valueCache.putAll(configuration); updateConfiguration(createIncremental(null, ImmutableMap.<String, Object>copyOf(configuration), null)); } else if ("delete".equals(action)) { for (String itemKey : configuration.keySet()) { valueCache.remove(itemKey); } updateConfiguration(createIncremental(null, null, ImmutableMap.<String, Object>copyOf(configuration))); } else { LOGGER.error("action: {} is invalid.", action); return; } LOGGER.warn("Config value cache changed: action:{}; item:{}", action, configuration.keySet()); } }
private void offer(WatchedUpdateResult event) { submit(() -> { listeners.stream().forEach(l -> l.updateConfiguration(event)); currentData.set(event.getComplete()); }); }
@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)); } } } } }
if (result == null || !result.hasChanges()) { return; logger.debug("incremental result? [{}]", result.isIncremental()); logger.debug("ignored deletes from source? [{}]", ignoreDeletesFromSource); if (!result.isIncremental()) { Map<String, Object> props = result.getComplete(); if (props == null) { return; Map<String, Object> props = result.getAdded(); if (props != null) { for (Entry<String, Object> entry : props.entrySet()) { props = result.getChanged(); if (props != null) { for (Entry<String, Object> entry : props.entrySet()) { props = result.getDeleted(); if (props != null) { for (String name : props.keySet()) {
/** * Create a full result that represents the complete content of the configuration source. * * @param complete * map that contains all the properties */ public static WatchedUpdateResult createFull(Map<String, Object> complete) { return new WatchedUpdateResult(complete); }
if (result == null || !result.hasChanges()) { return; logger.debug("incremental result? [{}]", result.isIncremental()); logger.debug("ignored deletes from source? [{}]", ignoreDeletesFromSource); if (!result.isIncremental()) { Map<String, Object> props = result.getComplete(); if (props == null) { return; Map<String, Object> props = result.getAdded(); if (props != null) { for (Entry<String, Object> entry : props.entrySet()) { props = result.getChanged(); if (props != null) { for (Entry<String, Object> entry : props.entrySet()) { props = result.getDeleted(); if (props != null) { for (String name : props.keySet()) {
@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)); } } } } }
/** * Create a full result that represents the complete content of the configuration source. * * @param complete * map that contains all the properties */ public static WatchedUpdateResult createFull(Map<String, Object> complete) { return new WatchedUpdateResult(complete); }
@Nullable @Override public Void apply(@Nullable WatchedUpdateListener watchedUpdateListener) { watchedUpdateListener.updateConfiguration(WatchedUpdateResult.createFull(new HashMap<String, Object>())); return null; } });
public void handle(ConfigurationAction action, Map<String, Object> config) { if (config == null || config.isEmpty()) { return; } Map<String, Object> configuration = ConfigMapping.getConvertedMap(config); if (CREATE.equals(action)) { valueCache.putAll(configuration); updateConfiguration(createIncremental(ImmutableMap.copyOf(configuration), null, null)); } else if (SET.equals(action)) { valueCache.putAll(configuration); updateConfiguration(createIncremental(null, ImmutableMap.copyOf(configuration), null)); } else if (DELETE.equals(action)) { for (String itemKey : configuration.keySet()) { valueCache.remove(itemKey); } updateConfiguration(createIncremental(null, null, ImmutableMap.copyOf(configuration))); } else { LOGGER.error("action: {} is invalid.", action.name()); return; } LOGGER.warn("Config value cache changed: action:{}; item:{}", action.name(), configuration.keySet()); } }
private void offer(WatchedUpdateResult event) { submit(() -> { listeners.stream().forEach(l -> l.updateConfiguration(event)); currentData.set(event.getComplete()); }); }
/** * Create a result that represents incremental changes from the configuration source. * * @param added * properties added * @param changed * properties changed * @param deleted * properties deleted, in which case the value in the map will be ignored */ public static WatchedUpdateResult createIncremental(Map<String, Object> added, Map<String, Object> changed, Map<String, Object> deleted) { return new WatchedUpdateResult(added, changed, deleted); }
@Override public void eventReceived(Action action, ConfigMap configMap) { offer(WatchedUpdateResult.createFull(asObjectMap(configMap.getData()))); }
public void handle(String action, Map<String, Object> parseConfigs) { if (parseConfigs == null || parseConfigs.isEmpty()) { return; } Map<String, Object> configuration = ConfigMapping.getConvertedMap(parseConfigs); if ("create".equals(action)) { valueCache.putAll(configuration); updateConfiguration(createIncremental(ImmutableMap.<String, Object>copyOf(configuration), null, null)); } else if ("set".equals(action)) { valueCache.putAll(configuration); updateConfiguration(createIncremental(null, ImmutableMap.<String, Object>copyOf(configuration), null)); } else if ("delete".equals(action)) { for (String itemKey : configuration.keySet()) { valueCache.remove(itemKey); } updateConfiguration(createIncremental(null, null, ImmutableMap.<String, Object>copyOf(configuration))); } else { LOGGER.error("action: {} is invalid.", action); return; } LOGGER.warn("Config value cache changed: action:{}; item:{}", action, configuration.keySet()); } }
private void offer(WatchedUpdateResult event) { submit(() -> { listeners.stream().forEach(l -> l.updateConfiguration(event)); currentData.set(event.getComplete()); }); }
/** * Create a result that represents incremental changes from the configuration source. * * @param added * properties added * @param changed * properties changed * @param deleted * properties deleted, in which case the value in the map will be ignored */ public static WatchedUpdateResult createIncremental(Map<String, Object> added, Map<String, Object> changed, Map<String, Object> deleted) { return new WatchedUpdateResult(added, changed, deleted); }
@Override public void eventReceived(Action action, ConfigMap configMap) { offer(WatchedUpdateResult.createFull(asObjectMap(configMap.getData()))); }
private WatchedUpdateResult incrementalResult( final ImmutableMap<String, Object> newState, final ImmutableMap<String, Object> previousState) { final Map<String, Object> added = Maps.newHashMap(); final Map<String, Object> removed = Maps.newHashMap(); final Map<String, Object> changed = Maps.newHashMap(); // added addAllKeys( Sets.difference(newState.keySet(), previousState.keySet()), newState, added ); // removed addAllKeys( Sets.difference(previousState.keySet(), newState.keySet()), previousState, removed ); // changed addFilteredKeys( Sets.intersection(previousState.keySet(), newState.keySet()), newState, changed, new Predicate<String>() { @Override public boolean apply(String key) { return !previousState.get(key).equals(newState.get(key)); } } ); return WatchedUpdateResult.createIncremental(added, changed, removed); }
public void runOnce() throws InterruptedException { try { Response<List<GetValue>> kvals = updateIndex(getRaw(watchParams())); ImmutableMap<String, Object> full = convertToMap(kvals); final WatchedUpdateResult result; if (lastState.get() == null) { result = WatchedUpdateResult.createFull(full); } else { result = incrementalResult(full, lastState.get()); } lastState.set(full); fireEvent(result); } catch (Exception e) { LOGGER.error("Error watching path, waiting to retry", e); Thread.sleep(5000); } }