You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/12/21 15:57:27 UTC
[dubbo] branch 3.0 updated: Fix the logic of removing REFER and EXPORT attributes from URL (#9372)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 40bb88e Fix the logic of removing REFER and EXPORT attributes from URL (#9372)
40bb88e is described below
commit 40bb88e26d63acd421f74300a48019b8b8e11624
Author: 灼华 <43...@users.noreply.github.com>
AuthorDate: Tue Dec 21 23:57:14 2021 +0800
Fix the logic of removing REFER and EXPORT attributes from URL (#9372)
* Fix the logic of removing REFER and EXPORT attributes from URL
* Remove file
* Remove unused import
---
.../src/main/java/org/apache/dubbo/common/URLBuilder.java | 6 ++++++
.../org/apache/dubbo/common/config/ConfigurationUtils.java | 4 ++--
.../config/configcenter/TreePathDynamicConfiguration.java | 2 +-
.../dubbo/config/deploy/DefaultApplicationDeployer.java | 12 ++++++------
.../dubbo/configcenter/support/zookeeper/CacheListener.java | 4 ----
.../support/zookeeper/ZookeeperDynamicConfiguration.java | 7 +------
.../apache/dubbo/metadata/report/MetadataReportFactory.java | 9 +++++++--
.../main/java/org/apache/dubbo/registry/RegistryFactory.java | 3 ++-
.../dubbo/registry/client/ServiceDiscoveryRegistry.java | 4 ----
.../org/apache/dubbo/registry/support/AbstractRegistry.java | 2 +-
.../dubbo/registry/support/AbstractRegistryFactory.java | 4 +++-
11 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java
index 2c934ce..3177ac1 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java
@@ -160,6 +160,12 @@ public final class URLBuilder extends ServiceConfigURL {
}
@Override
+ public URLBuilder removeAttribute(String key) {
+ attributes.remove(key);
+ return this;
+ }
+
+ @Override
public URLBuilder setProtocol(String protocol) {
this.protocol = protocol;
return this;
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
index 2f79aa2..fd25f03 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
@@ -106,7 +106,7 @@ public class ConfigurationUtils {
Configuration configuration = getGlobalConfiguration(scopeModel);
String value = StringUtils.trim(configuration.getString(SHUTDOWN_WAIT_KEY));
- if (value != null && value.length() > 0) {
+ if (StringUtils.isNotEmpty(value)) {
try {
timeout = Integer.parseInt(value);
} catch (Exception e) {
@@ -114,7 +114,7 @@ public class ConfigurationUtils {
}
} else {
value = StringUtils.trim(configuration.getString(SHUTDOWN_WAIT_SECONDS_KEY));
- if (value != null && value.length() > 0) {
+ if (StringUtils.isNotEmpty(value)) {
try {
timeout = Integer.parseInt(value) * 1000;
} catch (Exception e) {
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/TreePathDynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/TreePathDynamicConfiguration.java
index 09296b6..2c8a294 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/TreePathDynamicConfiguration.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/TreePathDynamicConfiguration.java
@@ -61,7 +61,7 @@ public abstract class TreePathDynamicConfiguration extends AbstractDynamicConfig
*/
public static final String DEFAULT_CONFIG_BASE_PATH = "/config";
- private final String rootPath;
+ protected final String rootPath;
public TreePathDynamicConfiguration(URL url) {
super(url);
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java
index 3688d67..518bd99 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java
@@ -357,7 +357,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
if (cc.getParameters() == null) {
cc.setParameters(new HashMap<>());
}
- if (registryConfig.getParameters() != null) {
+ if (CollectionUtils.isNotEmptyMap(registryConfig.getParameters())) {
cc.getParameters().putAll(registryConfig.getParameters()); // copy the parameters
}
cc.getParameters().put(CLIENT_KEY, registryConfig.getClient());
@@ -467,7 +467,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
if (metadataReportConfig.getParameters() == null) {
metadataReportConfig.setParameters(new HashMap<>());
}
- if (registryConfig.getParameters() != null) {
+ if (CollectionUtils.isNotEmptyMap(registryConfig.getParameters())) {
metadataReportConfig.getParameters().putAll(registryConfig.getParameters()); // copy the parameters
}
metadataReportConfig.getParameters().put(CLIENT_KEY, registryConfig.getClient());
@@ -531,12 +531,12 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
boolean hasPendingModule = hasPendingModule();
if (isStarting()) {
- // currently is starting, maybe both start by module and application
- // if has new modules, start them
+ // currently, is starting, maybe both start by module and application
+ // if it has new modules, start them
if (hasPendingModule) {
startModules();
}
- // if is starting, reuse previous startFuture
+ // if it is starting, reuse previous startFuture
return startFuture;
}
@@ -685,7 +685,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
return null;
}
- DynamicConfiguration dynamicConfiguration = null;
+ DynamicConfiguration dynamicConfiguration;
try {
dynamicConfiguration = getDynamicConfiguration(configCenter.toUrl());
} catch (Exception e) {
diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/CacheListener.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/CacheListener.java
index 515b46c..fe34bd5 100644
--- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/CacheListener.java
+++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/CacheListener.java
@@ -32,10 +32,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
import static org.apache.dubbo.common.constants.CommonConstants.DOT_SEPARATOR;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
-/**
- *
- */
-
public class CacheListener implements DataListener {
private Map<String, Set<ConfigurationListener>> keyListeners = new ConcurrentHashMap<>();
diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java
index d755fd8..f2370e1 100644
--- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java
+++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java
@@ -40,27 +40,22 @@ import java.util.concurrent.TimeUnit;
public class ZookeeperDynamicConfiguration extends TreePathDynamicConfiguration {
private Executor executor;
- // The final root path would be: /configRootPath/"config"
- private String rootPath;
private ZookeeperClient zkClient;
private CacheListener cacheListener;
- private URL url;
private static final int DEFAULT_ZK_EXECUTOR_THREADS_NUM = 1;
private static final int DEFAULT_QUEUE = 10000;
private static final Long THREAD_KEEP_ALIVE_TIME = 0L;
ZookeeperDynamicConfiguration(URL url, ZookeeperTransporter zookeeperTransporter) {
super(url);
- this.url = url;
- rootPath = getRootPath(url);
this.cacheListener = new CacheListener(rootPath);
final String threadName = this.getClass().getSimpleName();
this.executor = new ThreadPoolExecutor(DEFAULT_ZK_EXECUTOR_THREADS_NUM, DEFAULT_ZK_EXECUTOR_THREADS_NUM,
THREAD_KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS,
- new LinkedBlockingQueue<Runnable>(DEFAULT_QUEUE),
+ new LinkedBlockingQueue<>(DEFAULT_QUEUE),
new NamedThreadFactory(threadName, true),
new AbortPolicyWithReport(threadName, url));
diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReportFactory.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReportFactory.java
index 78f98f6..a0e1bb2 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReportFactory.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/MetadataReportFactory.java
@@ -20,12 +20,17 @@ import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.SPI;
+import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
+import static org.apache.dubbo.metadata.report.MetadataReportFactory.DEFAULT;
+
/**
*/
-@SPI("redis")
+@SPI(DEFAULT)
public interface MetadataReportFactory {
- @Adaptive({"protocol"})
+ String DEFAULT = "redis";
+
+ @Adaptive({PROTOCOL_KEY})
MetadataReport getMetadataReport(URL url);
default void destroy() {
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryFactory.java
index 1075c8c..8ed918a 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryFactory.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.common.extension.SPI;
+import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.extension.ExtensionScope.APPLICATION;
/**
@@ -44,7 +45,7 @@ public interface RegistryFactory {
* @param url Registry address, is not allowed to be empty
* @return Registry reference, never return empty value
*/
- @Adaptive({"protocol"})
+ @Adaptive({PROTOCOL_KEY})
Registry getRegistry(URL url);
}
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 079653c..a4842cc 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
@@ -30,7 +30,6 @@ import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent;
import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;
import org.apache.dubbo.registry.client.metadata.SubscribedURLsSynthesizer;
import org.apache.dubbo.registry.support.FailbackRegistry;
-import org.apache.dubbo.registry.support.RegistryManager;
import java.util.ArrayList;
import java.util.Collections;
@@ -79,13 +78,10 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
/* apps - listener */
private final Map<String, ServiceInstancesChangedListener> serviceListeners = new ConcurrentHashMap<>();
- private RegistryManager registryManager;
-
public ServiceDiscoveryRegistry(URL registryURL) {
super(registryURL);
this.serviceDiscovery = createServiceDiscovery(registryURL);
this.writableMetadataService = WritableMetadataService.getDefaultExtension(registryURL.getScopeModel());
- this.registryManager = registryURL.getOrDefaultApplicationModel().getBeanFactory().getBean(RegistryManager.class);
}
// Currently, for test purpose
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
index 4c71d83..cc9e6f5 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
@@ -94,7 +94,7 @@ public abstract class AbstractRegistry implements Registry {
// Local disk cache file
private File file;
private boolean localCacheEnabled;
- private RegistryManager registryManager;
+ protected RegistryManager registryManager;
public AbstractRegistry(URL url) {
setUrl(url);
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
index 72cfdd3..2e3e62a 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
@@ -64,7 +64,9 @@ public abstract class AbstractRegistryFactory implements RegistryFactory, ScopeM
url = URLBuilder.from(url)
.setPath(RegistryService.class.getName())
.addParameter(INTERFACE_KEY, RegistryService.class.getName())
- .removeParameters(EXPORT_KEY, REFER_KEY, TIMESTAMP_KEY)
+ .removeParameter(TIMESTAMP_KEY)
+ .removeAttribute(EXPORT_KEY)
+ .removeAttribute(REFER_KEY)
.build();
String key = createRegistryCacheKey(url);
Registry registry = null;