Class HeedRetryAfter

java.lang.Object
com.maybeitssquid.retry.resilience4j.HeedRetryAfter
All Implemented Interfaces:
io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse>, BiFunction<Integer,io.github.resilience4j.core.functions.Either<Throwable,jakarta.servlet.http.HttpServletResponse>,Long>

public class HeedRetryAfter extends Object implements io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse>
Function that extends the wait interval specified by a wrapped IntervalBiFunction so that it respects any Retry-After header that was returned in an HTTP response. If a Retry-After header is found, returns the maximum of the wait returned by the wrapped function and the wait indicated by the header. If no header is found, returns only the result of the wrapped function.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HeedRetryAfter(io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse> wrapped)
    Creates a wrapper using the extended header definitions.
    HeedRetryAfter(io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse> wrapped, Function<jakarta.servlet.http.HttpServletResponse,Optional<Duration>> parser)
    Creates a wrapper using the extended header definitions.
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(Integer t, io.github.resilience4j.core.functions.Either<Throwable,jakarta.servlet.http.HttpServletResponse> u)
    Checks for an HTTP response with a Retry-After header, and computes the required wait interval.
    atLeast(long milliseconds)
    Heeds the Retry-After header with a required minimum wait.
    atLeast(Duration minimum)
    Heeds the Retry-After header with a required minimum wait.
    Heeds the Retry-After header with a wait of RetryConfig.DEFAULT_WAIT_DURATION if none is required by a header.
    Heeds the Retry-After header with no wait if none is required by a header.
    heed(io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse> extending)
    Extends an IntervalBiFunction to heed any Retry-After header in the response.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.BiFunction

    andThen
  • Constructor Details

    • HeedRetryAfter

      public HeedRetryAfter(io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse> wrapped, Function<jakarta.servlet.http.HttpServletResponse,Optional<Duration>> parser)
      Creates a wrapper using the extended header definitions.
      Parameters:
      wrapped - the existing bifunction to wrap.
      parser - the parser for headers, such as from RetryAfterParser.
    • HeedRetryAfter

      public HeedRetryAfter(io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse> wrapped)
      Creates a wrapper using the extended header definitions.
      Parameters:
      wrapped - the existing bifunction to wrap.
  • Method Details

    • atLeast

      public static HeedRetryAfter atLeast(long milliseconds)
      Heeds the Retry-After header with a required minimum wait.
      Parameters:
      milliseconds - the minimum wait in milliseconds.
      Returns:
      function that waits for the Retry-After interval with a minimum.
    • atLeast

      public static HeedRetryAfter atLeast(Duration minimum)
      Heeds the Retry-After header with a required minimum wait.
      Parameters:
      minimum - the minimum wait.
      Returns:
      function that waits for the Retry-After interval with a minimum.
    • defaulted

      public static HeedRetryAfter defaulted()
      Heeds the Retry-After header with a wait of RetryConfig.DEFAULT_WAIT_DURATION if none is required by a header.
      Returns:
      function that waits for the Retry-After interval with a default minimum.
    • heed

      public static HeedRetryAfter heed()
      Heeds the Retry-After header with no wait if none is required by a header.
      Returns:
      function that waits for the Retry-After interval.
    • heed

      public static HeedRetryAfter heed(io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse> extending)
      Extends an IntervalBiFunction to heed any Retry-After header in the response.
      Parameters:
      extending - the function to extend.
      Returns:
      a function that extends the wait interval to heed the Retry-After header.
    • apply

      public Long apply(Integer t, io.github.resilience4j.core.functions.Either<Throwable,jakarta.servlet.http.HttpServletResponse> u)
      Checks for an HTTP response with a Retry-After header, and computes the required wait interval.
      Specified by:
      apply in interface BiFunction<Integer,io.github.resilience4j.core.functions.Either<Throwable,jakarta.servlet.http.HttpServletResponse>,Long>
      Parameters:
      t - the retry count, which is passed to the wrapped function.
      u - the result to evaluate
      Returns:
      the maximum of the wait interval specified by the wrapped function and the interval indicated by the Retry-After header.