-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support incremental configuration synchronization client
- Loading branch information
1 parent
21259e5
commit 5f1e105
Showing
7 changed files
with
269 additions
and
5 deletions.
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/ConfigurationChange.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,71 @@ | ||
/* | ||
* Copyright 2022 Apollo Authors | ||
* | ||
* Licensed 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 com.ctrip.framework.apollo.core.dto; | ||
|
||
|
||
import com.ctrip.framework.apollo.core.enums.ConfigurationChangeType; | ||
|
||
/** | ||
* Holds the information for a Configuration change. | ||
* @author jason | ||
*/ | ||
public class ConfigurationChange { | ||
private final String key; | ||
private String newValue; | ||
private ConfigurationChangeType configurationChangeType; | ||
|
||
/** | ||
* Constructor. | ||
* @param key the key whose value is changed | ||
* @param newValue the value after change | ||
* @param configurationChangeType the change type | ||
*/ | ||
public ConfigurationChange(String key, String newValue, ConfigurationChangeType configurationChangeType) { | ||
this.key = key; | ||
this.newValue = newValue; | ||
this.configurationChangeType = configurationChangeType; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
public String getNewValue() { | ||
return newValue; | ||
} | ||
|
||
public ConfigurationChangeType getConfigurationChangeType() { | ||
return configurationChangeType; | ||
} | ||
|
||
public void setNewValue(String newValue) { | ||
this.newValue = newValue; | ||
} | ||
|
||
public void setConfigurationChangeType(ConfigurationChangeType configurationChangeType) { | ||
this.configurationChangeType = configurationChangeType; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("ConfigChange{"); | ||
sb.append(" key='").append(key).append('\''); | ||
sb.append(", newValue='").append(newValue).append('\''); | ||
sb.append(", configurationChangeType=").append(configurationChangeType); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigSyncType.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,62 @@ | ||
/* | ||
* Copyright 2022 Apollo Authors | ||
* | ||
* Licensed 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 com.ctrip.framework.apollo.core.enums; | ||
|
||
import com.ctrip.framework.apollo.core.utils.StringUtils; | ||
|
||
import java.util.stream.Stream; | ||
|
||
/** | ||
* This enum represents all the possible Configuration sync from apollo-config | ||
* | ||
* @author jason | ||
*/ | ||
public enum ConfigSyncType { | ||
FULLSYNC("FullSync"), INCREMENTALSYNC("IncrementalSync"); | ||
|
||
private final String value; | ||
|
||
ConfigSyncType(String value) { | ||
this.value = value; | ||
} | ||
|
||
|
||
|
||
/** | ||
* Transforms a given string to its matching {@link ConfigSyncType}. | ||
* | ||
* @param value the string that matches | ||
* @return the matching {@link ConfigSyncType} | ||
* @throws IllegalArgumentException in case the <code>value</code> is empty or there is no | ||
* matching {@link ConfigSyncType} | ||
*/ | ||
public static ConfigSyncType fromString(String value) { | ||
if (StringUtils.isEmpty(value)) { | ||
return FULLSYNC; | ||
} | ||
return Stream.of(ConfigSyncType.values()).filter(type -> type.value.equals(value)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException(value + " can not map enum")); | ||
} | ||
|
||
/** | ||
* @return The string representation of the given {@link ConfigSyncType} | ||
*/ | ||
public String getValue() { | ||
return value; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/ConfigurationChangeType.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,25 @@ | ||
/* | ||
* Copyright 2022 Apollo Authors | ||
* | ||
* Licensed 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 com.ctrip.framework.apollo.core.enums; | ||
|
||
|
||
/** | ||
* @author jason | ||
*/ | ||
public enum ConfigurationChangeType { | ||
ADDED, MODIFIED, DELETED | ||
} |
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