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


##########
components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/JGroupsRaftNeverStartedConsumerTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jgroups.raft;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jgroups.raft.utils.NopStateMachine;
+import org.jgroups.JChannel;
+import org.jgroups.raft.RaftHandle;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Red-team probe: a consumer of the shared component handle that was never 
started (autoStartup=false) is stopped
+ * when its route is stopped or removed. Its doStop calls 
endpoint.disconnect() unconditionally, which decrements the
+ * count of the running producer and disconnects the shared handle under it.
+ */
+/**

Review Comment:
   Right, a leftover drafting note. Removed in 15b3af0af818; only the 
description of the test remains.
   
   _Claude Code on behalf of allthingssecurity_



##########
components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/JGroupsRaftComponent.java:
##########
@@ -99,5 +117,77 @@ public void setChannelProperties(String channelProperties) {
         this.channelProperties = channelProperties;
     }
 
+    /**
+     * Connects a RaftHandle that several endpoints can use, for a producer or 
a consumer of one of them.
+     */
+    void connectSharedHandle(RaftHandle sharedHandle, String clusterName) 
throws Exception {
+        sharedHandleLock.lock();
+        try {
+            sharedHandle.channel().connect(clusterName);
+            sharedHandleUsers.merge(sharedHandle, 1, Integer::sum);
+            sharedHandles.add(sharedHandle);
+        } finally {
+            sharedHandleLock.unlock();
+        }
+    }
+
+    /**
+     * Disconnects a RaftHandle that several endpoints can use, when its last 
producer or consumer stops.
+     */
+    void disconnectSharedHandle(RaftHandle sharedHandle) {
+        sharedHandleLock.lock();
+        try {
+            Integer users = sharedHandleUsers.get(sharedHandle);
+            if (users == null) {
+                return;
+            }
+            if (users > 1) {
+                sharedHandleUsers.put(sharedHandle, users - 1);
+            } else {
+                sharedHandleUsers.remove(sharedHandle);
+                LOG.trace("Disconnecting JGroupsraft Channel {}", 
sharedHandle.channel());
+                sharedHandle.channel().disconnect();

Review Comment:
   Yes, the I/O runs under the component lock. A component has one `raftHandle` 
option, so there is only ever one shared handle per component and nothing else 
waits on that lock; the same holds for the jgroups component channel 
(CAMEL-25852). Holding the lock also keeps a connect and a disconnect of the 
same handle from interleaving.
   
   _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