RaftClientReply sendRequestWithRetry()

in ratis-client/src/main/java/org/apache/ratis/client/impl/BlockingImpl.java [98:141]


  RaftClientReply sendRequestWithRetry(Supplier<RaftClientRequest> supplier) throws IOException {
    RaftClientImpl.PendingClientRequest pending = new RaftClientImpl.PendingClientRequest() {
      @Override
      public RaftClientRequest newRequestImpl() {
        return supplier.get();
      }
    };
    while (true) {
      final RaftClientRequest request = pending.newRequest();
      IOException ioe = null;
      try {
        final RaftClientReply reply = sendRequest(request);

        if (reply != null) {
          return client.handleReply(request, reply);
        }
      } catch (GroupMismatchException | StateMachineException | TransferLeadershipException |
               LeaderSteppingDownException | AlreadyClosedException | AlreadyExistsException |
               SetConfigurationException e) {
        throw e;
      } catch (IOException e) {
        ioe = e;
      }

      if (client.isClosed()) {
        throw new AlreadyClosedException(this + " is closed.");
      }

      final ClientRetryEvent event = pending.newClientRetryEvent(request, ioe);
      final RetryPolicy retryPolicy = client.getRetryPolicy();
      final RetryPolicy.Action action = retryPolicy.handleAttemptFailure(event);
      if (!action.shouldRetry()) {
        throw client.noMoreRetries(event);
      }

      final TimeDuration sleepTime = client.getEffectiveSleepTime(ioe, action.getSleepTime());
      try {
        sleepTime.sleep();
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new InterruptedIOException("retry policy=" + retryPolicy);
      }
    }
  }