diff --git a/client/src/main/java/com/alibaba/nacos/client/config/http/ServerHttpAgent.java b/client/src/main/java/com/alibaba/nacos/client/config/http/ServerHttpAgent.java index f26135c1248..fb419366f9b 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/http/ServerHttpAgent.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/http/ServerHttpAgent.java @@ -65,8 +65,7 @@ public class ServerHttpAgent implements HttpAgent { public HttpResult httpGet(String path, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException { final long endTime = System.currentTimeMillis() + readTimeoutMs; - - boolean isSSL = false; + final boolean isSSL = false; do { try { 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 cb881d677d3..374cbc616d5 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 @@ -505,8 +505,6 @@ public void run() { } } - // ================= - public boolean isHealthServer() { return isHealthServer; } @@ -515,16 +513,16 @@ private void setHealthServer(boolean isHealthServer) { this.isHealthServer = isHealthServer; } - final ScheduledExecutorService executor; - final ExecutorService executorService; + private final ScheduledExecutorService executor; + private final ExecutorService executorService; /** * groupKey -> cacheData */ - AtomicReference> cacheMap = new AtomicReference>( + private final AtomicReference> cacheMap = new AtomicReference>( new HashMap()); - HttpAgent agent; - ConfigFilterChainManager configFilterChainManager; + private final HttpAgent agent; + private final ConfigFilterChainManager configFilterChainManager; private boolean isHealthServer = true; private double currentLongingTaskCount = 0; } diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java index 8e5e0d2d332..d92492d3af9 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java @@ -45,6 +45,8 @@ */ @SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule") public class NacosNamingService implements NamingService { + private static final String DEFAULT_PORT = "8080"; + /** * Each Naming instance should have different namespace. */ @@ -74,7 +76,6 @@ public NacosNamingService(String serverList) { } public NacosNamingService(Properties properties) { - init(properties); } @@ -147,7 +148,7 @@ private void initCacheDir() { cacheDir = System.getProperty("user.home") + "/nacos/naming/" + namespace; } } - + @Override public void registerInstance(String serviceName, String ip, int port) throws NacosException { registerInstance(serviceName, ip, port, Constants.DEFAULT_CLUSTER_NAME); diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/cache/ConcurrentDiskUtil.java b/client/src/main/java/com/alibaba/nacos/client/naming/cache/ConcurrentDiskUtil.java index ce21c440366..74ed569f9ba 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/cache/ConcurrentDiskUtil.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/cache/ConcurrentDiskUtil.java @@ -211,6 +211,6 @@ private static void sleep(int time) { } } - static final int RETRY_COUNT = 10; - static final int SLEEP_BASETIME = 10; + private static final int RETRY_COUNT = 10; + private static final int SLEEP_BASETIME = 10; } diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/core/HostReactor.java b/client/src/main/java/com/alibaba/nacos/client/naming/core/HostReactor.java index 444093de228..e43dd67634a 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/core/HostReactor.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/core/HostReactor.java @@ -36,9 +36,9 @@ */ public class HostReactor { - public static final long DEFAULT_DELAY = 1000L; + private static final long DEFAULT_DELAY = 1000L; - public long updateHoldInterval = 5000L; + private static final long UPDATE_HOLD_INTERVAL = 5000L; private final Map> futureMap = new HashMap>(); @@ -234,11 +234,11 @@ public ServiceInfo getServiceInfo(final String serviceName, final String cluster } else if (updatingMap.containsKey(serviceName)) { - if (updateHoldInterval > 0) { + if (UPDATE_HOLD_INTERVAL > 0) { // hold a moment waiting for update finish synchronized (serviceObj) { try { - serviceObj.wait(updateHoldInterval); + serviceObj.wait(UPDATE_HOLD_INTERVAL); } catch (InterruptedException e) { NAMING_LOGGER.error("[getServiceInfo] serviceName:" + serviceName + ", clusters:" + clusters, e); } diff --git a/client/src/main/java/com/alibaba/nacos/client/utils/EnvUtil.java b/client/src/main/java/com/alibaba/nacos/client/utils/EnvUtil.java index cf13bf20de2..f3c6671540d 100644 --- a/client/src/main/java/com/alibaba/nacos/client/utils/EnvUtil.java +++ b/client/src/main/java/com/alibaba/nacos/client/utils/EnvUtil.java @@ -86,28 +86,22 @@ public static String getSelfLocationTag() { return selfLocationTag; } - public static String listToString(List list) { - if (list == null) { + private static String listToString(List list) { + if (list == null || list.isEmpty()) { return null; } StringBuilder result = new StringBuilder(); - boolean first = true; - // 第一个前面不拼接"," for (String string : list) { - if (first) { - first = false; - } else { - result.append(","); - } result.append(string); + result.append(","); } - return result.toString(); + return result.toString().substring(0, result.length() - 1); } private static String selfAmorayTag; private static String selfVipserverTag; private static String selfLocationTag; - public final static String AMORY_TAG = "Amory-Tag"; - public final static String VIPSERVER_TAG = "Vipserver-Tag"; - public final static String LOCATION_TAG = "Location-Tag"; + private final static String AMORY_TAG = "Amory-Tag"; + private final static String VIPSERVER_TAG = "Vipserver-Tag"; + private final static String LOCATION_TAG = "Location-Tag"; } diff --git a/client/src/main/java/com/alibaba/nacos/client/utils/StringUtils.java b/client/src/main/java/com/alibaba/nacos/client/utils/StringUtils.java index 2fc915ad15a..d510bf5f1d7 100644 --- a/client/src/main/java/com/alibaba/nacos/client/utils/StringUtils.java +++ b/client/src/main/java/com/alibaba/nacos/client/utils/StringUtils.java @@ -38,7 +38,7 @@ public static boolean isBlank(String str) { return true; } for (int i = 0; i < strLen; i++) { - if ((Character.isWhitespace(str.charAt(i)) == false)) { + if (!Character.isWhitespace(str.charAt(i))) { return false; } } @@ -46,7 +46,6 @@ public static boolean isBlank(String str) { } public static boolean isNotBlank(String str) { - return !isBlank(str); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/cluster/ServerListManager.java b/naming/src/main/java/com/alibaba/nacos/naming/cluster/ServerListManager.java index b63ca6a96f5..639ea720374 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/cluster/ServerListManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/cluster/ServerListManager.java @@ -41,7 +41,7 @@ @Component("serverListManager") public class ServerListManager { - public static final int STABLE_PERIOD = 60 * 1000; + private static final int STABLE_PERIOD = 60 * 1000; @Autowired private SwitchDomain switchDomain; diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java index 0fc8279c56d..24a85f7f08a 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java @@ -235,10 +235,6 @@ public JSONObject beat(HttpServletRequest request) throws Exception { String clusterName = clientBeat.getCluster(); - if (StringUtils.isBlank(clusterName)) { - clusterName = UtilsAndCommons.DEFAULT_CLUSTER_NAME; - } - if (Loggers.DEBUG_LOG.isDebugEnabled()) { Loggers.DEBUG_LOG.debug("[CLIENT-BEAT] full arguments: beat: {}, serviceName: {}", clientBeat, serviceName); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/ServerStatusSynchronizer.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/ServerStatusSynchronizer.java index d7b2c0a46bf..8ec380a45ae 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/ServerStatusSynchronizer.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/ServerStatusSynchronizer.java @@ -18,6 +18,7 @@ import com.alibaba.nacos.naming.boot.RunningConfig; import com.ning.http.client.AsyncCompletionHandler; import com.ning.http.client.Response; +import org.springframework.util.StringUtils; import java.net.HttpURLConnection; import java.util.HashMap; @@ -31,7 +32,7 @@ public class ServerStatusSynchronizer implements Synchronizer { @Override public void send(final String serverIP, Message msg) { - if (serverIP == null) { + if (StringUtils.isEmpty(serverIP)) { return; }