docs: @SuppressWarnings("unchecked")
    public <T> CompletableFuture<T> apply(Indexed<? extends RaftLogEntry> entry) {
      CompletableFuture<T> future = new CompletableFuture<>();
      stateContext.execute(() -> {
        logger.trace("Applying {}", entry);
        try {
          if (entry.type() == QueryEntry.class) {
            applyQuery(entry.cast()).whenComplete((r, e) -> {
              if (e != null) {
                future.completeExceptionally(e);
              } else {
                future.complete((T) r);
              }
            });
          } else {
            // Get the current snapshot. If the snapshot is for a higher index then skip this operation.
            // If the snapshot is for the prior index, install it.
            Snapshot snapshot = raft.getSnapshotStore().getCurrentSnapshot();
            if (snapshot != null) {
              if (snapshot.index() >= entry.index()) {
                future.complete(null);
                return;
              } else if (snapshot.index() == entry.index() - 1) {
                install(snapshot);
              }
            }
  
            if (entry.type() == CommandEntry.class) {
              future.complete((T) applyCommand(entry.cast()));
            } else if (entry.type() == OpenSessionEntry.class) {
              future.complete((T) (Long) applyOpenSession(entry.cast()));
            } else if (entry.type() == KeepAliveEntry.class) {
              future.complete((T) applyKeepAlive(entry.cast()));
            } else if (entry.type() == CloseSessionEntry.class) {
              applyCloseSession(entry.cast());
              future.complete(null);
            } else if (entry.type() == MetadataEntry.class) {
              future.complete((T) applyMetadata(entry.cast()));
            } else if (entry.type() == InitializeEntry.class) {
              future.complete((T) applyInitialize(entry.cast()));
            } else if (entry.type() == ConfigurationEntry.class) {
              future.complete((T) applyConfiguration(entry.cast()));
            } else {
              future.completeExceptionally(new RaftException.ProtocolException("Unknown entry type"));
            }
          }
        } catch (Exception e) {
          future.completeExceptionally(e);
        }
      });
      return future;
    }