gnodet commented on code in PR #28425: URL: https://github.com/apache/camel/pull/28425#discussion_r4369078541
########## 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: 💡 **Note:** Two adjacent Javadoc blocks appear before this class declaration (lines 27–31 and 32–35). The first block (`Red-team probe: …`) reads like an internal drafting note and appears to be a leftover. Only one class-level Javadoc should be present — the second (shorter) one describes the actual test scenario. ########## 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: 💡 **Note:** `sharedHandle.channel().disconnect()` is called while holding `sharedHandleLock`. JGroups channel disconnect involves network I/O (cluster view update, TCP teardown) and may block. Callers of `connectSharedHandle` on any other handle are serialised behind this lock for the duration of the I/O. If only one or two shared handles are ever used this is fine, but it's worth documenting the assumption. A finer-grained design (per-handle lock, or releasing the component lock before the network call) would decouple the handles from each other. -- 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]
