
org.apache.servicecomb.config.center.client.ConfigCenterConfigurationChangedEvent Maven / Gradle / Ivy
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.servicecomb.config.center.client;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* This event is fired when configuration changed of config center.
*/
public class ConfigCenterConfigurationChangedEvent {
private final Map added;
private final Map deleted;
private final Map updated;
private Set changed;
private ConfigCenterConfigurationChangedEvent(Map added, Map updated,
Map deleted) {
this.added = added;
this.deleted = deleted;
this.updated = updated;
this.changed = new HashSet<>();
this.changed.addAll(added.keySet());
this.changed.addAll(updated.keySet());
this.changed.addAll(deleted.keySet());
}
public static ConfigCenterConfigurationChangedEvent createIncremental(Map latest,
Map last) {
Map itemsCreated = new HashMap<>();
Map itemsDeleted = new HashMap<>();
Map itemsModified = new HashMap<>();
for (Map.Entry entry : latest.entrySet()) {
String itemKey = entry.getKey();
if (!last.containsKey(itemKey)) {
itemsCreated.put(itemKey, entry.getValue());
} else if (!Objects.equals(last.get(itemKey), latest.get(itemKey))) {
itemsModified.put(itemKey, entry.getValue());
}
}
for (String itemKey : last.keySet()) {
if (!latest.containsKey(itemKey)) {
itemsDeleted.put(itemKey, null);
}
}
ConfigCenterConfigurationChangedEvent event = ConfigCenterConfigurationChangedEvent
.createIncremental(itemsCreated, itemsModified, itemsDeleted);
return event;
}
public static ConfigCenterConfigurationChangedEvent createIncremental(Map added,
Map updated,
Map deleted) {
return new ConfigCenterConfigurationChangedEvent(added, updated, deleted);
}
public static ConfigCenterConfigurationChangedEvent createIncremental(Map updated) {
return new ConfigCenterConfigurationChangedEvent(new HashMap<>(), updated, new HashMap<>());
}
public final Map getAdded() {
return added;
}
public final Map getUpdated() {
return updated;
}
public final Map getDeleted() {
return deleted;
}
public final Set getChanged() {
return changed;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy