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/10/09 07:23:29 UTC
[dubbo] branch 3.0 updated: optimize for AbstractRegistry (#8971)
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 48c22fd optimize for AbstractRegistry (#8971)
48c22fd is described below
commit 48c22fdb578c1ec2a3fb9d9aad3351d3a8e548d6
Author: Wang Chengming <63...@qq.com>
AuthorDate: Sat Oct 9 15:23:12 2021 +0800
optimize for AbstractRegistry (#8971)
---
.../main/java/org/apache/dubbo/registry/Constants.java | 6 ++++++
.../dubbo/registry/support/AbstractRegistry.java | 18 +++++++++++-------
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java
index b6a3b27..6f053e0 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java
@@ -129,4 +129,10 @@ public interface Constants {
String MIGRATION_RULE_INTERFACES_KEY = "interfaces";
String MIGRATION_RULE_APPLICATIONS_KEY = "applications";
+
+ String USER_HOME = "user.home";
+
+ String DUBBO_REGISTRY = "/.dubbo/dubbo-registry-";
+
+ String CACHE = ".cache";
}
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 6cbc84a..9232c16 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
@@ -61,7 +61,10 @@ import static org.apache.dubbo.common.constants.RegistryConstants.ACCEPTS_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY;
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL;
+import static org.apache.dubbo.registry.Constants.CACHE;
+import static org.apache.dubbo.registry.Constants.DUBBO_REGISTRY;
import static org.apache.dubbo.registry.Constants.REGISTRY_FILESAVE_SYNC_KEY;
+import static org.apache.dubbo.registry.Constants.USER_HOME;
/**
* AbstractRegistry. (SPI, Prototype, ThreadSafe)
@@ -80,13 +83,13 @@ public abstract class AbstractRegistry implements Registry {
private final Properties properties = new Properties();
// File cache timing writing
private final ExecutorService registryCacheExecutor = Executors.newFixedThreadPool(1, new NamedThreadFactory("DubboSaveRegistryCache", true));
- // Is it synchronized to save the file
- private boolean syncSaveFile;
private final AtomicLong lastCacheChanged = new AtomicLong();
private final AtomicInteger savePropertiesRetryTimes = new AtomicInteger();
private final Set<URL> registered = new ConcurrentHashSet<>();
private final ConcurrentMap<URL, Set<NotifyListener>> subscribed = new ConcurrentHashMap<>();
private final ConcurrentMap<URL, Map<String, List<URL>>> notified = new ConcurrentHashMap<>();
+ // Is it synchronized to save the file
+ private boolean syncSaveFile;
private URL registryUrl;
// Local disk cache file
private File file;
@@ -100,7 +103,8 @@ public abstract class AbstractRegistry implements Registry {
if (localCacheEnabled) {
// Start file save timer
syncSaveFile = url.getParameter(REGISTRY_FILESAVE_SYNC_KEY, false);
- String defaultFilename = System.getProperty("user.home") + "/.dubbo/dubbo-registry-" + url.getApplication() + "-" + url.getAddress().replaceAll(":", "-") + ".cache";
+ String defaultFilename = System.getProperty(USER_HOME) + DUBBO_REGISTRY +
+ url.getApplication() + "-" + url.getAddress().replaceAll(":", "-") + CACHE;
String filename = url.getParameter(FILE_KEY, defaultFilename);
File file = null;
if (ConfigUtils.isNotEmpty(filename)) {
@@ -240,8 +244,8 @@ public abstract class AbstractRegistry implements Registry {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
if (StringUtils.isNotEmpty(key) && key.equals(url.getServiceKey())
- && (Character.isLetter(key.charAt(0)) || key.charAt(0) == '_')
- && StringUtils.isNotEmpty(value)) {
+ && (Character.isLetter(key.charAt(0)) || key.charAt(0) == '_')
+ && StringUtils.isNotEmpty(value)) {
String[] arr = value.trim().split(URL_SPLIT);
List<URL> urls = new ArrayList<>();
for (String u : arr) {
@@ -408,7 +412,7 @@ public abstract class AbstractRegistry implements Registry {
throw new IllegalArgumentException("notify listener == null");
}
if ((CollectionUtils.isEmpty(urls))
- && !ANY_VALUE.equals(url.getServiceInterface())) {
+ && !ANY_VALUE.equals(url.getServiceInterface())) {
logger.warn("Ignore empty notify urls for subscribe url " + url);
return;
}
@@ -517,7 +521,7 @@ public abstract class AbstractRegistry implements Registry {
}
return Arrays.stream(COMMA_SPLIT_PATTERN.split(pattern))
- .anyMatch(p -> p.equalsIgnoreCase(urlToRegistry.getProtocol()));
+ .anyMatch(p -> p.equalsIgnoreCase(urlToRegistry.getProtocol()));
}
@Override