code: public CompletableFuture<Long> appendEntries() {
      // If there are no other active members in the cluster, simply complete the append operation.
      if (context.getClusterState().getRemoteMemberStates().isEmpty())
        return CompletableFuture.completedFuture(null);
  
      // If no heartbeat future already exists, that indicates there's no heartbeat currently under way.
      // Create a new heartbeat future and commit to all members in the cluster.
      if (heartbeatFuture == null) {
        CompletableFuture<Long> newHeartbeatFuture = new CompletableFuture<>();
        heartbeatFuture = newHeartbeatFuture;
        heartbeatTime = System.currentTimeMillis();
        for (MemberState member : context.getClusterState().getRemoteMemberStates()) {
          appendEntries(member);
        }
        return newHeartbeatFuture;
      }
      // If a heartbeat future already exists, that indicates there is a heartbeat currently underway.
      // We don't want to allow callers to be completed by a heartbeat that may already almost be done.
      // So, we create the next heartbeat future if necessary and return that. Once the current heartbeat
      // completes the next future will be used to do another heartbeat. This ensures that only one
      // heartbeat can be outstanding at any given point in time.
      else if (nextHeartbeatFuture == null) {
        nextHeartbeatFuture = new CompletableFuture<>();
        return nextHeartbeatFuture;
      } else {
        return nextHeartbeatFuture;
      }
    }
docs: Triggers a heartbeat to a majority of the cluster.
  <p>
  For followers to which no AppendRequest is currently being sent, a new empty AppendRequest will be
  created and sent. For followers to which an AppendRequest is already being sent, the appendEntries()
  call will piggyback on the *next* AppendRequest. Thus, multiple calls to this method will only ever
  result in a single AppendRequest to each follower at any given time, and the returned future will be
  shared by all concurrent calls.
  
  @return A completable future to be completed the next time a heartbeat is received by a majority of the cluster.