allthingssecurity commented on code in PR #28325:
URL: https://github.com/apache/camel/pull/28325#discussion_r4358421997


##########
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:
   Applied in 06c6a7d853ee: `connectCount` is a plain `int` now, guarded by 
`connectLock`.
   
   _Claude Code on behalf of allthingssecurity_



##########
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:
   Applied in 06c6a7d853ee: `connectCount++;`
   
   _Claude Code on behalf of allthingssecurity_



##########
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:
   Applied in 06c6a7d853ee: `if (--connectCount == 0) {`
   
   _Claude Code on behalf of allthingssecurity_



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