Skip to content

Commit

Permalink
Transfer polaris change type to dubbo change type (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
finefuture authored Apr 8, 2024
1 parent 4e55d8a commit 8936563
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,7 +54,7 @@ public class PolarisDynamicConfiguration implements DynamicConfiguration {

private final ConfigFilePublishService filePublisher;

private Map<String, Set<ConfigurationListener>> listeners = new ConcurrentHashMap<>();
private final Map<String, Set<ConfigurationListener>> listeners = new ConcurrentHashMap<>();

PolarisDynamicConfiguration(URL url) {
this.operator = PolarisOperators.loadOrStoreForConfig(url.getHost(), url.getPort(), url.getParameters());
Expand All @@ -69,7 +71,8 @@ public void addListener(String key, String group, ConfigurationListener listener
configFile.addChangeListener(event -> {
Set<ConfigurationListener> 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);
});
});
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 8936563

Please sign in to comment.