private void leave(CompletableFuture<Void> future) {
    // Set a timer to retry the attempt to leave the cluster.
    leaveTimeout = raft.getThreadContext().schedule(raft.getElectionTimeout(), () -> {
      leave(future);
    });

    // Attempt to leave the cluster by submitting a LeaveRequest directly to the server state.
    // Non-leader states should forward the request to the leader if there is one. Leader states
    // will log, replicate, and commit the reconfiguration.
    raft.getRaftRole().onLeave(LeaveRequest.builder()
        .withMember(getMember())
        .build()).whenComplete((response, error) -> {
          // Cancel the leave timer.
          cancelLeaveTimer();

          if (error == null && response.status() == RaftResponse.Status.OK) {
            Configuration configuration = new Configuration(response.index(), response.term(), response.timestamp(), response.members());

            // Configure the cluster and commit the configuration as we know the successful response
            // indicates commitment.
            configure(configuration).commit();
            future.complete(null);
          } else {
            // Reset the leave timer.
            leaveTimeout = raft.getThreadContext().schedule(raft.getElectionTimeout(), () -> {
              leave(future);
            });
          }
        });
  }
private void leave ( CompletableFuture < Void > future ) { leaveTimeout = raft . getThreadContext ( ) . schedule ( raft . getElectionTimeout ( ) , ( ) -> { leave ( future ) ; } ) ; raft . getRaftRole ( ) . onLeave ( LeaveRequest . builder ( ) . withMember ( getMember ( ) ) . build ( ) ) . whenComplete ( ( response , error ) -> { cancelLeaveTimer ( ) ; if ( error == null && response . status ( ) == RaftResponse . Status . OK ) { Configuration configuration = new Configuration ( response . index ( ) , response . term ( ) , response . timestamp ( ) , response . members ( ) ) ; configure ( configuration ) . commit ( ) ; future . complete ( null ) ; } else { leaveTimeout = raft . getThreadContext ( ) . schedule ( raft . getElectionTimeout ( ) , ( ) -> { leave ( future ) ; } ) ; } } ) ; }
Attempts to leave the cluster.