Package dev.failsafe

Interface Fallback<R>

  • Type Parameters:
    R - result type
    All Superinterfaces:
    Policy<R>
    All Known Implementing Classes:
    FallbackImpl

    public interface Fallback<R>
    extends Policy<R>
    A Policy that handles failures using a fallback function or result.

    This class is threadsafe.

    See Also:
    TimeoutConfig, FallbackBuilder
    • Method Detail

      • builder

        static <R> FallbackBuilder<R> builder​(CheckedRunnable fallback)
        Returns the fallback to be executed if execution fails.
        Throws:
        java.lang.NullPointerException - if fallback is null
      • builder

        static <R> FallbackBuilder<R> builder​(CheckedSupplier<? extends R> fallback)
        Returns the fallback to be executed if execution fails.
        Throws:
        java.lang.NullPointerException - if fallback is null
      • builder

        static <R> FallbackBuilder<R> builder​(R fallbackResult)
        Returns the fallbackResult to be provided if execution fails.
      • builderOfException

        static <R> FallbackBuilder<R> builderOfException​(CheckedFunction<ExecutionAttemptedEvent<? extends R>,​? extends java.lang.Exception> fallback)
        Returns the fallback to be executed if execution fails and allows an alternative exception to be supplied instead. The fallback applies an ExecutionAttemptedEvent and must return an exception.
        Throws:
        java.lang.NullPointerException - if fallback is null
      • builderOfStage

        static <R> FallbackBuilder<R> builderOfStage​(CheckedSupplier<? extends java.util.concurrent.CompletionStage<R>> fallback)
        Returns the fallback to be executed if execution fails.
        Throws:
        java.lang.NullPointerException - if fallback is null
      • of

        static <R> Fallback<R> of​(CheckedRunnable fallback)
        Returns the fallback to be executed if execution fails.
        Throws:
        java.lang.NullPointerException - if fallback is null
      • of

        static <R> Fallback<R> of​(CheckedSupplier<? extends R> fallback)
        Returns the fallback to be executed if execution fails.
        Throws:
        java.lang.NullPointerException - if fallback is null
      • ofException

        static <R> Fallback<R> ofException​(CheckedFunction<ExecutionAttemptedEvent<? extends R>,​? extends java.lang.Exception> fallback)
        Returns the fallback to be executed if execution fails and allows an alternative exception to be supplied instead. The fallback applies an ExecutionAttemptedEvent and must return an exception.
        Throws:
        java.lang.NullPointerException - if fallback is null
      • of

        static <R> Fallback<R> of​(R fallbackResult)
        Returns the fallbackResult to be provided if execution fails.
      • ofStage

        static <R> Fallback<R> ofStage​(CheckedSupplier<? extends java.util.concurrent.CompletionStage<R>> fallback)
        Returns the fallback to be executed if execution fails.
        Throws:
        java.lang.NullPointerException - if fallback is null
      • none

        static Fallback<java.lang.Void> none()
        Returns a fallback that will return a null if execution fails.