java.lang.Object
com.maybeitssquid.retry.RetryStatusCodes
- All Implemented Interfaces:
Predicate<jakarta.servlet.http.HttpServletResponse>
public class RetryStatusCodes
extends Object
implements Predicate<jakarta.servlet.http.HttpServletResponse>
Predicate to decide whether a retry is allowable based on the HTTP response code. By default,
retries are allowed for HTTP response codes in the 1xx and 3xx ranges, as shown in the following
table.
| Status | Idempotent | Non-Idempotent |
|---|---|---|
| 1xx | true | true |
| 2xx | false | false |
| 3xx | true | true |
| 4xx | false | false |
408 | true | true |
409 | true | true |
| 429 | true | true |
| 5xx | true | false |
501 | false | false |
505 | false | false |
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe HTTP status code for a retry being too early.static final intThe HTTP status code for a server complaining of too many requests. -
Method Summary
Modifier and TypeMethodDescriptionstatic RetryStatusCodesidempotent(int... additional) Returns a predicate with default decisions for an idempotent service.static RetryStatusCodesnonIdempotent(int... additional) Returns a predicate with default decisions for a non-idempotent service.static RetryStatusCodesonly(int... retry) Returns a predicate that allows retry for only the explicitly provided status codes.booleanretries(int code) Returns whether the status code allows a retry.booleantest(jakarta.servlet.http.HttpServletResponse t) Tests whether the HTTP response status allows for a retry.
-
Field Details
-
SC_TOO_EARLY
public static final int SC_TOO_EARLYThe HTTP status code for a retry being too early.- See Also:
-
SC_TOO_MANY_REQUESTS
public static final int SC_TOO_MANY_REQUESTSThe HTTP status code for a server complaining of too many requests.- See Also:
-
-
Method Details
-
idempotent
Returns a predicate with default decisions for an idempotent service. Idempotent services allow retries of 5xx HTTP status codes except forHttpServletResponse.SC_NOT_IMPLEMENTEDandHttpServletResponse.SC_HTTP_VERSION_NOT_SUPPORTED.- Parameters:
additional- status codes that are expressly allowed for retry. Codes in this list override defaults.- Returns:
- predicate with decisions for an idempotent service.
-
nonIdempotent
Returns a predicate with default decisions for a non-idempotent service. Non-idempotent services do not allow retries of 5xx HTTP status codes.- Parameters:
additional- status codes that are expressly allowed for retry. Codes in this list override defaults.- Returns:
- predicate with decisions for a non-idempotent service.
-
only
Returns a predicate that allows retry for only the explicitly provided status codes.- Parameters:
retry- status codes that are expressly allowed for retry.- Returns:
- predicate that returns
truefor the provided response codes
-
retries
public boolean retries(int code) Returns whether the status code allows a retry.- Parameters:
code- the status code to check.- Returns:
- whether the status code allows a retry.
-
test
public boolean test(jakarta.servlet.http.HttpServletResponse t) Tests whether the HTTP response status allows for a retry.
-