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 0b0b83f962877cbf4d84df4b7ce862cf6d924e7a
Merge: 5817ac7 27ba1c7
Author: ken.lj <ken.lj...@gmail.com>
AuthorDate: Mon Aug 26 21:15:16 2019 +0800

    Merge remote-tracking branch 'origin/cloud-native' into cloud-native
    
    # Conflicts:
    #   
dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
    #   
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
    #   
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java

 .../DubboServiceProviderMinimumBootstrap.java      |  10 +-
 .../NacosDubboServiceConsumerBootstrap.java        |   4 +-
 .../NacosDubboServiceProviderBootstrap.java        |   4 +-
 ...=> ZookeeperDubboServiceConsumerBootstrap.java} |  20 +-
 ...=> ZookeeperDubboServiceProviderBootstrap.java} |  16 +-
 .../support/nacos/NacosDynamicConfiguration.java   |  71 +++-
 .../nacos/NacosDynamicConfigurationTest.java       |  13 +
 .../dubbo/registry/client/ServiceDiscovery.java    |  13 +-
 .../registry/client/ServiceDiscoveryRegistry.java  | 371 ++++++++++++++-------
 .../CompositeMetadataServiceURLBuilder.java        |   4 +-
 .../metadata/ProtocolPortsMetadataCustomizer.java  |  51 +++
 .../metadata/ServiceInstanceMetadataUtils.java     | 112 ++++---
 .../StandardMetadataServiceURLBuilder.java         |  20 +-
 .../client/metadata/URLRevisionResolver.java       |  58 +++-
 .../metadata/proxy/MetadataServiceProxy.java       | 122 -------
 .../selector/RandomServiceInstanceSelector.java    |   2 +-
 ...dubbo.registry.client.ServiceInstanceCustomizer |   1 +
 dubbo-registry/dubbo-registry-eureka/pom.xml       |  13 +
 18 files changed, 561 insertions(+), 344 deletions(-)

diff --cc 
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
index af7ec91,84b5a75..d41e4bc
--- 
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
@@@ -37,10 -37,9 +37,9 @@@ import org.apache.dubbo.registry.suppor
  
  import java.util.ArrayList;
  import java.util.Collection;
- import java.util.Collections;
  import java.util.HashMap;
- import java.util.Iterator;
 -import java.util.HashSet;
  import java.util.LinkedHashMap;
++import java.util.HashSet;
  import java.util.LinkedHashSet;
  import java.util.LinkedList;
  import java.util.List;
@@@ -51,13 -51,15 +51,14 @@@ import java.util.stream.Collectors
  
  import static java.lang.String.format;
  import static java.util.Collections.emptyList;
 -import static java.util.Collections.emptySet;
 -import static java.util.Collections.unmodifiableSet;
 -import static java.util.stream.Collectors.toSet;
  import static java.util.stream.Stream.of;
- import static 
org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
 +import static 
org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+ import static org.apache.dubbo.common.URLBuilder.from;
  import static 
org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL;
 +import static 
org.apache.dubbo.common.constants.CommonConstants.GROUP_CHAR_SEPERATOR;
  import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
  import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
+ import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY;
  import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
  import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
  import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
@@@ -303,7 -297,7 +310,7 @@@ public class ServiceDiscoveryRegistry e
          subscribeURLs(url, listener, serviceName, serviceInstances);
  
          // register ServiceInstancesChangedListener
