Skip to content

Commit

Permalink
Dubbo cloud native (#4923)
Browse files Browse the repository at this point in the history
* Polish #4542 : [Enhancement] Adapt the Java standard Event/Listener mechanism

* Polish #4541 : [Feature] Add local File System DynamicConfigurationFactory‘s extension

* Polish #4541 : Bugfix

* Polish #4541 : Optimization

* Polish #4541 : Add the compatibility for PollingWatchService on the some platforms

* Polish #4541 : Add delay publish without ThreadPoolExecutor

* Polish #4541 : Refactor the extension name

* Polish #4541 : Add remove ops

* Polish #4541 : Add testable constructor

* Polish #4541 : Add getConfigGroups method

* Polish #4610 : [Refactor] Refactor the bootstrap module

* Polish #4541 : Fix the nulling URL issue

* Polish #4622 : [Refactor] Refactor ConfigManager

* Polish #4622 : [Refactor] Refactor ConfigManager

* Polish #4622 : Support multiple configcenters

* Polish #4671 : ServiceNameMapping will not map the group, version and protocol

* update referenceCount log (#4683)

Add comments to support multiple shared connections

* Polish /#4687 : Remove the duplicated test code in dubbo-config-spring (#4688)

* #4685  修改代码if判断false问题 if (hasException == false)修改成if (!hasException) (#4695)

* Fixed Service annotation method parameters are not in effect (#4598)

* keep demo simple, and switch to use zookeeper as registry center (#4705)

* keep demo simple, and switch to use zookeeper as registry center

* remove comment

* @reference auto-wires the instance of generic interface #4594 (#4677)

* try to shorten maven output to make travis build pass (#4710)

* use CountDownLatch to check zk registry if establish connection (#4589)

* Minor change

* Rename the extension name of WritableMetadataService

* Polish #4759 : [Refactor] Change the signature of methods of MetadataService #4759

* Merge remote-tracking branch 'upstream/master' into dubbo-cloud-native

# Conflicts:
#	dubbo-all/pom.xml
#	dubbo-bom/pom.xml
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
#	dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java
#	dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfiguration.java
#	dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfiguration.java
#	dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java
#	dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
#	dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
#	dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
#	dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java
#	dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java
#	dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java
#	dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
#	dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java
#	dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilder.java
#	dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilderTest.java
#	dubbo-metadata/pom.xml
#	dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java
#	dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
#	dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java
#	dubbo-rpc/dubbo-rpc-xml/src/main/java/org/apache/dubbo/xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java

* Polish #3984 : Add the implementation of Page<ServiceInstance> getInstances(String serviceName, int offset, int pageSize, boolean healthyOnly)

* Code merge

* Fix the cases

* Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud-native

# Conflicts:
#	dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
#	dubbo-metadata/dubbo-metadata-definition-protobuf/pom.xml
#	dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java
#	dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryFactory.java
#	dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java

* Refactor ConfigManager

* Refactor ConfigManager

* Resolve the issues on ConfigManager

* Refactor and add test-cases for ConfigManager

* Polish #4774 : [Feature] Dubbo Cloud Native - To Support in Spring

* Polish #4808 : [Feature] Add the registered/unregistered event mechanism ShutdownHook

* Polish #4807 : [Feature] Add the callback mechanism ShutdownHook #4807

* Polish #4813 : [Feature] add Prioritized implementation for ServiceInstanceCustomizer

* Polish #4815 : [Feature] Add the ServiceLoader for Dubbo's services or components

* Polish #4815 : [Feature] Add the ServiceLoader for Dubbo's services or components

* Polish #4813 : [Feature] add Prioritized implementation for ServiceInstanceCustomizer

* Polish #4807 : Add sort implementation

* Refactor

* Refactor

* Polish #4845 : [Feature] Enhance the Event-Publishing feature to original ServiceDiscovery

* Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud-native

# Conflicts:
#	dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceDiscoveryFactory.java
#	dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java

* Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud-native

# Conflicts:
#	dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceDiscoveryFactory.java
#	dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java

* Polish #4854 : [Feature] MetadataService supports the Dubbo protocol under auto-increased port

* Polish #4857 : [Enhancement] Sync the Metadata storage type into ApplicationConfig

* Polish #4868 : [Enhancement] Refactor ConfigChangeEvent

* Polish #4868 : [Enhancement] Refactor ConfigChangeEvent

* Polish #4873 : [Feature] Add a conditional EventListener into Event Module

* Polish #4875 : [Feature] Refactor ServiceInstancesChangedListener

* Remove the cycle dependencies

* Remove the cycle dependencies

* Polish #4903 : [Feature] Set source into the BeanDefinition of Dubbo Config

* Polish #4902 : [Feature] Dubbo Cloud Native to Spring XML scenario

* Polish #4713 : Initial the new module and dependencies

* Polish #4690 : AnnotatedBeanDefinitionRegistryUtils#registerBeans can't remove the duplicated bean definitions

* Polish #4690 : AnnotatedBeanDefinitionRegistryUtils#registerBeans can't remove the duplicated bean definitions

* Polish #4690 : AnnotatedBeanDefinitionRegistryUtils#registerBeans can't remove the duplicated bean definitions

* Polish #4910 : [Feature] To suppoort DubboLifecycleComponentApplicationListener in Spring XML scenario

* Polish #4713 : Add Service discovery implementation for Eureka #4713

* Polish #4713 : Add Service registration and discovery implementation for Eureka

* Polish #4713 : Add Service registration and discovery implementation for Eureka

* Polish #4920 : [Refactor] Extract the common implementation for URLs' revision
  • Loading branch information
mercyblitz authored Aug 23, 2019
1 parent a3aa6c1 commit d105b74
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@
*/
package org.apache.dubbo.registry.client.metadata;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.compiler.support.ClassUtils;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.ServiceInstanceMetadataCustomizer;

import java.util.Arrays;
import java.util.Collection;
import java.util.SortedSet;

import static java.lang.String.valueOf;
import static java.util.Objects.hash;
import static org.apache.dubbo.metadata.WritableMetadataService.getExtension;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.EXPORTED_SERVICES_REVISION_KEY;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.EXPORTED_SERVICES_REVISION_PROPERTY_NAME;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataStorageType;

/**
Expand All @@ -44,7 +37,7 @@ public class ExportedServicesRevisionMetadataCustomizer extends ServiceInstanceM

@Override
protected String buildMetadataKey(ServiceInstance serviceInstance) {
return EXPORTED_SERVICES_REVISION_KEY;
return EXPORTED_SERVICES_REVISION_PROPERTY_NAME;
}

@Override
Expand All @@ -55,21 +48,9 @@ protected String buildMetadataValue(ServiceInstance serviceInstance) {
WritableMetadataService writableMetadataService = getExtension(metadataStorageType);

SortedSet<String> exportedURLs = writableMetadataService.getExportedURLs();
Object[] data = exportedURLs.stream()
.map(URL::valueOf) // String to URL
.map(URL::getServiceInterface) // get the service interface
.filter(this::isNotMetadataService) // filter not MetadataService interface
.map(ClassUtils::forName) // load business interface class
.map(Class::getMethods) // get all public methods from business interface
.map(Arrays::asList) // Array to List
.flatMap(Collection::stream) // flat Stream<Stream> to be Stream
.map(Object::toString) // Method to String
.sorted() // sort methods marking sure the calculation of reversion is stable
.toArray(); // Stream to Array
return valueOf(hash(data)); // calculate the hash code as reversion
}

private boolean isNotMetadataService(String serviceInterface) {
return !MetadataService.class.getName().equals(serviceInterface);
URLRevisionResolver resolver = new URLRevisionResolver();

return resolver.resolve(exportedURLs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import static org.apache.dubbo.metadata.MetadataService.toURLs;
import static org.apache.dubbo.metadata.WritableMetadataService.getExtension;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_URL_PARAMS_KEY;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceParameter;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataStorageType;

Expand All @@ -41,7 +41,7 @@ public class MetadataServiceURLParamsMetadataCustomizer extends ServiceInstanceM

@Override
public String buildMetadataKey(ServiceInstance serviceInstance) {
return METADATA_SERVICE_URL_PARAMS_KEY;
return METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public class ServiceInstanceMetadataUtils {
public static final String METADATA_SERVICE_PREFIX = "dubbo.metadata-service.";

/**
* The key of metadata JSON of {@link MetadataService}'s {@link URL}
* The property name of metadata JSON of {@link MetadataService}'s {@link URL}
*/
public static String METADATA_SERVICE_URL_PARAMS_KEY = METADATA_SERVICE_PREFIX + "url-params";
public static String METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME = METADATA_SERVICE_PREFIX + "url-params";

/**
* The {@link URL URLs} property name of {@link MetadataService} :
Expand All @@ -62,29 +62,29 @@ public class ServiceInstanceMetadataUtils {
public static final String METADATA_SERVICE_URLS_PROPERTY_NAME = METADATA_SERVICE_PREFIX + "urls";

/**
* The key of The revision for all exported Dubbo services.
* The property name of The revision for all exported Dubbo services.
*/
public static String EXPORTED_SERVICES_REVISION_KEY = "dubbo.exported-services.revision";
public static String EXPORTED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.exported-services.revision";

/**
* The key of The revision for all subscribed Dubbo services.
* The property name of The revision for all subscribed Dubbo services.
*/
public static String SUBSCRIBER_SERVICES_REVISION_KEY = "dubbo.subscribed-services.revision";
public static String SUBSCRIBER_SERVICES_REVISION_PROPERTY_NAME = "dubbo.subscribed-services.revision";

/**
* The key of metadata storage type.
* The property name of metadata storage type.
*/
public static String METADATA_STORAGE_TYPE_KEY = "dubbo.metadata.storage-type";
public static String METADATA_STORAGE_TYPE_PROPERTY_NAME = "dubbo.metadata.storage-type";

/**
* The {@link URL url's} parameter name of Dubbo Provider host
* The property name of {@link URL url's} parameter name of Dubbo Provider host
*/
public static final String HOST_PARAM_NAME = "provider.host";
public static final String PROVIDER_HOST_PROPERTY_NAME = "provider.host";

/**
* The {@link URL url's} parameter name of Dubbo Provider port
*/
public static final String PORT_PARAM_NAME = "provider.port";
public static final String PROVIDER_PORT_PROPERTY_NAME = "provider.port";

/**
* Get the multiple {@link URL urls'} parameters of {@link MetadataService MetadataService's} Metadata
Expand All @@ -95,7 +95,7 @@ public class ServiceInstanceMetadataUtils {
*/
public static Map<String, Map<String, Object>> getMetadataServiceURLsParams(ServiceInstance serviceInstance) {
Map<String, String> metadata = serviceInstance.getMetadata();
String param = metadata.get(METADATA_SERVICE_URL_PARAMS_KEY);
String param = metadata.get(METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME);
return isBlank(param) ? emptyMap() : (Map) JSON.parse(param);
}

Expand Down Expand Up @@ -153,11 +153,11 @@ private static Map<String, String> getParams(URL providerURL) {
}

public static String getProviderHost(Map<String, Object> params) {
return valueOf(params.get(HOST_PARAM_NAME));
return valueOf(params.get(PROVIDER_HOST_PROPERTY_NAME));
}

public static Integer getProviderPort(Map<String, Object> params) {
return Integer.valueOf(valueOf(params.get(PORT_PARAM_NAME)));
return Integer.valueOf(valueOf(params.get(PROVIDER_PORT_PROPERTY_NAME)));
}

/**
Expand All @@ -168,7 +168,7 @@ public static Integer getProviderPort(Map<String, Object> params) {
*/
public static String getExportedServicesRevision(ServiceInstance serviceInstance) {
Map<String, String> metadata = serviceInstance.getMetadata();
return metadata.get(EXPORTED_SERVICES_REVISION_KEY);
return metadata.get(EXPORTED_SERVICES_REVISION_PROPERTY_NAME);
}

/**
Expand All @@ -179,7 +179,7 @@ public static String getExportedServicesRevision(ServiceInstance serviceInstance
*/
public static String getSubscribedServicesRevision(ServiceInstance serviceInstance) {
Map<String, String> metadata = serviceInstance.getMetadata();
return metadata.get(SUBSCRIBER_SERVICES_REVISION_KEY);
return metadata.get(SUBSCRIBER_SERVICES_REVISION_PROPERTY_NAME);
}

/**
Expand All @@ -190,7 +190,7 @@ public static String getSubscribedServicesRevision(ServiceInstance serviceInstan
* {@link WritableMetadataService#DEFAULT_METADATA_STORAGE_TYPE}
*/
public static String getMetadataStorageType(URL registryURL) {
return registryURL.getParameter(METADATA_STORAGE_TYPE_KEY, DEFAULT_METADATA_STORAGE_TYPE);
return registryURL.getParameter(METADATA_STORAGE_TYPE_PROPERTY_NAME, DEFAULT_METADATA_STORAGE_TYPE);
}

/**
Expand All @@ -202,7 +202,7 @@ public static String getMetadataStorageType(URL registryURL) {
*/
public static String getMetadataStorageType(ServiceInstance serviceInstance) {
Map<String, String> metadata = serviceInstance.getMetadata();
return metadata.getOrDefault(METADATA_STORAGE_TYPE_KEY, DEFAULT_METADATA_STORAGE_TYPE);
return metadata.getOrDefault(METADATA_STORAGE_TYPE_PROPERTY_NAME, DEFAULT_METADATA_STORAGE_TYPE);
}

/**
Expand All @@ -213,7 +213,19 @@ public static String getMetadataStorageType(ServiceInstance serviceInstance) {
*/
public static void setMetadataStorageType(ServiceInstance serviceInstance, String metadataType) {
Map<String, String> metadata = serviceInstance.getMetadata();
metadata.put(METADATA_STORAGE_TYPE_KEY, metadataType);
metadata.put(METADATA_STORAGE_TYPE_PROPERTY_NAME, metadataType);
}

/**
* Is Dubbo Service instance or not
*
* @param serviceInstance {@link ServiceInstance service instance}
* @return if Dubbo Service instance, return <code>true</code>, or <code>false</code>
*/
public static boolean isDubboServiceInstance(ServiceInstance serviceInstance) {
Map<String, String> metadata = serviceInstance.getMetadata();
return metadata.containsKey(METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME)
|| metadata.containsKey(METADATA_SERVICE_URLS_PROPERTY_NAME);
}

/**
Expand All @@ -229,11 +241,11 @@ public static boolean isDubboServiceInstance(ServiceInstance serviceInstance) {
}

private static void setProviderHostParam(Map<String, String> params, URL providerURL) {
params.put(HOST_PARAM_NAME, providerURL.getHost());
params.put(PROVIDER_HOST_PROPERTY_NAME, providerURL.getHost());
}

private static void setProviderPortParam(Map<String, String> params, URL providerURL) {
params.put(PORT_PARAM_NAME, valueOf(providerURL.getPort()));
params.put(PROVIDER_PORT_PROPERTY_NAME, valueOf(providerURL.getPort()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@
*/
package org.apache.dubbo.registry.client.metadata;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.compiler.support.ClassUtils;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.ServiceInstanceMetadataCustomizer;

import java.util.Arrays;
import java.util.Collection;
import java.util.SortedSet;

import static java.lang.String.valueOf;
import static java.util.Objects.hash;
import static org.apache.dubbo.metadata.WritableMetadataService.getExtension;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.SUBSCRIBER_SERVICES_REVISION_KEY;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.SUBSCRIBER_SERVICES_REVISION_PROPERTY_NAME;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataStorageType;

/**
Expand All @@ -44,7 +37,7 @@ public class SubscribedServicesRevisionMetadataCustomizer extends ServiceInstanc

@Override
protected String buildMetadataKey(ServiceInstance serviceInstance) {
return SUBSCRIBER_SERVICES_REVISION_KEY;
return SUBSCRIBER_SERVICES_REVISION_PROPERTY_NAME;
}

@Override
Expand All @@ -55,21 +48,10 @@ protected String buildMetadataValue(ServiceInstance serviceInstance) {
WritableMetadataService writableMetadataService = getExtension(metadataStorageType);

SortedSet<String> subscribedURLs = writableMetadataService.getSubscribedURLs();
Object[] data = subscribedURLs.stream()
.map(URL::valueOf) // String to URL
.map(URL::getServiceInterface) // get the service interface
.filter(this::isNotMetadataService) // filter not MetadataService interface
.map(ClassUtils::forName) // load business interface class
.map(Class::getMethods) // get all public methods from business interface
.map(Arrays::asList) // Array to List
.flatMap(Collection::stream) // flat Stream<Stream> to be Stream
.map(Object::toString) // Method to String
.sorted() // sort methods marking sure the calculation of reversion is stable
.toArray(); // Stream to Array
return valueOf(hash(data)); // calculate the hash code as reversion
}

private boolean isNotMetadataService(String serviceInterface) {
return !MetadataService.class.getName().equals(serviceInterface);
URLRevisionResolver resolver = new URLRevisionResolver();

return resolver.resolve(subscribedURLs);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.registry.client.metadata;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.compiler.support.ClassUtils;
import org.apache.dubbo.metadata.MetadataService;

import java.util.Arrays;
import java.util.Collection;

import static org.apache.dubbo.common.utils.CollectionUtils.isEmpty;

/**
* A class to resolve the version from {@link URL URLs}
*
* @since 2.7.4
*/
public class URLRevisionResolver {

public static final String NO_REVISION = "N/A";

/**
* Resolve revision as {@link String}
*
* @param urls {@link URL#toFullString() strings} presenting the {@link URL URLs}
* @return non-null
*/
public String resolve(Collection<String> urls) {

if (isEmpty(urls)) {
return NO_REVISION;
}

return urls.stream()
.map(URL::valueOf) // String to URL
.map(URL::getServiceInterface) // get the service interface
.filter(this::isNotMetadataService) // filter not MetadataService interface
.map(ClassUtils::forName) // load business interface class
.map(Class::getMethods) // get all public methods from business interface
.map(Arrays::asList) // Array to List
.flatMap(Collection::stream) // flat Stream<Stream> to be Stream
.map(Object::toString) // Method to String
.sorted() // sort methods marking sure the calculation of reversion is stable
.map(URLRevisionResolver::hashCode) // generate Long hashCode
.reduce(Long::sum) // sum hashCode
.map(String::valueOf) // Long to String
.orElse(NO_REVISION); // NO_REVISION as default
}

private static long hashCode(String value) {
long h = 0;
char[] chars = value.toCharArray();
for (int i = 0; i < chars.length; i++) {
h = 31L * h + chars[i];
}
return h;
}

private boolean isNotMetadataService(String serviceInterface) {
return !MetadataService.class.getName().equals(serviceInterface);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.apache.dubbo.metadata.report.MetadataReportInstance;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils;

Expand All @@ -17,9 +16,7 @@
import java.util.SortedSet;
import java.util.TreeSet;

import static org.apache.dubbo.common.constants.CommonConstants.METADATA_REVISION;
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;

/**
* 2019-08-09
Expand All @@ -35,7 +32,7 @@ public class RemoteMetadataServiceProxy implements MetadataService {
public RemoteMetadataServiceProxy(ServiceInstance serviceInstance) {
this.serviceName = serviceInstance.getServiceName();
this.revision = serviceInstance.getMetadata()
.getOrDefault(ServiceInstanceMetadataUtils.EXPORTED_SERVICES_REVISION_KEY, "");
.getOrDefault(ServiceInstanceMetadataUtils.EXPORTED_SERVICES_REVISION_PROPERTY_NAME, "");
}

@Override
Expand Down
Loading

0 comments on commit d105b74

Please sign in to comment.