From c72cb016b4b2702aedb5a941a8b7adb10b5df89b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BB=B6?= <1060026287@qq.com> Date: Mon, 21 Dec 2020 09:42:11 +0800 Subject: [PATCH] Enhance log info and fix code checkstyle (#4529) * 1.fix code checkstyle check 2.enhance disconnect log info * log enhance * revert line --- .../nacos/api/remote/PayloadRegistry.java | 1 - .../client/config/impl/ClientWorker.java | 2 +- .../nacos/common/remote/client/RpcClient.java | 26 +++++++++++-------- .../naming/core/CatalogServiceV2Impl.java | 1 - 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/PayloadRegistry.java b/api/src/main/java/com/alibaba/nacos/api/remote/PayloadRegistry.java index ef6dcc07b..7a3bc9020 100644 --- a/api/src/main/java/com/alibaba/nacos/api/remote/PayloadRegistry.java +++ b/api/src/main/java/com/alibaba/nacos/api/remote/PayloadRegistry.java @@ -74,7 +74,6 @@ public class PayloadRegistry { inited = true; } - static void register(String type, Class clazz) { if (Modifier.isAbstract(clazz.getModifiers())) { return; diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java index f24c1ee4c..7e1fd9379 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java @@ -595,7 +595,7 @@ public class ClientWorker implements Closeable { @Override public void onDisConnect() { String taskId = rpcClientInner.getLabels().get("taskId"); - LOGGER.info("[0]clear listen context...", rpcClientInner.getName()); + LOGGER.info("[{}] clear listen context...", rpcClientInner.getName()); Collection values = cacheMap.get().values(); for (CacheData cacheData : values) { diff --git a/common/src/main/java/com/alibaba/nacos/common/remote/client/RpcClient.java b/common/src/main/java/com/alibaba/nacos/common/remote/client/RpcClient.java index 8069821b4..c811f5c92 100644 --- a/common/src/main/java/com/alibaba/nacos/common/remote/client/RpcClient.java +++ b/common/src/main/java/com/alibaba/nacos/common/remote/client/RpcClient.java @@ -119,14 +119,15 @@ public abstract class RpcClient implements Closeable { } /** - * Notify when client re connected. + * Notify when client disconnected. */ protected void notifyDisConnected() { - if (!connectionEventListeners.isEmpty()) { - LoggerUtils.printIfInfoEnabled(LOGGER, "Notify connection event listeners."); - for (ConnectionEventListener connectionEventListener : connectionEventListeners) { - connectionEventListener.onDisConnect(); - } + if (connectionEventListeners.isEmpty()) { + return; + } + LoggerUtils.printIfInfoEnabled(LOGGER, "Notify disconnected event to listeners"); + for (ConnectionEventListener connectionEventListener : connectionEventListeners) { + connectionEventListener.onDisConnect(); } } @@ -134,10 +135,12 @@ public abstract class RpcClient implements Closeable { * Notify when client new connected. */ protected void notifyConnected() { - if (!connectionEventListeners.isEmpty()) { - for (ConnectionEventListener connectionEventListener : connectionEventListeners) { - connectionEventListener.onConnected(); - } + if (connectionEventListeners.isEmpty()) { + return; + } + LoggerUtils.printIfInfoEnabled(LOGGER, "Notify connected event to listeners."); + for (ConnectionEventListener connectionEventListener : connectionEventListeners) { + connectionEventListener.onConnected(); } } @@ -256,7 +259,8 @@ public abstract class RpcClient implements Closeable { } if (connectToServer != null) { - LoggerUtils.printIfInfoEnabled(LOGGER, String.format("[%s] success to connect to server on start up", name)); + LoggerUtils + .printIfInfoEnabled(LOGGER, String.format("[%s] success to connect to server on start up", name)); this.currentConnection = connectToServer; rpcClientStatus.set(RpcClientStatus.RUNNING); eventLinkedBlockingQueue.offer(new ConnectionEvent(ConnectionEvent.CONNECTED)); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/CatalogServiceV2Impl.java b/naming/src/main/java/com/alibaba/nacos/naming/core/CatalogServiceV2Impl.java index 242c27f17..18aed94fe 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/CatalogServiceV2Impl.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/CatalogServiceV2Impl.java @@ -21,7 +21,6 @@ import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.pojo.Cluster; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.ServiceInfo; -import com.alibaba.nacos.api.naming.utils.NamingUtils; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.naming.core.v2.ServiceManager; import com.alibaba.nacos.naming.core.v2.index.ServiceStorage;