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 2023/08/29 08:14:58 UTC

[dubbo] branch 3.2 updated: enhance application discovery toString (#12953)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new c12a57eb3c enhance application discovery toString (#12953)
c12a57eb3c is described below

commit c12a57eb3c5593b735ea342c99b5981188d5720d
Author: TomlongTK <lo...@maoyan.com>
AuthorDate: Tue Aug 29 16:14:52 2023 +0800

    enhance application discovery toString (#12953)
---
 .../dubbo/rpc/cluster/directory/AbstractDirectory.java       |  4 +---
 .../dubbo/registry/client/ServiceDiscoveryRegistry.java      |  8 +++-----
 .../registry/client/ServiceDiscoveryRegistryDirectory.java   | 12 ++++++++++--
 .../apache/dubbo/registry/integration/DynamicDirectory.java  |  2 +-
 4 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
index 4ffe016d12..8f5875333f 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
@@ -224,10 +224,8 @@ public abstract class AbstractDirectory<T> implements Directory<T> {
 
                 logger.warn(CLUSTER_NO_VALID_PROVIDER, "provider server or registry center crashed", "",
                     "No provider available after connectivity filter for the service " + getConsumerUrl().getServiceKey()
-                        + " All validInvokers' size: " + validInvokers.size()
                         + " All routed invokers' size: " + routedResult.size()
-                        + " All invokers' size: " + invokers.size()
-                        + " from registry " + getUrl().getAddress()
+                        + " from registry " + this
                         + " on the consumer " + NetUtils.getLocalHost()
                         + " using the dubbo version " + Version.getVersion() + ".");
             }
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 95a196466e..ec125e37be 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
@@ -133,10 +133,8 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
 
         boolean should = PROVIDER_SIDE.equals(side); // Only register the Provider.
 
-        if (!should) {
-            if (logger.isDebugEnabled()) {
-                logger.debug(String.format("The URL[%s] should not be registered.", providerURL));
-            }
+        if (!should && logger.isDebugEnabled()) {
+            logger.debug(String.format("The URL[%s] should not be registered.", providerURL));
         }
 
         if (!acceptable(providerURL)) {
@@ -394,7 +392,7 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
             Lock mappingLock = serviceNameMapping.getMappingLock(event.getServiceKey());
             try {
                 mappingLock.lock();
-                if (CollectionUtils.isEmpty(tempOldApps) && newApps.size() > 0) {
+                if (CollectionUtils.isEmpty(tempOldApps) && !newApps.isEmpty()) {
                     serviceNameMapping.putCachedMapping(ServiceNameMapping.buildMappingKey(url), newApps);
                     subscribeURLs(url, listener, newApps);
                     oldApps = newApps;
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java
index d5168aaf7c..5dbfac3ce8 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java
@@ -584,7 +584,7 @@ public class ServiceDiscoveryRegistryDirectory<T> extends DynamicDirectory<T> {
         }
 
         void addNotifyListener(ServiceDiscoveryRegistryDirectory<?> listener) {
-            if (listeners.size() == 0) {
+            if (listeners.isEmpty()) {
                 this.initWith(moduleModel.getApplicationModel().getApplicationName() + CONFIGURATORS_SUFFIX);
             }
             this.listeners.add(listener);
@@ -592,7 +592,7 @@ public class ServiceDiscoveryRegistryDirectory<T> extends DynamicDirectory<T> {
 
         void removeNotifyListener(ServiceDiscoveryRegistryDirectory<?> listener) {
             this.listeners.remove(listener);
-            if (listeners.size() == 0) {
+            if (listeners.isEmpty()) {
                 this.stopListen(moduleModel.getApplicationModel().getApplicationName() + CONFIGURATORS_SUFFIX);
             }
         }
@@ -693,4 +693,12 @@ public class ServiceDiscoveryRegistryDirectory<T> extends DynamicDirectory<T> {
         }
     }
 
+    @Override
+    public String toString() {
+        return "ServiceDiscoveryRegistryDirectory(" +
+            "registry: " + getUrl().getAddress() +
+            ", subscribed key: " + (serviceListener == null || CollectionUtils.isEmpty(serviceListener.getServiceNames())
+            ? getConsumerUrl().getServiceKey() : serviceListener.getServiceNames().toString()) +
+            ")-" + super.toString();
+    }
 }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
index 7ee4da0ed8..1f57e972d7 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
@@ -195,7 +195,7 @@ public abstract class DynamicDirectory<T> extends AbstractDirectory<T> implement
         if (forbidden && shouldFailFast) {
             // 1. No service provider 2. Service providers are disabled
             throw new RpcException(RpcException.FORBIDDEN_EXCEPTION, "No provider available from registry " +
-                getUrl().getAddress() + " for service " + getConsumerUrl().getServiceKey() + " on consumer " +
+                this + " for service " + getConsumerUrl().getServiceKey() + " on consumer " +
                 NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() +
                 ", please check status of providers(disabled, not registered or in blacklist).");
         }