From 27ed66869554c8768a25ee3de671e2ff0f67f32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=99=93=E5=8F=8C=20Li=20Xiao=20Shuang?= <644968328@qq.com> Date: Fri, 7 Jan 2022 18:09:55 +0800 Subject: [PATCH] Strengthen the code (#7511) --- .../task/engine/AbstractNacosTaskExecuteEngine.java | 2 +- .../common/task/engine/NacosDelayTaskExecuteEngine.java | 2 +- .../config/server/service/dump/DumpConfigHandler.java | 2 +- .../nacos/config/server/service/dump/DumpService.java | 9 ++++----- .../server/service/dump/processor/DumpAllProcessor.java | 7 +++---- .../service/dump/processor/DumpChangeProcessor.java | 4 ++-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/com/alibaba/nacos/common/task/engine/AbstractNacosTaskExecuteEngine.java b/common/src/main/java/com/alibaba/nacos/common/task/engine/AbstractNacosTaskExecuteEngine.java index b690eb23f..d6dd51cef 100644 --- a/common/src/main/java/com/alibaba/nacos/common/task/engine/AbstractNacosTaskExecuteEngine.java +++ b/common/src/main/java/com/alibaba/nacos/common/task/engine/AbstractNacosTaskExecuteEngine.java @@ -33,7 +33,7 @@ public abstract class AbstractNacosTaskExecuteEngine implem private final Logger log; - private final ConcurrentHashMap taskProcessors = new ConcurrentHashMap(); + private final ConcurrentHashMap taskProcessors = new ConcurrentHashMap<>(); private NacosTaskProcessor defaultTaskProcessor; diff --git a/common/src/main/java/com/alibaba/nacos/common/task/engine/NacosDelayTaskExecuteEngine.java b/common/src/main/java/com/alibaba/nacos/common/task/engine/NacosDelayTaskExecuteEngine.java index 99bb1b8fd..23ff94d9e 100644 --- a/common/src/main/java/com/alibaba/nacos/common/task/engine/NacosDelayTaskExecuteEngine.java +++ b/common/src/main/java/com/alibaba/nacos/common/task/engine/NacosDelayTaskExecuteEngine.java @@ -155,7 +155,7 @@ public class NacosDelayTaskExecuteEngine extends AbstractNacosTaskExecuteEngine< retryFailedTask(taskKey, task); } } catch (Throwable e) { - getEngineLog().error("Nacos task execute error : " + e.toString(), e); + getEngineLog().error("Nacos task execute error ", e); retryFailedTask(taskKey, task); } } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpConfigHandler.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpConfigHandler.java index 97e205f82..47961fe9d 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpConfigHandler.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpConfigHandler.java @@ -47,7 +47,7 @@ public class DumpConfigHandler extends Subscriber { final String type = event.getType(); final long lastModified = event.getLastModifiedTs(); if (event.isBeta()) { - boolean result = false; + boolean result; if (event.isRemove()) { result = ConfigCacheService.removeBeta(dataId, group, namespaceId); if (result) { diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpService.java index c6e3c89ef..58a8b0334 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpService.java @@ -230,8 +230,7 @@ public abstract class DumpService { } } catch (Exception e) { LogUtil.FATAL_LOG - .error("Nacos Server did not start because dumpservice bean construction failure :\n" + e - .toString()); + .error("Nacos Server did not start because dumpservice bean construction failure :\n" + e); throw new NacosException(NacosException.SERVER_ERROR, "Nacos Server did not start because dumpservice bean construction failure :\n" + e.getMessage(), e); @@ -337,9 +336,9 @@ public abstract class DumpService { private Boolean isQuickStart() { try { - String val = null; + String val; val = EnvUtil.getProperty("isQuickStart"); - if (val != null && TRUE_STR.equals(val)) { + if (TRUE_STR.equals(val)) { isQuickStart = true; } FATAL_LOG.warn("isQuickStart:{}", isQuickStart); @@ -404,7 +403,7 @@ public abstract class DumpService { static List> splitList(List list, int count) { List> result = new ArrayList>(count); for (int i = 0; i < count; i++) { - result.add(new ArrayList()); + result.add(new ArrayList<>()); } for (int i = 0; i < list.size(); i++) { ConfigInfoChanged config = list.get(i); diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllProcessor.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllProcessor.java index d3ff3575d..56676e0c3 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllProcessor.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllProcessor.java @@ -67,10 +67,9 @@ public class DumpAllProcessor implements NacosTaskProcessor { if (cf.getDataId().equals(SwitchService.SWITCH_META_DATAID)) { SwitchService.load(cf.getContent()); } - - boolean result = ConfigCacheService - .dump(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(), cf.getLastModified(), - cf.getType()); + + ConfigCacheService.dump(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(), + cf.getLastModified(), cf.getType()); final String content = cf.getContent(); final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE); diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpChangeProcessor.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpChangeProcessor.java index 5a46ce0de..ff3261b41 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpChangeProcessor.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpChangeProcessor.java @@ -86,8 +86,8 @@ public class DumpChangeProcessor implements NacosTaskProcessor { List changeConfigs = persistService.findChangeConfig(startTime, endTime); LogUtil.DEFAULT_LOG.warn("changeConfig count:{}", changeConfigs.size()); for (ConfigInfoWrapper cf : changeConfigs) { - boolean result = ConfigCacheService - .dumpChange(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(), cf.getLastModified()); + ConfigCacheService.dumpChange(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(), + cf.getLastModified()); final String content = cf.getContent(); final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE); LogUtil.DEFAULT_LOG.info("[dump-change-ok] {}, {}, length={}, md5={}", GroupKey2.getKey(cf.getDataId(), cf.getGroup()),