You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/10/26 07:42:50 UTC

[incubator-eventmesh] branch master updated: issue(1728): use entrySet replace key set iterator

This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new 20a01bab issue(1728): use entrySet replace key set iterator
     new c7ec9211 Merge pull request #1873 from NewtonVan/dev-1728
20a01bab is described below

commit 20a01babf9d624d7b7265b28184df9fc688f547c
Author: idi0tn3 <26...@qq.com>
AuthorDate: Wed Oct 26 11:46:07 2022 +0800

    issue(1728): use entrySet replace key set iterator
    
    - Unlike style of proposed method in the issue, we use 'happy path' in
      the for loop.
---
 .../processor/LocalSubscribeEventProcessor.java    | 30 ++++++++++++----------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/LocalSubscribeEventProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/LocalSubscribeEventProcessor.java
index 9ff7f969..be752ab4 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/LocalSubscribeEventProcessor.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/LocalSubscribeEventProcessor.java
@@ -47,6 +47,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -233,20 +234,23 @@ public class LocalSubscribeEventProcessor extends AbstractEventProcessor impleme
                         newTopicConf.setIdcUrls(idcUrls);
                         map.put(subTopic.getTopic(), newTopicConf);
                     }
-                    for (String key : map.keySet()) {
-                        if (StringUtils.equals(subTopic.getTopic(), key)) {
-                            ConsumerGroupTopicConf latestTopicConf = new ConsumerGroupTopicConf();
-                            latestTopicConf.setConsumerGroup(consumerGroup);
-                            latestTopicConf.setTopic(subTopic.getTopic());
-                            latestTopicConf.setSubscriptionItem(subTopic);
-                            latestTopicConf.setUrls(new HashSet<>(Arrays.asList(url)));
-
-                            ConsumerGroupTopicConf currentTopicConf = map.get(key);
-                            latestTopicConf.getUrls().addAll(currentTopicConf.getUrls());
-                            latestTopicConf.setIdcUrls(idcUrls);
-
-                            map.put(key, latestTopicConf);
+                    Set<Map.Entry<String, ConsumerGroupTopicConf>> entrySet = map.entrySet();
+                    for (Map.Entry<String, ConsumerGroupTopicConf> set : entrySet) {
+                        if (!StringUtils.equals(subTopic.getTopic(), set.getKey())) {
+                            continue;
                         }
+
+                        ConsumerGroupTopicConf latestTopicConf = new ConsumerGroupTopicConf();
+                        latestTopicConf.setConsumerGroup(consumerGroup);
+                        latestTopicConf.setTopic(subTopic.getTopic());
+                        latestTopicConf.setSubscriptionItem(subTopic);
+                        latestTopicConf.setUrls(new HashSet<>(Arrays.asList(url)));
+
+                        ConsumerGroupTopicConf currentTopicConf = set.getValue();
+                        latestTopicConf.getUrls().addAll(currentTopicConf.getUrls());
+                        latestTopicConf.setIdcUrls(idcUrls);
+
+                        map.put(set.getKey(), latestTopicConf);
                     }
                 }
                 eventMeshHTTPServer.localConsumerGroupMapping.put(consumerGroup, consumerGroupConf);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org