Pil0tXia commented on code in PR #4736:
URL: https://github.com/apache/eventmesh/pull/4736#discussion_r1566640489


##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumer/SubscriptionManager.java:
##########
@@ -71,82 +74,69 @@ public ConcurrentHashMap<String, List<Client>> 
getLocalClientInfoMapping() {
 
     public void registerClient(final ClientInfo clientInfo, final String 
consumerGroup,
         final List<SubscriptionItem> subscriptionItems, final String url) {
-        for (final SubscriptionItem subscription : subscriptionItems) {
-            final String groupTopicKey = consumerGroup + "@" + 
subscription.getTopic();
-
-            List<Client> localClients = 
localClientInfoMapping.get(groupTopicKey);
-
-            if (localClients == null) {
-                localClientInfoMapping.putIfAbsent(groupTopicKey, new 
ArrayList<>());
-                localClients = localClientInfoMapping.get(groupTopicKey);
-            }
-
-            boolean isContains = false;
-            for (final Client localClient : localClients) {
-                // TODO: compare the whole Client would be better?
-                if (StringUtils.equals(localClient.getUrl(), url)) {
-                    isContains = true;
-                    localClient.setLastUpTime(new Date());
-                    break;
+        lock.lock();
+        try {
+            for (final SubscriptionItem subscription : subscriptionItems) {
+                final String groupTopicKey = consumerGroup + "@" + 
subscription.getTopic();
+                List<Client> localClients = 
localClientInfoMapping.computeIfAbsent(groupTopicKey, (groupTopicKeyInner) ->
+                    new ArrayList<>()
+                );
+                Client clientInner = urlClientInfoMapping.computeIfAbsent(url, 
urlInner -> {
+                    Client client = new Client();
+                    client.setEnv(clientInfo.getEnv());
+                    client.setIdc(clientInfo.getIdc());
+                    client.setSys(clientInfo.getSys());
+                    client.setIp(clientInfo.getIp());
+                    client.setPid(clientInfo.getPid());
+                    client.setConsumerGroup(consumerGroup);
+                    client.setTopic(subscription.getTopic());
+                    client.setUrl(url);
+                    return client;
+                });
+                clientInner.reNewLastUpTime();
+                if (!localClients.contains(clientInner)) {

Review Comment:
   @karsonto It seems that this conversation is waiting for your reply.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to