From bf1131113596582b76d0e3172c2de544a54cf2c7 Mon Sep 17 00:00:00 2001 From: hardyfish <85128645+hardyfish@users.noreply.github.com> Date: Thu, 23 Feb 2023 11:50:35 +0800 Subject: [PATCH] [ISSUE #6057] Modify magic number code --- .../protocol/body/RegisterBrokerBody.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/body/RegisterBrokerBody.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/body/RegisterBrokerBody.java index 6b9a28d745b..99557b1d3fb 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/body/RegisterBrokerBody.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/body/RegisterBrokerBody.java @@ -45,6 +45,7 @@ public class RegisterBrokerBody extends RemotingSerializable { private static final Logger LOGGER = LoggerFactory.getLogger(LoggerName.COMMON_LOGGER_NAME); private TopicConfigAndMappingSerializeWrapper topicConfigSerializeWrapper = new TopicConfigAndMappingSerializeWrapper(); private List filterServerList = new ArrayList<>(); + private static final long MINIMUM_TAKE_TIME_MILLISECOND = 50; public byte[] encode(boolean compress) { @@ -99,9 +100,9 @@ public byte[] encode(boolean compress) { } outputStream.finish(); - long interval = System.currentTimeMillis() - start; - if (interval > 50) { - LOGGER.info("Compressing takes {}ms", interval); + long takeTime = System.currentTimeMillis() - start; + if (takeTime > MINIMUM_TAKE_TIME_MILLISECOND) { + LOGGER.info("Compressing takes {}ms", takeTime); } return byteArrayOutputStream.toByteArray(); } catch (IOException e) { @@ -163,9 +164,9 @@ public static RegisterBrokerBody decode(byte[] data, boolean compressed, MQVersi registerBrokerBody.getTopicConfigSerializeWrapper().setTopicQueueMappingInfoMap(topicQueueMappingInfoMap); } - long interval = System.currentTimeMillis() - start; - if (interval > 50) { - LOGGER.info("Decompressing takes {}ms", interval); + long takeTime = System.currentTimeMillis() - start; + if (takeTime > MINIMUM_TAKE_TIME_MILLISECOND) { + LOGGER.info("Decompressing takes {}ms", takeTime); } return registerBrokerBody; } @@ -212,12 +213,13 @@ public void setFilterServerList(List filterServerList) { this.filterServerList = filterServerList; } - public static ConcurrentMap cloneTopicConfigTable( + private ConcurrentMap cloneTopicConfigTable( ConcurrentMap topicConfigConcurrentMap) { - ConcurrentHashMap result = new ConcurrentHashMap<>(); - if (topicConfigConcurrentMap != null) { - result.putAll(topicConfigConcurrentMap); + if (topicConfigConcurrentMap == null) { + return null; } + ConcurrentHashMap result = new ConcurrentHashMap<>(topicConfigConcurrentMap.size()); + result.putAll(topicConfigConcurrentMap); return result; } }