You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by me...@apache.org on 2019/08/23 09:45:50 UTC
[dubbo] branch cloud-native updated: Dubbo cloud native (#4929)
This is an automated email from the ASF dual-hosted git repository.
mercyblitz pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/cloud-native by this push:
new 876d165 Dubbo cloud native (#4929)
876d165 is described below
commit 876d165ec216327b574c1f336c7da3896ad11bb5
Author: Mercy Ma <me...@gmail.com>
AuthorDate: Fri Aug 23 17:45:41 2019 +0800
Dubbo cloud native (#4929)
* Polish apache/dubbo#4542 : [Enhancement] Adapt the Java standard Event/Listener mechanism
* Polish apache/dubbo#4541 : [Feature] Add local File System DynamicConfigurationFactory‘s extension
* Polish apache#4541 : Bugfix
* Polish apache/dubbo#4541 : Optimization
* Polish apache/dubbo#4541 : Add the compatibility for PollingWatchService on the some platforms
* Polish apache/dubbo#4541 : Add delay publish without ThreadPoolExecutor
* Polish apache/dubbo#4541 : Refactor the extension name
* Polish apache/dubbo#4541 : Add remove ops
* Polish apache/dubbo#4541 : Add testable constructor
* Polish apache/dubbo#4541 : Add getConfigGroups method
* Polish apache/dubbo#4610 : [Refactor] Refactor the bootstrap module
* Polish apache/dubbo#4541 : Fix the nulling URL issue
* Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager
* Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager
* Polish apache/dubbo#4622 : Support multiple configcenters
* Polish apache/dubbo#4671 : ServiceNameMapping will not map the group, version and protocol
* update referenceCount log (#4683)
Add comments to support multiple shared connections
* Polish /apache/dubbo#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 apache/dubbo#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 apache/dubbo#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 apache/dubbo#4774 : [Feature] Dubbo Cloud Native - To Support in Spring
* Polish apache/dubbo#4808 : [Feature] Add the registered/unregistered event mechanism ShutdownHook
* Polish apache/dubbo#4807 : [Feature] Add the callback mechanism ShutdownHook #4807
* Polish apache/dubbo#4813 : [Feature] add Prioritized implementation for ServiceInstanceCustomizer
* Polish apache/dubbo#4815 : [Feature] Add the ServiceLoader for Dubbo's services or components
* Polish apache/dubbo#4815 : [Feature] Add the ServiceLoader for Dubbo's services or components
* Polish apache/dubbo#4813 : [Feature] add Prioritized implementation for ServiceInstanceCustomizer
* Polish apache/dubbo#4807 : Add sort implementation
* Refactor
* Refactor
* Polish apache/dubbo#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 apache/dubbo#4854 : [Feature] MetadataService supports the Dubbo protocol under auto-increased port
* Polish apache/dubbo#4857 : [Enhancement] Sync the Metadata storage type into ApplicationConfig
* Polish apache/dubbo#4868 : [Enhancement] Refactor ConfigChangeEvent
* Polish apache/dubbo#4868 : [Enhancement] Refactor ConfigChangeEvent
* Polish apache/dubbo#4873 : [Feature] Add a conditional EventListener into Event Module
* Polish apache/dubbo#4875 : [Feature] Refactor ServiceInstancesChangedListener
* Remove the cycle dependencies
* Remove the cycle dependencies
* Polish apache/dubbo#4903 : [Feature] Set source into the BeanDefinition of Dubbo Config
* Polish apache/dubbo#4902 : [Feature] Dubbo Cloud Native to Spring XML scenario
* Polish apache/dubbo#4713 : Initial the new module and dependencies
* Polish apache/dubbo#4690 : AnnotatedBeanDefinitionRegistryUtils#registerBeans can't remove the duplicated bean definitions
* Polish apache/dubbo#4690 : AnnotatedBeanDefinitionRegistryUtils#registerBeans can't remove the duplicated bean definitions
* Polish apache/dubbo#4690 : AnnotatedBeanDefinitionRegistryUtils#registerBeans can't remove the duplicated bean definitions
* Polish apache/dubbo#4910 : [Feature] To suppoort DubboLifecycleComponentApplicationListener in Spring XML scenario
* Polish apache/dubbo#4713 : Add Service discovery implementation for Eureka #4713
* Polish apache/dubbo#4713 : Add Service registration and discovery implementation for Eureka
* Polish apache/dubbo#4713 : Add Service registration and discovery implementation for Eureka
* Polish apache/dubbo#4920 : [Refactor] Extract the common implementation for URLs' revision
* Refactor
* Polish apache/dubbo#4925 : ServiceDiscovery limits only one ServiceInstancesChangedListener each service
* Polish apache/dubbo#4925 : ServiceDiscovery limits only one ServiceInstancesChangedListener each service
* Remove useless classes
---
.../dubbo/registry/client/ServiceDiscovery.java | 13 ++-
.../registry/client/ServiceDiscoveryRegistry.java | 14 ++-
.../CompositeMetadataServiceURLBuilder.java | 4 +-
.../metadata/proxy/MetadataServiceProxy.java | 122 ---------------------
4 files changed, 21 insertions(+), 132 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscovery.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscovery.java
index c556967..e8908e0 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscovery.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscovery.java
@@ -23,6 +23,7 @@ import org.apache.dubbo.common.utils.Page;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.event.EventDispatcher;
import org.apache.dubbo.event.EventListener;
+import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent;
import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;
@@ -198,16 +199,22 @@ public interface ServiceDiscovery extends Prioritized {
/**
* Add an instance of {@link ServiceInstancesChangedListener} for specified service
* <p>
- * Default, the ServiceInstancesChangedListener will be {@link EventDispatcher#addEventListener(EventListener) added}
- * into {@link EventDispatcher}
+ * Default, Current method will be invoked by {@link ServiceDiscoveryRegistry#subscribe(URL, NotifyListener)
+ * the ServiceDiscoveryRegistry on the subscription}, and it's mandatory to
+ * {@link EventDispatcher#addEventListener(EventListener) add} the {@link ServiceInstancesChangedListener} argument
+ * into {@link EventDispatcher} whether the subclass implements same approach or not, thus this method is used to
+ * trigger or adapt the vendor's change notification mechanism typically, like Zookeeper Watcher,
+ * Nacos EventListener. If the registry observes the change, It's suggested that the implementation could invoke
+ * {@link #dispatchServiceInstancesChangedEvent(String)} method or variants
*
* @param listener an instance of {@link ServiceInstancesChangedListener}
* @throws NullPointerException
* @throws IllegalArgumentException
+ * @see EventPublishingServiceDiscovery
+ * @see EventDispatcher
*/
default void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener)
throws NullPointerException, IllegalArgumentException {
- getDefaultExtension().addEventListener(listener);
}
/**
diff --git 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
index b4ba206..d30e59b 100644
--- 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
@@ -105,7 +105,7 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
private final WritableMetadataService writableMetadataService;
- private final Set<String> listenedServices = new LinkedHashSet<>();
+ private final Set<String> registeredListeners = new LinkedHashSet<>();
public ServiceDiscoveryRegistry(URL registryURL) {
super(registryURL);
@@ -287,7 +287,7 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
subscribeURLs(url, listener, serviceName, serviceInstances);
// register ServiceInstancesChangedListener
- registerServiceInstancesChangedListener(new ServiceInstancesChangedListener(serviceName) {
+ registerServiceInstancesChangedListener(url, new ServiceInstancesChangedListener(serviceName) {
@Override
public void onEvent(ServiceInstancesChangedEvent event) {
@@ -299,14 +299,20 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
/**
* Register the {@link ServiceInstancesChangedListener} If absent
*
+ * @param url {@link URL}
* @param listener the {@link ServiceInstancesChangedListener}
*/
- private void registerServiceInstancesChangedListener(ServiceInstancesChangedListener listener) {
- if (listenedServices.add(listener.getServiceName())) {
+ private void registerServiceInstancesChangedListener(URL url, ServiceInstancesChangedListener listener) {
+ String listenerId = createListenerId(url, listener);
+ if (registeredListeners.add(listenerId)) {
serviceDiscovery.addServiceInstancesChangedListener(listener);
}
}
+ private String createListenerId(URL url, ServiceInstancesChangedListener listener) {
+ return listener.getServiceName() + ":" + url.toString(VERSION_KEY, GROUP_KEY, PROTOCOL_KEY);
+ }
+
protected void subscribeURLs(URL subscribedURL, NotifyListener listener, String serviceName,
Collection<ServiceInstance> serviceInstances) {
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/CompositeMetadataServiceURLBuilder.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/CompositeMetadataServiceURLBuilder.java
index 8006c85..ef19d86 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/CompositeMetadataServiceURLBuilder.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/CompositeMetadataServiceURLBuilder.java
@@ -19,7 +19,6 @@ package org.apache.dubbo.registry.client.metadata;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.registry.client.ServiceInstance;
-import org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxy;
import java.util.Iterator;
import java.util.LinkedList;
@@ -34,10 +33,9 @@ import static org.apache.dubbo.common.utils.CollectionUtils.isNotEmpty;
/**
* The implementation of {@link MetadataServiceURLBuilder} composites the multiple {@link MetadataServiceURLBuilder}
* instances are loaded by Java standard {@link ServiceLoader} will aggregate {@link URL URLs} for
- * {@link MetadataServiceProxy}
+ * {@link MetadataService}
*
* @see MetadataServiceURLBuilder
- * @see MetadataServiceProxy
* @see MetadataService
* @see URL
* @see ServiceLoader
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxy.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxy.java
deleted file mode 100644
index a5b7384..0000000
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxy.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.proxy;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.metadata.MetadataService;
-import org.apache.dubbo.registry.client.ServiceInstance;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Protocol;
-import org.apache.dubbo.rpc.proxy.InvokerInvocationHandler;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.function.Function;
-
-import static java.lang.reflect.Proxy.newProxyInstance;
-import static org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilder.composite;
-
-/**
- * The Proxy object for the {@link MetadataService} whose {@link ServiceInstance} providers may export multiple
- * {@link Protocol protocols} at the same time.
- *
- * @see ServiceInstance
- * @see MetadataService
- * @since 2.7.4
- */
-public class MetadataServiceProxy implements MetadataService {
-
- private final Logger logger = LoggerFactory.getLogger(getClass());
-
- private final List<URL> urls;
-
- private final Protocol protocol;
-
- public MetadataServiceProxy(ServiceInstance serviceInstance, Protocol protocol) {
- this(composite().build(serviceInstance), protocol);
- }
-
- public MetadataServiceProxy(List<URL> urls, Protocol protocol) {
- this.urls = urls;
- this.protocol = protocol;
- }
-
- @Override
- public String serviceName() {
- return doInMetadataService(MetadataService::serviceName);
- }
-
- @Override
- public SortedSet<String> getExportedURLs(String serviceInterface, String group, String version, String protocol) {
- return doInMetadataService(metadataService ->
- metadataService.getExportedURLs(serviceInterface, group, version, protocol));
- }
-
- @Override
- public String getServiceDefinition(String interfaceName, String version, String group) {
- return doInMetadataService(metadataService ->
- metadataService.getServiceDefinition(interfaceName, version, group));
- }
-
- @Override
- public String getServiceDefinition(String serviceKey) {
- return doInMetadataService(metadataService ->
- metadataService.getServiceDefinition(serviceKey));
- }
-
- protected <T> T doInMetadataService(Function<MetadataService, T> callback) {
-
- T result = null; // execution result
-
- Throwable exception = null; // exception maybe present
-
- Iterator<URL> iterator = urls.iterator();
-
- while (iterator.hasNext()) { // Executes MetadataService's method until success
- URL url = iterator.next();
- Invoker<MetadataService> invoker = null;
- try {
- invoker = this.protocol.refer(MetadataService.class, url);
- MetadataService proxy = (MetadataService) newProxyInstance(getClass().getClassLoader(),
- new Class[]{MetadataService.class}, new InvokerInvocationHandler(invoker));
- result = callback.apply(proxy);
- exception = null;
- } catch (Throwable e) {
- exception = e;
- // If met with some error, invoke next
- if (logger.isErrorEnabled()) {
- logger.error(e.getMessage(), e);
- }
- } finally {
- if (invoker != null) {
- // to destroy the Invoker finally
- invoker.destroy();
- invoker = null;
- }
- }
- }
-
- if (exception != null) { // If all executions were failed
- throw new RuntimeException(exception.getMessage(), exception);
- }
-
- return result;
- }
-}