You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/03 09:14:01 UTC

[dubbo] branch master updated: Fill conditionKeys collections when necessary (#7462)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new dd36381  Fill conditionKeys collections when necessary (#7462)
dd36381 is described below

commit dd363819ea9a65b83265d867bb591c29eebe6104
Author: 灼华 <43...@users.noreply.github.com>
AuthorDate: Thu Jun 3 17:13:41 2021 +0800

    Fill conditionKeys collections when necessary (#7462)
    
    * fill conditionKeys collections when necessary
    
    * Use set container to handle multiple tildeKey situations
---
 .../cluster/configurator/AbstractConfigurator.java | 44 +++++++++++-----------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
index 108810d..266b08d 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
@@ -126,7 +126,26 @@ public abstract class AbstractConfigurator implements Configurator {
                 String currentApplication = url.getParameter(APPLICATION_KEY, url.getUsername());
                 if (configApplication == null || ANY_VALUE.equals(configApplication)
                         || configApplication.equals(currentApplication)) {
-                    Set<String> conditionKeys = new HashSet<String>();
+
+                    Set<String> tildeKeys = new HashSet<>();
+                    for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) {
+                        String key = entry.getKey();
+                        String value = entry.getValue();
+                        String tildeKey = StringUtils.isNotEmpty(key) && key.startsWith(TILDE) ? key : null;
+
+                        if (tildeKey != null || APPLICATION_KEY.equals(key) || SIDE_KEY.equals(key)) {
+                            if (value != null && !ANY_VALUE.equals(value)
+                                    && !value.equals(url.getParameter(tildeKey != null ? key.substring(1) : key))) {
+                                return url;
+                            }
+                        }
+
+                        if (tildeKey != null) {
+                            tildeKeys.add(tildeKey);
+                        }
+                    }
+
+                    Set<String> conditionKeys = new HashSet<>();
                     conditionKeys.add(CATEGORY_KEY);
                     conditionKeys.add(Constants.CHECK_KEY);
                     conditionKeys.add(DYNAMIC_KEY);
@@ -138,20 +157,8 @@ public abstract class AbstractConfigurator implements Configurator {
                     conditionKeys.add(CONFIG_VERSION_KEY);
                     conditionKeys.add(COMPATIBLE_CONFIG_KEY);
                     conditionKeys.add(INTERFACES);
-                    for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) {
-                        String key = entry.getKey();
-                        String value = entry.getValue();
-                        boolean startWithTilde = startWithTilde(key);
-                        if (startWithTilde || APPLICATION_KEY.equals(key) || SIDE_KEY.equals(key)) {
-                            if (startWithTilde) {
-                                conditionKeys.add(key);
-                            }
-                            if (value != null && !ANY_VALUE.equals(value)
-                                    && !value.equals(url.getParameter(startWithTilde ? key.substring(1) : key))) {
-                                return url;
-                            }
-                        }
-                    }
+                    conditionKeys.addAll(tildeKeys);
+
                     return doConfigure(url, configuratorUrl.removeParameters(conditionKeys));
                 }
             }
@@ -159,13 +166,6 @@ public abstract class AbstractConfigurator implements Configurator {
         return url;
     }
 
-    private boolean startWithTilde(String key) {
-        if (StringUtils.isNotEmpty(key) && key.startsWith(TILDE)) {
-            return true;
-        }
-        return false;
-    }
-
     protected abstract URL doConfigure(URL currentUrl, URL configUrl);
 
 }