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()); } }
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()); } }
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 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); }
case "create": valueCache.put(sourceKey, value); updateConfiguration(createIncremental(null, ImmutableMap.<String, Object>of(sourceKey, value), null)); break; updateConfiguration(createIncremental(ImmutableMap.<String, Object>of(sourceKey, value), null, null)); break; updateConfiguration(createIncremental(null, null, ImmutableMap.<String, Object>of(sourceKey, ""))); break;
WatchedUpdateResult result = WatchedUpdateResult.createIncremental(added, changed, deleted);