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 Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <R> FallbackBuilder<R>
builder(FallbackConfig<R> config)
Creates a new FallbackBuilder that will be based on theconfig
.static <R> FallbackBuilder<R>
builder(CheckedConsumer<ExecutionAttemptedEvent<? extends R>> fallback)
Returns thefallback
to be executed if execution fails.static <R> FallbackBuilder<R>
builder(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends R> fallback)
Returns thefallback
to be executed if execution fails.static <R> FallbackBuilder<R>
builder(CheckedRunnable fallback)
Returns thefallback
to be executed if execution fails.static <R> FallbackBuilder<R>
builder(CheckedSupplier<? extends R> fallback)
Returns thefallback
to be executed if execution fails.static <R> FallbackBuilder<R>
builder(R fallbackResult)
Returns thefallbackResult
to be provided if execution fails.static <R> FallbackBuilder<R>
builderOfException(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends java.lang.Exception> fallback)
Returns thefallback
to be executed if execution fails and allows an alternative exception to be supplied instead.static <R> FallbackBuilder<R>
builderOfStage(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends java.util.concurrent.CompletionStage<R>> fallback)
Returns thefallback
to be executed if execution fails.static <R> FallbackBuilder<R>
builderOfStage(CheckedSupplier<? extends java.util.concurrent.CompletionStage<R>> fallback)
Returns thefallback
to be executed if execution fails.FallbackConfig<R>
getConfig()
Returns theFallbackConfig
that the Fallback was built with.static Fallback<java.lang.Void>
none()
Returns a fallback that will return a null if execution fails.static <R> Fallback<R>
of(CheckedConsumer<ExecutionAttemptedEvent<? extends R>> fallback)
Returns thefallback
to be executed if execution fails.static <R> Fallback<R>
of(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends R> fallback)
Returns thefallback
to be executed if execution fails.static <R> Fallback<R>
of(CheckedRunnable fallback)
Returns thefallback
to be executed if execution fails.static <R> Fallback<R>
of(CheckedSupplier<? extends R> fallback)
Returns thefallback
to be executed if execution fails.static <R> Fallback<R>
of(R fallbackResult)
Returns thefallbackResult
to be provided if execution fails.static <R> Fallback<R>
ofException(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends java.lang.Exception> fallback)
Returns thefallback
to be executed if execution fails and allows an alternative exception to be supplied instead.static <R> Fallback<R>
ofStage(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends java.util.concurrent.CompletionStage<R>> fallback)
Returns thefallback
to be executed if execution fails.static <R> Fallback<R>
ofStage(CheckedSupplier<? extends java.util.concurrent.CompletionStage<R>> fallback)
Returns thefallback
to be executed if execution fails.-
Methods inherited from interface dev.failsafe.Policy
toExecutor
-
-
-
-
Method Detail
-
builder
static <R> FallbackBuilder<R> builder(FallbackConfig<R> config)
Creates a new FallbackBuilder that will be based on theconfig
.
-
builder
static <R> FallbackBuilder<R> builder(CheckedRunnable fallback)
Returns thefallback
to be executed if execution fails.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
builder
static <R> FallbackBuilder<R> builder(CheckedSupplier<? extends R> fallback)
Returns thefallback
to be executed if execution fails.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
builder
static <R> FallbackBuilder<R> builder(CheckedConsumer<ExecutionAttemptedEvent<? extends R>> fallback)
Returns thefallback
to be executed if execution fails. Thefallback
accepts anExecutionAttemptedEvent
.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
builder
static <R> FallbackBuilder<R> builder(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends R> fallback)
Returns thefallback
to be executed if execution fails. Thefallback
applies anExecutionAttemptedEvent
.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
builder
static <R> FallbackBuilder<R> builder(R fallbackResult)
Returns thefallbackResult
to be provided if execution fails.
-
builderOfException
static <R> FallbackBuilder<R> builderOfException(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends java.lang.Exception> fallback)
Returns thefallback
to be executed if execution fails and allows an alternative exception to be supplied instead. Thefallback
applies anExecutionAttemptedEvent
and must return an exception.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
builderOfStage
static <R> FallbackBuilder<R> builderOfStage(CheckedSupplier<? extends java.util.concurrent.CompletionStage<R>> fallback)
Returns thefallback
to be executed if execution fails.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
builderOfStage
static <R> FallbackBuilder<R> builderOfStage(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends java.util.concurrent.CompletionStage<R>> fallback)
Returns thefallback
to be executed if execution fails. Thefallback
accepts anExecutionAttemptedEvent
.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
of
static <R> Fallback<R> of(CheckedRunnable fallback)
Returns thefallback
to be executed if execution fails.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
of
static <R> Fallback<R> of(CheckedSupplier<? extends R> fallback)
Returns thefallback
to be executed if execution fails.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
of
static <R> Fallback<R> of(CheckedConsumer<ExecutionAttemptedEvent<? extends R>> fallback)
Returns thefallback
to be executed if execution fails. Thefallback
accepts anExecutionAttemptedEvent
.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
of
static <R> Fallback<R> of(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends R> fallback)
Returns thefallback
to be executed if execution fails. Thefallback
applies anExecutionAttemptedEvent
.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
ofException
static <R> Fallback<R> ofException(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends java.lang.Exception> fallback)
Returns thefallback
to be executed if execution fails and allows an alternative exception to be supplied instead. Thefallback
applies anExecutionAttemptedEvent
and must return an exception.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
of
static <R> Fallback<R> of(R fallbackResult)
Returns thefallbackResult
to be provided if execution fails.
-
ofStage
static <R> Fallback<R> ofStage(CheckedSupplier<? extends java.util.concurrent.CompletionStage<R>> fallback)
Returns thefallback
to be executed if execution fails.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
ofStage
static <R> Fallback<R> ofStage(CheckedFunction<ExecutionAttemptedEvent<? extends R>,? extends java.util.concurrent.CompletionStage<R>> fallback)
Returns thefallback
to be executed if execution fails. Thefallback
accepts anExecutionAttemptedEvent
.- Throws:
java.lang.NullPointerException
- iffallback
is null
-
none
static Fallback<java.lang.Void> none()
Returns a fallback that will return a null if execution fails.
-
getConfig
FallbackConfig<R> getConfig()
Returns theFallbackConfig
that the Fallback was built with.
-
-