private void runImpl()

in ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java [246:281]


  private void runImpl() {
    if (!lifeCycle.compareAndTransition(STARTING, RUNNING)) {
      final LifeCycle.State state = lifeCycle.getCurrentState();
      LOG.info("{}: skip running since this is already {}", this, state);
      return;
    }

    try (AutoCloseable ignored = Timekeeper.start(server.getLeaderElectionMetrics().getLeaderElectionTimer())) {
      for (int round = 0; shouldRun(); round++) {
        if (skipPreVote || askForVotes(Phase.PRE_VOTE, round)) {
          if (askForVotes(Phase.ELECTION, round)) {
            server.changeToLeader();
          }
        }
      }
    } catch(Exception e) {
      if (e instanceof InterruptedException) {
          Thread.currentThread().interrupt();
      }
      final LifeCycle.State state = lifeCycle.getCurrentState();
      if (state.isClosingOrClosed()) {
        LOG.info(this + ": since this is already " + state + ", safely ignore " + e);
      } else {
        if (!server.getInfo().isAlive()) {
          LOG.info(this + ": since the server is not alive, safely ignore " + e);
        } else {
          LOG.error("{}: Failed, state={}", this, state, e);
        }
        shutdown();
      }
    } finally {
      // Update leader election completion metric(s).
      server.getLeaderElectionMetrics().onNewLeaderElectionCompletion();
      lifeCycle.checkStateAndClose(() -> {});
    }
  }