From 893656391b1acce1dd161d1e79f432d5fce60fb4 Mon Sep 17 00:00:00 2001 From: TomlongTK <1120170646@qq.com> Date: Mon, 8 Apr 2024 09:57:00 +0800 Subject: [PATCH] Transfer polaris change type to dubbo change type (#61) --- .../PolarisDynamicConfiguration.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfiguration.java b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfiguration.java index c691fe9..9d63527 100644 --- a/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfiguration.java +++ b/dubbo/dubbo-plugins/dubbo-configcenter-polaris/src/main/java/com/tencent/polaris/dubbo/configuration/PolarisDynamicConfiguration.java @@ -23,11 +23,13 @@ import com.tencent.polaris.common.registry.PolarisConfig; import com.tencent.polaris.common.registry.PolarisOperator; import com.tencent.polaris.common.registry.PolarisOperators; +import com.tencent.polaris.configuration.api.core.ChangeType; import com.tencent.polaris.configuration.api.core.ConfigFile; import com.tencent.polaris.configuration.api.core.ConfigFilePublishService; import com.tencent.polaris.configuration.api.core.ConfigFileService; import com.tencent.polaris.configuration.api.rpc.ConfigPublishRequest; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.config.configcenter.ConfigChangeType; import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent; import org.apache.dubbo.common.config.configcenter.ConfigurationListener; import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; @@ -52,7 +54,7 @@ public class PolarisDynamicConfiguration implements DynamicConfiguration { private final ConfigFilePublishService filePublisher; - private Map> listeners = new ConcurrentHashMap<>(); + private final Map> listeners = new ConcurrentHashMap<>(); PolarisDynamicConfiguration(URL url) { this.operator = PolarisOperators.loadOrStoreForConfig(url.getHost(), url.getPort(), url.getParameters()); @@ -69,7 +71,8 @@ public void addListener(String key, String group, ConfigurationListener listener configFile.addChangeListener(event -> { Set watchers = listeners.getOrDefault(fileKey, Collections.emptySet()); watchers.forEach(configurationListener -> { - ConfigChangedEvent dubboEvent = new ConfigChangedEvent(key, group, event.getNewValue()); + ConfigChangedEvent dubboEvent = new ConfigChangedEvent( + key, group, event.getNewValue(), getChangeType(event.getChangeType())); configurationListener.process(dubboEvent); }); }); @@ -180,4 +183,20 @@ public boolean publishConfigCas(String key, String group, String content, Object private String formatCode(Object val) { return "POLARIS:" + val; } + + private ConfigChangeType getChangeType(ChangeType polarisChangeType) { + ConfigChangeType dubboChangeType; + switch (polarisChangeType) { + case ADDED: + dubboChangeType = ConfigChangeType.ADDED; + break; + case DELETED: + dubboChangeType = ConfigChangeType.DELETED; + break; + default: + dubboChangeType = ConfigChangeType.MODIFIED; + break; + } + return dubboChangeType; + } }