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
ConstructorsConstructorDescriptionHeedRetryAfter(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 TypeMethodDescriptionapply(Integer t, io.github.resilience4j.core.functions.Either<Throwable, jakarta.servlet.http.HttpServletResponse> u) Checks for an HTTP response with aRetry-Afterheader, and computes the required wait interval.static HeedRetryAfteratLeast(long milliseconds) Heeds theRetry-Afterheader with a required minimum wait.static HeedRetryAfterHeeds theRetry-Afterheader with a required minimum wait.static HeedRetryAfterHeeds theRetry-Afterheader with a wait ofRetryConfig.DEFAULT_WAIT_DURATIONif none is required by a header.static HeedRetryAfterheed()Heeds theRetry-Afterheader with no wait if none is required by a header.static HeedRetryAfterheed(io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse> extending) Extends anIntervalBiFunctionto heed anyRetry-Afterheader in the response.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 fromRetryAfterParser.
-
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
Heeds theRetry-Afterheader with a required minimum wait.- Parameters:
milliseconds- the minimum wait in milliseconds.- Returns:
- function that waits for the
Retry-Afterinterval with a minimum.
-
atLeast
Heeds theRetry-Afterheader with a required minimum wait.- Parameters:
minimum- the minimum wait.- Returns:
- function that waits for the
Retry-Afterinterval with a minimum.
-
defaulted
Heeds theRetry-Afterheader with a wait ofRetryConfig.DEFAULT_WAIT_DURATIONif none is required by a header.- Returns:
- function that waits for the
Retry-Afterinterval with a default minimum.
-
heed
Heeds theRetry-Afterheader with no wait if none is required by a header.- Returns:
- function that waits for the
Retry-Afterinterval.
-
heed
public static HeedRetryAfter heed(io.github.resilience4j.core.IntervalBiFunction<jakarta.servlet.http.HttpServletResponse> extending) Extends anIntervalBiFunctionto heed anyRetry-Afterheader in the response.- Parameters:
extending- the function to extend.- Returns:
- a function that extends the wait interval to heed the
Retry-Afterheader.
-
apply
public Long apply(Integer t, io.github.resilience4j.core.functions.Either<Throwable, jakarta.servlet.http.HttpServletResponse> u) Checks for an HTTP response with aRetry-Afterheader, and computes the required wait interval.- Specified by:
applyin interfaceBiFunction<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-Afterheader.
-