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/16 03:42:31 UTC
[dubbo] branch cloud-native updated: [Feature] Enhance the
Event-Publishing feature to original ServiceDiscovery (#4846)
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 d9cc75f [Feature] Enhance the Event-Publishing feature to original ServiceDiscovery (#4846)
d9cc75f is described below
commit d9cc75f65c2b61e66746ce462087c6e8e7692f12
Author: Mercy Ma <me...@gmail.com>
AuthorDate: Fri Aug 16 11:42:25 2019 +0800
[Feature] Enhance the Event-Publishing feature to original ServiceDiscovery (#4846)
* 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
---
.../client/DefaultServiceDiscoveryFactory.java | 18 ++++------
.../registry/client/ServiceDiscoveryRegistry.java | 41 ++++++++++++++--------
2 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceDiscoveryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceDiscoveryFactory.java
index 0d38ace..c5f5fe4 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceDiscoveryFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceDiscoveryFactory.java
@@ -33,21 +33,15 @@ import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoad
* @since 2.7.4
*/
public class DefaultServiceDiscoveryFactory extends AbstractServiceDiscoveryFactory {
-
- @Override
- protected ServiceDiscovery createDiscovery(URL connectionURL) {
- ServiceDiscovery serviceDiscovery = load(connectionURL);
- return new EventPublishingServiceDiscovery(serviceDiscovery);
- }
-
/**
- * Load the {@link ServiceDiscovery} by {@link URL#getProtocol() the protocol} from {@link URL connection URL}
+ * Create the {@link ServiceDiscovery} by {@link URL#getProtocol() the protocol} from {@link URL connection URL}
*
- * @param connectionURL the {@link URL url} to connect
- * @return non-null
+ * @param registryURL
+ * @return
*/
- private ServiceDiscovery load(URL connectionURL) {
- String protocol = connectionURL.getProtocol();
+ @Override
+ protected ServiceDiscovery createDiscovery(URL registryURL) {
+ String protocol = registryURL.getProtocol();
ExtensionLoader<ServiceDiscovery> loader = getExtensionLoader(ServiceDiscovery.class);
return loader.getOrDefaultExtension(protocol);
}
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 40d0a09..725963a 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
@@ -103,7 +103,7 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
public ServiceDiscoveryRegistry(URL registryURL) {
super(registryURL);
- this.serviceDiscovery = getServiceDiscovery(registryURL);
+ this.serviceDiscovery = createServiceDiscovery(registryURL);
this.subscribedServices = getSubscribedServices(registryURL);
this.serviceNameMapping = ServiceNameMapping.getDefaultExtension();
String metadataStorageType = getMetadataStorageType(registryURL);
@@ -120,14 +120,14 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
}
/**
- * Get the {@link ServiceDiscovery} from the connection {@link URL}
+ * Create the {@link ServiceDiscovery} from the registry {@link URL}
*
* @param registryURL the {@link URL} to connect the registry
* @return non-null
*/
- protected ServiceDiscovery getServiceDiscovery(URL registryURL) {
- ServiceDiscoveryFactory factory = getExtension(registryURL);
- ServiceDiscovery serviceDiscovery = factory.getServiceDiscovery(registryURL);
+ protected ServiceDiscovery createServiceDiscovery(URL registryURL) {
+ ServiceDiscovery originalServiceDiscovery = getServiceDiscovery(registryURL);
+ ServiceDiscovery serviceDiscovery = enhanceEventPublishing(originalServiceDiscovery);
execute(() -> {
serviceDiscovery.initialize(registryURL.addParameter(INTERFACE_KEY, ServiceDiscovery.class.getName())
.removeParameter(REGISTRY_TYPE_KEY));
@@ -135,6 +135,28 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
return serviceDiscovery;
}
+ /**
+ * Get the instance {@link ServiceDiscovery} from the registry {@link URL} using
+ * {@link ServiceDiscoveryFactory} SPI
+ *
+ * @param registryURL the {@link URL} to connect the registry
+ * @return
+ */
+ private ServiceDiscovery getServiceDiscovery(URL registryURL) {
+ ServiceDiscoveryFactory factory = getExtension(registryURL);
+ return factory.getServiceDiscovery(registryURL);
+ }
+
+ /**
+ * Enhance the original {@link ServiceDiscovery} with event publishing feature
+ *
+ * @param original the original {@link ServiceDiscovery}
+ * @return {@link EventPublishingServiceDiscovery} instance
+ */
+ private ServiceDiscovery enhanceEventPublishing(ServiceDiscovery original) {
+ return new EventPublishingServiceDiscovery(original);
+ }
+
protected boolean shouldRegister(URL providerURL) {
String side = providerURL.getParameter(SIDE_KEY);
@@ -506,13 +528,4 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
public static boolean supports(URL registryURL) {
return SERVICE_REGISTRY_TYPE.equalsIgnoreCase(registryURL.getParameter(REGISTRY_TYPE_KEY));
}
-
- /**
- * Get the instance of {@link ServiceDiscovery}
- *
- * @return non-null
- */
- public ServiceDiscovery getServiceDiscovery() {
- return serviceDiscovery;
- }
}