Interface CustomBackoffStrategy


@Experimental("first attempt at providing additional retry backoff strategies") public interface CustomBackoffStrategy
For each invocation of a method annotated @Retry and @CustomBackoff, an instance of custom backoff strategy is created and used for computing delays between individual retry attempts. Therefore, implementations of this interface must have a public zero-parameter constructor and should generally be cheap to construct and not use a lot of memory. Additionally, they may be used from multiple threads, so they must be thread safe.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    init(long initialDelayInMillis)
    Called once, after instantiation.
    long
    Called to compute a delay before each retry attempt, including before the first retry.
  • Method Details

    • init

      default void init(long initialDelayInMillis)
      Called once, after instantiation. Can be used to initialize state, if needed. Implementations are free to use initialDelayInMillis as they see fit; possibly even ignore, if the concept of initial delay doesn't make sense for the strategy.
      Parameters:
      initialDelayInMillis - initial delay in milliseconds, per Retry.delay and Retry.delayUnit
    • nextDelayInMillis

      long nextDelayInMillis(Throwable exception)
      Called to compute a delay before each retry attempt, including before the first retry. Implementations must be fast and non-blocking (i.e., they must not do any IO or long-running computations).
      Parameters:
      exception - exception that caused the retry attempt
      Returns:
      delay in milliseconds; must be >= 0