You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/08/27 01:27:13 UTC
[dubbo] 04/05: Merge remote-tracking branch 'origin/cloud-native'
into cloud-native
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 3707e1de5be96a7a53c778aced37f6cdc42c4868
Merge: f4d72ea edd37e3
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Aug 27 09:23:47 2019 +0800
Merge remote-tracking branch 'origin/cloud-native' into cloud-native
# Conflicts:
# dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
.../NacosDubboServiceConsumerBootstrap.java | 13 +---
.../registry/client/ServiceDiscoveryRegistry.java | 64 ++++++++++++---
.../RestProtocolSubscribedURLsSynthesizer.java | 91 ++++++++++++++++++++++
.../client/metadata/SubscribedURLsSynthesizer.java | 53 +++++++++++++
...istry.client.metadata.SubscribedURLsSynthesizer | 1 +
5 files changed, 203 insertions(+), 19 deletions(-)
diff --cc dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
index 0cfa520,581e388..5368b56
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
@@@ -345,12 -341,32 +354,32 @@@ public class ServiceDiscoveryRegistry e
return;
}
- List<URL> subscribedURLs = getSubscribedURLs(subscribedURL, serviceInstances, serviceName);
+ List<URL> subscribedURLs = new LinkedList<>();
+
+ /**
+ * Add the exported URLs from {@link MetadataService}
+ */
- subscribedURLs.addAll(getExportedURLs(subscribedURL, serviceInstances));
++ subscribedURLs.addAll(getExportedURLs(subscribedURL, serviceInstances, serviceName));
+
+ if (subscribedURLs.isEmpty()) { // If empty, try to synthesize
+ /**
+ * Add the subscribed URLs that were synthesized
+ */
+ subscribedURLs.addAll(synthesizeSubscribedURLs(subscribedURL, serviceInstances));
+ }
listener.notify(subscribedURLs);
}
- private List<URL> getSubscribedURLs(URL subscribedURL, Collection<ServiceInstance> instances, String serviceName) {
+ /**
+ * Get the exported {@link URL URLs} from the {@link MetadataService} in the specified
+ * {@link ServiceInstance service instances}
+ *
+ * @param subscribedURL the subscribed {@link URL url}
+ * @param instances {@link ServiceInstance service instances}
+ * @return the exported {@link URL URLs} if present, or <code>{@link Collections#emptyList() empty list}</code>
+ */
- private List<URL> getExportedURLs(URL subscribedURL, Collection<ServiceInstance> instances) {
++ private List<URL> getExportedURLs(URL subscribedURL, Collection<ServiceInstance> instances, String serviceName) {
// local service instances could be mutable
List<ServiceInstance> serviceInstances = instances.stream()
@@@ -683,13 -685,28 +712,28 @@@
return exportedURLs;
}
+ /**
+ * Synthesize new subscribed {@link URL URLs} from old one
+ *
+ * @param subscribedURL
+ * @param serviceInstances
+ * @return non-null
+ */
+ private Collection<? extends URL> synthesizeSubscribedURLs(URL subscribedURL, Collection<ServiceInstance> serviceInstances) {
+ return subscribedURLsSynthesizers.stream()
+ .filter(synthesizer -> synthesizer.supports(subscribedURL))
+ .map(synthesizer -> synthesizer.synthesize(subscribedURL, serviceInstances))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toList());
+ }
+
- protected Set<String> getServices(URL subscribedURL) {
- Set<String> serviceNames = getSubscribedServices();
- if (isEmpty(serviceNames)) {
- serviceNames = findMappedServices(subscribedURL);
+ protected Map<String, String> getServices(URL subscribedURL) {
+ Map<String, String> services = getSubscribedServices();
+ if (isEmptyMap(services)) {
+ services = findMappedServices(subscribedURL);
}
- return serviceNames;
+ return services;
}
/**