Skip to content

Commit

Permalink
modify dependency apache#3932
Browse files Browse the repository at this point in the history
  • Loading branch information
cvictory committed May 13, 2019
1 parent 8e7f950 commit e23afa0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
8 changes: 8 additions & 0 deletions dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-multiple</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-monitor-api</artifactId>
Expand Down Expand Up @@ -567,6 +574,7 @@
<include>org.apache.dubbo:dubbo-registry-etcd3</include>
<include>org.apache.dubbo:dubbo-registry-nacos</include>
<include>org.apache.dubbo:dubbo-registry-sofa</include>
<include>org.apache.dubbo:dubbo-registry-multiple</include>
<include>org.apache.dubbo:dubbo-monitor-api</include>
<include>org.apache.dubbo:dubbo-monitor-default</include>
<include>org.apache.dubbo:dubbo-config-api</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, Registry> serviceRegistries = new HashMap<String, Registry>(4);
Expand All @@ -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<String>());
Expand Down Expand Up @@ -160,13 +162,16 @@ public List<URL> lookup(URL url) {
List<URL> urls = new ArrayList<URL>();
for (Registry registry : referenceRegistries.values()) {
List<URL> tmpUrls = registry.lookup(url);
if (tmpUrls != null && !tmpUrls.isEmpty()) {
if (!CollectionUtils.isEmpty(tmpUrls)) {
urls.addAll(tmpUrls);
}
}
return urls;
}

protected void init(){
}

protected List<String> filterServiceRegistry(List<String> serviceRegistryURLs) {
return serviceRegistryURLs;
}
Expand All @@ -176,6 +181,7 @@ protected List<String> filterReferenceRegistry(List<String> referenceRegistryURL
}

protected synchronized void refreshServiceRegistry(List<String> serviceRegistryURLs) {
this.effectServiceRegistryURLs = serviceRegistryURLs;
doRefreshRegistry(serviceRegistryURLs, serviceRegistries, () -> this.getRegisteredURLs(),
(registry, registeredURLs) -> {
for (URL url : (Set<URL>) registeredURLs) {
Expand All @@ -193,6 +199,7 @@ protected synchronized void refreshServiceRegistry(List<String> serviceRegistryU
}

protected synchronized void refreshReferenceRegistry(List<String> referenceRegistryURLs) {
this.effectReferenceRegistryURLs = referenceRegistryURLs;
doRefreshRegistry(referenceRegistryURLs, referenceRegistries, () -> this.getSubscribedURLMap(),
(registry, registeredURLs) -> {
for (Map.Entry<URL, Set<NotifyListener>> urlNotifyListenerMap : ((Map<URL, Set<NotifyListener>>) registeredURLs).entrySet()) {
Expand Down Expand Up @@ -257,7 +264,7 @@ private synchronized void doRefreshRegistry(List<String> newRegistryURLs, Map<St
removedRegistries.add(origRegistryEntry.getValue());
}
}
// unregister by remove registry
// unregister/unsubscribe by remove registry
for (Registry removedRegistry : removedRegistries) {
leftConsumer.accept(removedRegistry, registeredURLs);
}
Expand All @@ -271,7 +278,9 @@ private Set<URL> 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();
Expand All @@ -284,10 +293,12 @@ private Map<URL, Set<NotifyListener>> 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) {
Expand All @@ -312,4 +323,12 @@ public List<String> getOrigServiceRegistryURLs() {
public List<String> getOrigReferenceRegistryURLs() {
return origReferenceRegistryURLs;
}

public List<String> getEffectServiceRegistryURLs() {
return effectServiceRegistryURLs;
}

public List<String> getEffectReferenceRegistryURLs() {
return effectReferenceRegistryURLs;
}
}

0 comments on commit e23afa0

Please sign in to comment.