gnodet-bot commented on code in PR #28325:
URL: https://github.com/apache/camel/pull/28325#discussion_r4358113732


##########
components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java:
##########
@@ -50,6 +52,9 @@ public class JGroupsEndpoint extends DefaultEndpoint {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(JGroupsEndpoint.class);
     private AtomicInteger connectCount = new AtomicInteger();

Review Comment:
   💡 **Nit:** `connectCount` is now always accessed inside `connectLock`, so 
`AtomicInteger` is redundant — a plain `int` is sufficient and clearer:
   
   ```suggestion
       private int connectCount;
   ```



##########
components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java:
##########
@@ -227,18 +241,37 @@ private JChannel resolveChannel() throws Exception {
      * Connect shared channel, called by producer and consumer.
      */
     public void connect() throws Exception {
-        connectCount.incrementAndGet();
         LOG.trace("Connecting JGroups Channel {}", getEndpointUri());
-        resolvedChannel.connect(clusterName);
+        if (!isOwnChannel()) {
+            ((JGroupsComponent) 
getComponent()).connectSharedChannel(resolvedChannel, clusterName);
+            return;
+        }
+        connectLock.lock();
+        try {
+            resolvedChannel.connect(clusterName);
+            // counted after a successful connect, as a producer or consumer 
whose connect failed does not disconnect
+            connectCount.incrementAndGet();

Review Comment:
   💡 **Nit:** With a plain `int`, this becomes:
   
   ```suggestion
               connectCount++;
   ```



##########
components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java:
##########
@@ -227,18 +241,37 @@ private JChannel resolveChannel() throws Exception {
      * Connect shared channel, called by producer and consumer.
      */
     public void connect() throws Exception {
-        connectCount.incrementAndGet();
         LOG.trace("Connecting JGroups Channel {}", getEndpointUri());
-        resolvedChannel.connect(clusterName);
+        if (!isOwnChannel()) {
+            ((JGroupsComponent) 
getComponent()).connectSharedChannel(resolvedChannel, clusterName);
+            return;
+        }
+        connectLock.lock();
+        try {
+            resolvedChannel.connect(clusterName);
+            // counted after a successful connect, as a producer or consumer 
whose connect failed does not disconnect
+            connectCount.incrementAndGet();
+        } finally {
+            connectLock.unlock();
+        }
     }
 
     /**
      * Disconnect shared channel, called by producer and consumer.
      */
     public void disconnect() {
-        if (connectCount.decrementAndGet() == 0) {
-            LOG.trace("Disconnecting JGroups Channel {}", getEndpointUri());
-            resolvedChannel.disconnect();
+        if (!isOwnChannel()) {
+            ((JGroupsComponent) 
getComponent()).disconnectSharedChannel(resolvedChannel);
+            return;
+        }
+        connectLock.lock();
+        try {
+            if (connectCount.decrementAndGet() == 0) {

Review Comment:
   💡 **Nit:** With a plain `int`, this becomes:
   
   ```suggestion
               if (--connectCount == 0) {
   ```



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