You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/12/13 04:06:57 UTC
[dubbo] branch 2.7.5-release updated: [Bugfix] Refactor the default
timeout and change it for Nacos (#5476)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 2.7.5-release
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.7.5-release by this push:
new a901899 [Bugfix] Refactor the default timeout and change it for Nacos (#5476)
a901899 is described below
commit a90189937c9dbe1a5cdcca0d41112bce6f63ccf4
Author: Mercy Ma <me...@gmail.com>
AuthorDate: Fri Dec 13 12:06:43 2019 +0800
[Bugfix] Refactor the default timeout and change it for Nacos (#5476)
---
.../config/configcenter/DynamicConfiguration.java | 38 +++++++++++++++++-----
.../support/nacos/NacosDynamicConfiguration.java | 11 +++++--
2 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java
index 398ed6f..c532746 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java
@@ -52,7 +52,7 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
* @param listener configuration listener
*/
default void addListener(String key, ConfigurationListener listener) {
- addListener(key, DEFAULT_GROUP, listener);
+ addListener(key, getDefaultGroup(), listener);
}
@@ -63,7 +63,7 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
* @param listener configuration listener
*/
default void removeListener(String key, ConfigurationListener listener) {
- removeListener(key, DEFAULT_GROUP, listener);
+ removeListener(key, getDefaultGroup(), listener);
}
/**
@@ -88,14 +88,15 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
void removeListener(String key, String group, ConfigurationListener listener);
/**
- * Get the configuration mapped to the given key and the given group
+ * Get the configuration mapped to the given key and the given group with {@link #getDefaultTimeout() the default
+ * timeout}
*
* @param key the key to represent a configuration
* @param group the group where the key belongs to
* @return target configuration mapped to the given key and the given group
*/
default String getConfig(String key, String group) {
- return getConfig(key, group, -1L);
+ return getConfig(key, group, getDefaultTimeout());
}
/**
@@ -111,10 +112,11 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
String getConfig(String key, String group, long timeout) throws IllegalStateException;
/**
- * This method are mostly used to get a compound config file, such as a complete dubbo.properties file.
+ * This method are mostly used to get a compound config file with {@link #getDefaultTimeout() the default timeout},
+ * such as a complete dubbo.properties file.
*/
default String getProperties(String key, String group) throws IllegalStateException {
- return getProperties(key, group, -1L);
+ return getProperties(key, group, getDefaultTimeout());
}
/**
@@ -127,7 +129,7 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
}
/**
- * Publish Config mapped to the given key under the {@link #DEFAULT_GROUP default group}
+ * Publish Config mapped to the given key under the {@link #getDefaultGroup() default group}
*
* @param key the key to represent a configuration
* @param content the content of configuration
@@ -136,7 +138,7 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
* @since 2.7.5
*/
default boolean publishConfig(String key, String content) throws UnsupportedOperationException {
- return publishConfig(key, DEFAULT_GROUP, content);
+ return publishConfig(key, getDefaultGroup(), content);
}
/**
@@ -166,6 +168,26 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
}
/**
+ * Get the default group for the operations
+ *
+ * @return The default value is {@link #DEFAULT_GROUP "dubbo"}
+ * @since 2.7.5
+ */
+ default String getDefaultGroup() {
+ return DEFAULT_GROUP;
+ }
+
+ /**
+ * Get the default timeout for the operations in milliseconds
+ *
+ * @return The default value is <code>-1L</code>
+ * @since 2.7.5
+ */
+ default long getDefaultTimeout() {
+ return -1L;
+ }
+
+ /**
* Close the configuration
*
* @throws Exception
diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
index fb92a49..2227015 100644
--- a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
+++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
@@ -234,7 +234,7 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
String resolvedGroup = resolveGroup(group);
try {
- long nacosTimeout = timeout < 0 ? DEFAULT_TIMEOUT : timeout;
+ long nacosTimeout = timeout < 0 ? getDefaultTimeout() : timeout;
if (StringUtils.isEmpty(resolvedGroup)) {
resolvedGroup = DEFAULT_GROUP;
}
@@ -248,7 +248,7 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
@Override
public Object getInternalProperty(String key) {
try {
- return configService.getConfig(key, DEFAULT_GROUP, DEFAULT_TIMEOUT);
+ return configService.getConfig(key, DEFAULT_GROUP, getDefaultTimeout());
} catch (NacosException e) {
logger.error(e.getMessage());
}
@@ -260,7 +260,7 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
boolean published = false;
String resolvedGroup = resolveGroup(group);
try {
- String value = configService.getConfig(key, resolvedGroup, -1L);
+ String value = configService.getConfig(key, resolvedGroup, getDefaultTimeout());
if (StringUtils.isNotEmpty(value)) {
content = value + "," + content;
}
@@ -271,6 +271,11 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
return published;
}
+ @Override
+ public long getDefaultTimeout() {
+ return DEFAULT_TIMEOUT;
+ }
+
/**
* TODO Nacos does not support atomic update of the value mapped to a key.
*