-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SCB-2813]DynamicProperties: when key removed should get default value (
- Loading branch information
Showing
10 changed files
with
211 additions
and
152 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
...va/org/apache/servicecomb/config/center/client/ConfigCenterConfigurationChangedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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<String, Object> added; | ||
|
||
private final Map<String, Object> deleted; | ||
|
||
private final Map<String, Object> updated; | ||
|
||
private Set<String> changed; | ||
|
||
private ConfigCenterConfigurationChangedEvent(Map<String, Object> added, Map<String, Object> updated, | ||
Map<String, Object> 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<String, Object> latest, | ||
Map<String, Object> last) { | ||
Map<String, Object> itemsCreated = new HashMap<>(); | ||
Map<String, Object> itemsDeleted = new HashMap<>(); | ||
Map<String, Object> itemsModified = new HashMap<>(); | ||
|
||
for (Map.Entry<String, Object> 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<String, Object> added, | ||
Map<String, Object> updated, | ||
Map<String, Object> deleted) { | ||
return new ConfigCenterConfigurationChangedEvent(added, updated, deleted); | ||
} | ||
|
||
public static ConfigCenterConfigurationChangedEvent createIncremental(Map<String, Object> updated) { | ||
return new ConfigCenterConfigurationChangedEvent(new HashMap<>(), updated, new HashMap<>()); | ||
} | ||
|
||
public final Map<String, Object> getAdded() { | ||
return added; | ||
} | ||
|
||
|
||
public final Map<String, Object> getUpdated() { | ||
return updated; | ||
} | ||
|
||
|
||
public final Map<String, Object> getDeleted() { | ||
return deleted; | ||
} | ||
|
||
public final Set<String> getChanged() { | ||
return changed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
...mon/src/test/java/org/apache/servicecomb/config/common/TestConfigurationChangedEvent.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.