-         registerServiceInstancesChangedListener(new 
ServiceInstancesChangedListener(serviceName, 
subscribedServices.get(serviceName)) {
 -        registerServiceInstancesChangedListener(url, new 
ServiceInstancesChangedListener(serviceName) {
++        registerServiceInstancesChangedListener(url, new 
ServiceInstancesChangedListener(serviceName, 
subscribedServices.get(serviceName)) {
  
              @Override
              public void onEvent(ServiceInstancesChangedEvent event) {
@@@ -336,59 -336,29 +349,28 @@@
          listener.notify(subscribedURLs);
      }
  
 -    private List<URL> getSubscribedURLs(URL subscribedURL, 
Collection<ServiceInstance> instances) {
 +    private List<URL> getSubscribedURLs(URL subscribedURL, 
Collection<ServiceInstance> instances, String serviceName) {
  
-         List<URL> subscribedURLs = new LinkedList<>();
- 
          // local service instances could be mutable
          List<ServiceInstance> serviceInstances = instances.stream()
                  .filter(ServiceInstance::isEnabled)
                  .filter(ServiceInstance::isHealthy)
 -                .filter(ServiceInstanceMetadataUtils::isDubboServiceInstance)
                  .collect(Collectors.toList());
  
-         /**
-          * A caches all revisions of exported services in different {@link 
ServiceInstance}s
-          * associating with the {@link URL urls}
-          */
-         Map<String, List<URL>> revisionURLsCache = new HashMap<>();
- 
-         if 
(ServiceInstanceMetadataUtils.isDubboServiceInstance(serviceInstances.get(0))) {
-             // try to get the exported URLs from every instance until it's 
successful.
-             for (int i = 0; i < serviceInstances.size(); i++) {
-                 // select a instance of {@link ServiceInstance}
-                 ServiceInstance selectedInstance = 
selectServiceInstance(serviceInstances);
-                 List<URL> templateURLs = getTemplateURLs(subscribedURL, 
selectedInstance, revisionURLsCache);
-                 if (isNotEmpty(templateURLs)) {
-                     // add templateURLs into subscribedURLs
-                     subscribedURLs.addAll(templateURLs);
-                     // remove the selected ServiceInstance in this time, it 
remains N - 1 elements.
-                     serviceInstances.remove(selectedInstance);
-                     break;
-                 }
-             }
+         int size = serviceInstances.size();
  
-             // Clone the subscribed URLs from the template URLs
-             List<URL> clonedURLs = cloneSubscribedURLs(subscribedURL, 
serviceInstances, revisionURLsCache);
-             // Add all cloned URLs into subscribedURLs
-             subscribedURLs.addAll(clonedURLs);
-             // clear all revisions
-             revisionURLsCache.clear();
-         } else {
-             for (ServiceInstance instance : serviceInstances) {
-                 URLBuilder builder = new URLBuilder(
-                         subscribedServices.get(serviceName),
-                         instance.getHost(),
-                         instance.getPort(),
-                         subscribedURL.getServiceInterface(),
-                         instance.getMetadata()
-                 );
-                 builder.addParameter(APPLICATION_KEY, serviceName);
-                 subscribedURLs.add(builder.build());
-             }
+         if (size == 0) {
+             return emptyList();
          }
+ 
+         expungeStaleRevisionExportedURLs(serviceInstances);
+ 
+         initTemplateURLs(subscribedURL, serviceInstances);
+ 
+         // Clone the subscribed URLs from the template URLs
+         List<URL> subscribedURLs = cloneSubscribedURLs(subscribedURL, 
serviceInstances);
          // clear local service instances
          serviceInstances.clear();
- 
          return subscribedURLs;
      }
  
diff --cc 
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
index 98f9d14,a180cb7..31a3e1d
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java
@@@ -28,11 -29,14 +29,14 @@@ import java.util.LinkedHashMap
  import java.util.List;
  import java.util.Map;
  
- import static java.lang.String.valueOf;
  import static java.util.Collections.emptyMap;
 +import static 
org.apache.dubbo.common.constants.CommonConstants.METADATA_DEFAULT;
+ import static 
org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
+ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
+ import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
  import static org.apache.dubbo.common.utils.StringUtils.isBlank;
 -import static 
org.apache.dubbo.metadata.WritableMetadataService.DEFAULT_METADATA_STORAGE_TYPE;
  import static 
org.apache.dubbo.registry.integration.RegistryProtocol.DEFAULT_REGISTER_PROVIDER_KEYS;
+ import static org.apache.dubbo.rpc.Constants.DEPRECATED_KEY;
  
  /**
   * The Utilities class for the {@link ServiceInstance#getMetadata() metadata 
of the service instance}

Reply via email to