private CompletableFuture processChangeState()

in ratis-logservice/src/main/java/org/apache/ratis/logservice/server/LogStateMachine.java [526:564]


  private CompletableFuture<Message> processChangeState(LogServiceRequestProto logServiceRequestProto) {
    LogServiceProtos.ChangeStateLogRequestProto changeState = logServiceRequestProto.getChangeState();
    // Need to check whether the file is opened if opened close it.
    // TODO need to handle exceptions while operating with files.

    State targetState = State.valueOf(changeState.getState().name());
    Throwable t = null;
    //if forced skip checking states
    if(!changeState.getForce()) {
      switch (targetState) {
      case OPEN:
        if (state != null) {
          t = verifyState(State.OPEN, State.CLOSED);
        }
        break;
      case CLOSED:
        t =  verifyState(State.OPEN);
        break;
      case ARCHIVED:
        t = verifyState(State.ARCHIVING);
        break;
      case ARCHIVING:
        t = verifyState(State.CLOSED);
        break;
      case DELETED:
        t = verifyState(State.CLOSED);
        break;
      default:
      }
    }
    if(t != null) {
      return CompletableFuture.completedFuture(Message
              .valueOf(LogServiceProtos.ChangeStateReplyProto.newBuilder().
                      setException(LogServiceProtoUtil.toLogException(t)).build().toByteString()));
    }
    this.state = targetState;
    return CompletableFuture.completedFuture(Message
        .valueOf(LogServiceProtos.ChangeStateReplyProto.newBuilder().build().toByteString()));
  }