From e23afa0159467f26284ded5b52213c473581ee7b Mon Sep 17 00:00:00 2001 From: cvictory Date: Mon, 13 May 2019 14:20:38 +0800 Subject: [PATCH] modify dependency #3932 --- dubbo-all/pom.xml | 8 +++++ .../registry/multiple/MultipleRegistry.java | 33 +++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/dubbo-all/pom.xml b/dubbo-all/pom.xml index c38263aa7b9..851888c1257 100644 --- a/dubbo-all/pom.xml +++ b/dubbo-all/pom.xml @@ -275,6 +275,13 @@ compile true + + org.apache.dubbo + dubbo-registry-multiple + ${project.version} + compile + true + org.apache.dubbo dubbo-monitor-api @@ -567,6 +574,7 @@ org.apache.dubbo:dubbo-registry-etcd3 org.apache.dubbo:dubbo-registry-nacos org.apache.dubbo:dubbo-registry-sofa + org.apache.dubbo:dubbo-registry-multiple org.apache.dubbo:dubbo-monitor-api org.apache.dubbo:dubbo-monitor-default org.apache.dubbo:dubbo-config-api diff --git a/dubbo-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistry.java b/dubbo-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistry.java index a20ad38f347..1a36feef64b 100644 --- a/dubbo-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistry.java +++ b/dubbo-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistry.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryFactory; @@ -45,8 +46,8 @@ public class MultipleRegistry implements Registry { private static final Logger logger = LoggerFactory.getLogger(MultipleRegistry.class); - private static final String REGISTRY_FOR_SERVICE = "for-service"; - private static final String REGISTRY_FOR_REFERENCE = "for-reference"; + private static final String REGISTRY_FOR_SERVICE = "service-registry"; + private static final String REGISTRY_FOR_REFERENCE = "reference-registry"; private RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension(); private Map serviceRegistries = new HashMap(4); @@ -62,6 +63,7 @@ public class MultipleRegistry implements Registry { public MultipleRegistry(URL url) { this.registryUrl = url; this.applicationName = url.getParameter(Constants.APPLICATION_KEY); + init(); checkApplicationName(this.applicationName); // This urls contain parameter and it donot inherit from the parameter of url in MultipleRegistry origServiceRegistryURLs = url.getParameter(REGISTRY_FOR_SERVICE, new ArrayList()); @@ -160,13 +162,16 @@ public List lookup(URL url) { List urls = new ArrayList(); for (Registry registry : referenceRegistries.values()) { List tmpUrls = registry.lookup(url); - if (tmpUrls != null && !tmpUrls.isEmpty()) { + if (!CollectionUtils.isEmpty(tmpUrls)) { urls.addAll(tmpUrls); } } return urls; } + protected void init(){ + } + protected List filterServiceRegistry(List serviceRegistryURLs) { return serviceRegistryURLs; } @@ -176,6 +181,7 @@ protected List filterReferenceRegistry(List referenceRegistryURL } protected synchronized void refreshServiceRegistry(List serviceRegistryURLs) { + this.effectServiceRegistryURLs = serviceRegistryURLs; doRefreshRegistry(serviceRegistryURLs, serviceRegistries, () -> this.getRegisteredURLs(), (registry, registeredURLs) -> { for (URL url : (Set) registeredURLs) { @@ -193,6 +199,7 @@ protected synchronized void refreshServiceRegistry(List serviceRegistryU } protected synchronized void refreshReferenceRegistry(List referenceRegistryURLs) { + this.effectReferenceRegistryURLs = referenceRegistryURLs; doRefreshRegistry(referenceRegistryURLs, referenceRegistries, () -> this.getSubscribedURLMap(), (registry, registeredURLs) -> { for (Map.Entry> urlNotifyListenerMap : ((Map>) registeredURLs).entrySet()) { @@ -257,7 +264,7 @@ private synchronized void doRefreshRegistry(List newRegistryURLs, Map getRegisteredURLs() { Registry tmpRegistry = iterator.next(); if (tmpRegistry instanceof AbstractRegistry) { AbstractRegistry tmpAbstractRegistry = (AbstractRegistry) tmpRegistry; - return tmpAbstractRegistry.getRegistered(); + if (!CollectionUtils.isEmpty(tmpAbstractRegistry.getRegistered())) { + return tmpAbstractRegistry.getRegistered(); + } } } return Collections.emptySet(); @@ -284,10 +293,12 @@ private Map> getSubscribedURLMap() { Registry tmpRegistry = iterator.next(); if (tmpRegistry instanceof AbstractRegistry) { AbstractRegistry tmpAbstractRegistry = (AbstractRegistry) tmpRegistry; - return tmpAbstractRegistry.getSubscribed(); + if (CollectionUtils.isEmptyMap(tmpAbstractRegistry.getSubscribed())) { + return tmpAbstractRegistry.getSubscribed(); + } } } - return Collections.EMPTY_MAP; + return null; } protected void checkApplicationName(String applicationName) { @@ -312,4 +323,12 @@ public List getOrigServiceRegistryURLs() { public List getOrigReferenceRegistryURLs() { return origReferenceRegistryURLs; } + + public List getEffectServiceRegistryURLs() { + return effectServiceRegistryURLs; + } + + public List getEffectReferenceRegistryURLs() { + return effectReferenceRegistryURLs; + } }