sherlock-lin commented on code in PR #6832:
URL: https://github.com/apache/rocketmq/pull/6832#discussion_r1217529639


##########
broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java:
##########
@@ -161,24 +161,15 @@ public synchronized boolean doChannelCloseEvent(final 
String remoteAddr, final C
     }
 
     public synchronized void registerProducer(final String group, final 
ClientChannelInfo clientChannelInfo) {
-        ClientChannelInfo clientChannelInfoFound = null;
-
+        this.groupChannelTable.putIfAbsent(group, new ConcurrentHashMap<>());
         ConcurrentHashMap<Channel, ClientChannelInfo> channelTable = 
this.groupChannelTable.get(group);

Review Comment:
   I also tried this way, but this method returns null when the object is not 
found
   
![image](https://github.com/apache/rocketmq/assets/19645523/15e6ce3c-d42f-43e4-9fe0-95ca3114d1bf)
   



##########
broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java:
##########
@@ -161,24 +161,15 @@ public synchronized boolean doChannelCloseEvent(final 
String remoteAddr, final C
     }
 
     public synchronized void registerProducer(final String group, final 
ClientChannelInfo clientChannelInfo) {
-        ClientChannelInfo clientChannelInfoFound = null;
-
+        this.groupChannelTable.putIfAbsent(group, new ConcurrentHashMap<>());
         ConcurrentHashMap<Channel, ClientChannelInfo> channelTable = 
this.groupChannelTable.get(group);
-        if (null == channelTable) {
-            channelTable = new ConcurrentHashMap<>();
-            this.groupChannelTable.put(group, channelTable);
-        }
 
-        clientChannelInfoFound = 
channelTable.get(clientChannelInfo.getChannel());
+        ClientChannelInfo clientChannelInfoFound = 
channelTable.putIfAbsent(clientChannelInfo.getChannel(), clientChannelInfo);

Review Comment:
   Thanks, but here we need to update the timestamp when it exists and add it 
when it doesn't。So we can't use computeIfAbsent instead of if else



-- 
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]

Reply via email to