Class ExponentialBackoffPolicy

java.lang.Object
io.spiffe.workloadapi.retry.ExponentialBackoffPolicy

public class ExponentialBackoffPolicy extends Object
Represents a backoff policy for performing retries using exponential increasing delays.
  • Field Details

  • Constructor Details

    • ExponentialBackoffPolicy

      public ExponentialBackoffPolicy(Duration initialDelay, Duration maxDelay, int maxRetries, int backoffMultiplier)
  • Method Details

    • nextDelay

      public Duration nextDelay(Duration currentDelay)
      Calculate the nextDelay based on a currentDelay, applying the backoff function If the calculated delay is greater than maxDelay, it returns maxDelay.
      Parameters:
      currentDelay - a Duration representing the current delay
      Returns:
      a Duration representing the next delay
    • reachedMaxRetries

      public boolean reachedMaxRetries(int retriesCount)
      Returns false if the RetryPolicy is configured with UNLIMITED_RETRIES or if the retriesCount param is lower than the maxRetries.
      Parameters:
      retriesCount - the current number of retries
      Returns:
      true if the number of retries reached the max number of retries, false otherwise