Package dev.failsafe
Interface Fallback<R>
- Type Parameters:
R
- result type
- All Superinterfaces:
Policy<R>
- All Known Implementing Classes:
FallbackImpl
A Policy that handles failures using a fallback function or result.
This class is threadsafe.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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 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 CompletionStage<R>> fallback) Returns thefallback
to be executed if execution fails.static <R> FallbackBuilder
<R> builderOfStage
(CheckedSupplier<? extends CompletionStage<R>> fallback) Returns thefallback
to be executed if execution fails.Returns theFallbackConfig
that the Fallback was built with.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 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 CompletionStage<R>> fallback) Returns thefallback
to be executed if execution fails.static <R> Fallback
<R> ofStage
(CheckedSupplier<? extends CompletionStage<R>> fallback) Returns thefallback
to be executed if execution fails.Methods inherited from interface dev.failsafe.Policy
toExecutor
-
Method Details
-
builder
Creates a new FallbackBuilder that will be based on theconfig
. -
builder
Returns thefallback
to be executed if execution fails.- Throws:
NullPointerException
- iffallback
is null
-
builder
Returns thefallback
to be executed if execution fails.- Throws:
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:
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:
NullPointerException
- iffallback
is null
-
builder
Returns thefallbackResult
to be provided if execution fails. -
builderOfException
static <R> FallbackBuilder<R> builderOfException(CheckedFunction<ExecutionAttemptedEvent<? extends R>, ? extends 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:
NullPointerException
- iffallback
is null
-
builderOfStage
static <R> FallbackBuilder<R> builderOfStage(CheckedSupplier<? extends CompletionStage<R>> fallback) Returns thefallback
to be executed if execution fails.- Throws:
NullPointerException
- iffallback
is null
-
builderOfStage
static <R> FallbackBuilder<R> builderOfStage(CheckedFunction<ExecutionAttemptedEvent<? extends R>, ? extends CompletionStage<R>> fallback) Returns thefallback
to be executed if execution fails. Thefallback
accepts anExecutionAttemptedEvent
.- Throws:
NullPointerException
- iffallback
is null
-
of
Returns thefallback
to be executed if execution fails.- Throws:
NullPointerException
- iffallback
is null
-
of
Returns thefallback
to be executed if execution fails.- Throws:
NullPointerException
- iffallback
is null
-
of
Returns thefallback
to be executed if execution fails. Thefallback
accepts anExecutionAttemptedEvent
.- Throws:
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:
NullPointerException
- iffallback
is null
-
ofException
static <R> Fallback<R> ofException(CheckedFunction<ExecutionAttemptedEvent<? extends R>, ? extends 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:
NullPointerException
- iffallback
is null
-
of
Returns thefallbackResult
to be provided if execution fails. -
ofStage
Returns thefallback
to be executed if execution fails.- Throws:
NullPointerException
- iffallback
is null
-
ofStage
static <R> Fallback<R> ofStage(CheckedFunction<ExecutionAttemptedEvent<? extends R>, ? extends CompletionStage<R>> fallback) Returns thefallback
to be executed if execution fails. Thefallback
accepts anExecutionAttemptedEvent
.- Throws:
NullPointerException
- iffallback
is null
-
none
Returns a fallback that will return a null if execution fails. -
getConfig
FallbackConfig<R> getConfig()Returns theFallbackConfig
that the Fallback was built with.
-