Class RetryStatusCodes

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.
Default retry behavior
StatusIdempotentNon-Idempotent
1xxtruetrue
2xxfalsefalse
3xxtruetrue
4xxfalsefalse
408truetrue
409truetrue
429truetrue
5xxtruefalse
501falsefalse
505falsefalse
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The HTTP status code for a retry being too early.
    static final int
    The HTTP status code for a server complaining of too many requests.
  • Method Summary

    Modifier and Type
    Method
    Description
    idempotent(int... additional)
    Returns a predicate with default decisions for an idempotent service.
    nonIdempotent(int... additional)
    Returns a predicate with default decisions for a non-idempotent service.
    only(int... retry)
    Returns a predicate that allows retry for only the explicitly provided status codes.
    boolean
    retries(int code)
    Returns whether the status code allows a retry.
    boolean
    test(jakarta.servlet.http.HttpServletResponse t)
    Tests whether the HTTP response status allows for a retry.

    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.Predicate

    and, negate, or
  • Field Details

    • SC_TOO_EARLY

      public static final int SC_TOO_EARLY
      The HTTP status code for a retry being too early.
      See Also:
    • SC_TOO_MANY_REQUESTS

      public static final int SC_TOO_MANY_REQUESTS
      The HTTP status code for a server complaining of too many requests.
      See Also:
  • Method Details

    • idempotent

      public static RetryStatusCodes idempotent(int... additional)
      Returns a predicate with default decisions for an idempotent service. Idempotent services allow retries of 5xx HTTP status codes except for HttpServletResponse.SC_NOT_IMPLEMENTED and HttpServletResponse.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

      public static RetryStatusCodes nonIdempotent(int... additional)
      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

      public static RetryStatusCodes only(int... retry)
      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 true for 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.
      Specified by:
      test in interface Predicate<jakarta.servlet.http.HttpServletResponse>
      Parameters:
      t - the HTTP response
      Returns:
      whether a retry is allowed based on the status code