You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/08/30 11:40:28 UTC

[GitHub] [rocketmq] aaron-ai commented on a diff in pull request #4932: fix excessive nesting in MQClientInstance.java

aaron-ai commented on code in PR #4932:
URL: https://github.com/apache/rocketmq/pull/4932#discussion_r958368902


##########
client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java:
##########
@@ -561,42 +561,43 @@ private void sendHeartbeatToAllBroker() {
             return;
         }
 
-        if (!this.brokerAddrTable.isEmpty()) {
-            long times = this.sendHeartbeatTimesTotal.getAndIncrement();
-            Iterator<Entry<String, HashMap<Long, String>>> it = this.brokerAddrTable.entrySet().iterator();
-            while (it.hasNext()) {
-                Entry<String, HashMap<Long, String>> entry = it.next();
-                String brokerName = entry.getKey();
-                HashMap<Long, String> oneTable = entry.getValue();
-                if (oneTable != null) {
-                    for (Map.Entry<Long, String> entry1 : oneTable.entrySet()) {
-                        Long id = entry1.getKey();
-                        String addr = entry1.getValue();
-                        if (addr != null) {
-                            if (consumerEmpty) {
-                                if (id != MixAll.MASTER_ID)
-                                    continue;
-                            }
+        if (this.brokerAddrTable.isEmpty()) {
+            return;
+        }
+        long times = this.sendHeartbeatTimesTotal.getAndIncrement();
+        for (Entry<String, HashMap<Long, String>> brokerClusterInfo : this.brokerAddrTable.entrySet()) {
+            String brokerName = brokerClusterInfo.getKey();
+            HashMap<Long, String> oneTable = brokerClusterInfo.getValue();
+            if (oneTable == null) {
+                continue;
+            }
+            for (Entry<Long, String> singleBrokerInstance : oneTable.entrySet()) {
+                Long id = singleBrokerInstance.getKey();
+                String addr = singleBrokerInstance.getValue();
+                if (addr == null) {
+                    continue;
+                }
+                if (consumerEmpty) {
+                    if (id != MixAll.MASTER_ID)
+                        continue;
+                }

Review Comment:
   ```suggestion
                   if (consumerEmpty && MixAll.MASTER_ID != id) {
                       continue;
                   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org