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


##########
components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusterView.java:
##########
@@ -76,81 +87,72 @@ public List<CamelClusterMember> getMembers() {
 
     @Override
     protected void doStart() throws Exception {
-        if (raftHandle == null && jgroupsConfig != null && 
!jgroupsConfig.isEmpty()) {
-            raftHandle = new RaftHandle(new JChannel(jgroupsConfig), new 
NopStateMachine()).raftId(raftId);
-        } else if (raftHandle == null) {
-            raftHandle = new RaftHandle(new 
JChannel(JGroupsRaftConstants.DEFAULT_JGROUPSRAFT_CONFIG), new 
NopStateMachine())
-                    .raftId(raftId);
-        }
         fireLeadershipChangedEvent((CamelClusterMember) null);
-
-        // Register the listener once before attempting to connect; 
registering inside
-        // the retry loop would accumulate duplicate listeners across retries.
-        roleListener = new ClusterRoleChangeListener(this);
-        raftHandle.addRoleListener(roleListener);
-
-        // it may take a while for event to trigger and allow us to join so 
retry a while
-        Exception cause = null;
-        for (int i = 1; i < 11; i++) {
-            LOG.debug("Attempt #{} for raft {} to join {}", i, raftId, 
jgroupsClusterName);
-            try {
-                raftHandle.channel().connect(jgroupsClusterName);
-                LOG.debug("Joined and connected to {} with raft id: {}", 
jgroupsClusterName, raftId);
-                cause = null;
-                break;
-            } catch (Exception e) {
-                cause = e;
-            }
-            // wait for next attempt
-            Thread.sleep(5000);
+        roleLock.lock();
+        try {
+            disconnected = false;
+        } finally {
+            roleLock.unlock();
         }
-        if (cause != null) {
-            throw cause;
+
+        ClusterRoleChangeListener listener = new 
ClusterRoleChangeListener(this);
+        RaftHandle handle = getRaftClusterService().connectView(listener);
+        roleListener = listener;
+
+        // the node may already be the leader (elected before this view 
started), and then no role change is notified
+        roleLock.lock();
+        try {
+            leadershipChanged(Role.Leader.name().equals(handle.raft().role()));

Review Comment:
   Good catch, applied in c2a2522fd541: the view now reads the initial role 
with `handle.isLeader()`, and the `Role` import is gone from the view. In 
jgroups-raft 1.1.4 `RaftHandle.isLeader()` is `RAFT.isLeader()`, true when the 
leader address is the local address, and RAFT sets that address before it 
switches the role to Leader and notifies the listeners, so it means the same 
here. camel-jgroups-raft tests: 37 run, 0 failures; the two changed test 
classes pass 5 runs in a row.
   



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