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

albumenj pushed a commit to branch 3.0-multi-instances
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0-multi-instances by this 
push:
     new 8fd6a88  Fix Configurator Listener in Singleton mode override issue
8fd6a88 is described below

commit 8fd6a88a52c1a86c8b5a7b1c1f6fbdaa3daf930d
Author: Albumen Kevin <[email protected]>
AuthorDate: Sun Aug 29 23:46:09 2021 +0800

    Fix Configurator Listener in Singleton mode override issue
---
 .../registry/integration/RegistryProtocol.java     | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
index f53096a..661771e 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
@@ -138,7 +138,6 @@ public class RegistryProtocol implements Protocol, 
ScopeModelAware {
     };
 
     private final static Logger logger = 
LoggerFactory.getLogger(RegistryProtocol.class);
-    private final Map<URL, NotifyListener> overrideListeners = new 
ConcurrentHashMap<>();
     private final Map<String, ServiceConfigurationListener> 
serviceConfigurationListeners = new ConcurrentHashMap<>();
     //To solve the problem of RMI repeated exposure port conflicts, the 
services that have been exposed are no longer exposed.
     //provider url <--> exporter
@@ -187,7 +186,16 @@ public class RegistryProtocol implements Protocol, 
ScopeModelAware {
     }
 
     public Map<URL, NotifyListener> getOverrideListeners() {
-        return overrideListeners;
+        Map<URL, NotifyListener> map = new HashMap<>();
+        List<ApplicationModel> applicationModels = 
frameworkModel.getApplicationModels();
+        if (applicationModels.size() == 1) {
+            return 
applicationModels.get(0).getBeanFactory().getBean(ProviderConfigurationListener.class).getOverrideListeners();
+        } else {
+            for (ApplicationModel applicationModel : applicationModels) {
+                
map.putAll(applicationModel.getBeanFactory().getBean(ProviderConfigurationListener.class).getOverrideListeners());
+            }
+        }
+        return map;
     }
 
     private void register(Registry registry, URL registeredProviderUrl) {
@@ -215,6 +223,7 @@ public class RegistryProtocol implements Protocol, 
ScopeModelAware {
         //  subscription information to cover.
         final URL overrideSubscribeUrl = getSubscribedOverrideUrl(providerUrl);
         final OverrideListener overrideSubscribeListener = new 
OverrideListener(overrideSubscribeUrl, originInvoker);
+        Map<URL, NotifyListener> overrideListeners = 
getProviderConfigurationListener(providerUrl).getOverrideListeners();
         overrideListeners.put(registryUrl, overrideSubscribeListener);
 
         providerUrl = overrideUrlWithConfig(providerUrl, 
overrideSubscribeListener);
@@ -761,6 +770,8 @@ public class RegistryProtocol implements Protocol, 
ScopeModelAware {
 
     private class ProviderConfigurationListener extends 
AbstractConfiguratorListener {
 
+        private final Map<URL, NotifyListener> overrideListeners = new 
ConcurrentHashMap<>();
+
         public ProviderConfigurationListener(ApplicationModel 
applicationModel) {
             super(applicationModel);
             if 
(applicationModel.getApplicationEnvironment().getConfiguration().convert(Boolean.class,
 ENABLE_CONFIGURATION_LISTEN, true)) {
@@ -783,6 +794,10 @@ public class RegistryProtocol implements Protocol, 
ScopeModelAware {
         protected void notifyOverrides() {
             overrideListeners.values().forEach(listener -> ((OverrideListener) 
listener).doOverrideIfNecessary());
         }
+
+        public Map<URL, NotifyListener> getOverrideListeners() {
+            return overrideListeners;
+        }
     }
 
     /**
@@ -830,7 +845,8 @@ public class RegistryProtocol implements Protocol, 
ScopeModelAware {
                 logger.warn(t.getMessage(), t);
             }
             try {
-                NotifyListener listener = 
RegistryProtocol.this.overrideListeners.remove(registerUrl);
+                Map<URL, NotifyListener> overrideListeners = 
getProviderConfigurationListener(subscribeUrl).getOverrideListeners();
+                NotifyListener listener = 
overrideListeners.remove(registerUrl);
                 registry.unsubscribe(subscribeUrl, listener);
                 ApplicationModel applicationModel = 
getApplicationModel(registerUrl.getScopeModel());
                 if 
(applicationModel.getApplicationEnvironment().getConfiguration().convert(Boolean.class,
 ENABLE_CONFIGURATION_LISTEN, true)) {

Reply via email to