code: ServerContext setLeader(int leader) {
      if (this.leader != leader) {
        // 0 indicates no leader.
        if (leader == 0) {
          this.leader = 0;
        } else {
          // If a valid leader ID was specified, it must be a member that's currently a member of the
          // ACTIVE members configuration. Note that we don't throw exceptions for unknown members. It's
          // possible that a failure following a configuration change could result in an unknown leader
          // sending AppendRequest to this server. Simply configure the leader if it's known.
          ServerMember member = cluster.member(leader);
          if (member != null) {
            this.leader = leader;
            LOGGER.info("{} - Found leader {}", cluster.member().address(), member.address());
            electionListeners.forEach(l -> l.accept(member));
            cluster.identify();
          }
        }
  
        this.lastVotedFor = 0;
        meta.storeVote(0);
      }
      return this;
    }
docs: Sets the state leader.
  
  @param leader The state leader.
  @return The Raft context.