code: public <T> CompletableFuture<T> apply(long index) {
      try {
        // If entries remain to be applied prior to this entry then synchronously apply them.
        if (index > lastApplied + 1) {
          applyAll(index - 1);
        }
  
        // Read the entry from the log. If the entry is non-null them apply the entry, otherwise
        // simply update the last applied index and return a null result.
        try (Entry entry = log.get(index)) {
          if (entry != null) {
            return apply(entry);
          } else {
            return CompletableFuture.completedFuture(null);
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
        return Futures.exceptionalFuture(e);
      } finally {
        setLastApplied(index);
      }
    }
docs: Applies the entry at the given index to the state machine.
  <p>
  Calls to this method are assumed to expect a result. This means linearizable session events
  triggered by the application of the command at the given index will be awaited before completing
  the returned future.
  
  @param index The index to apply.
  @return A completable future to be completed once the commit has been applied.