Package dev.failsafe
Class FallbackBuilder<R>
java.lang.Object
dev.failsafe.PolicyBuilder<FallbackBuilder<R>,FallbackConfig<R>,R>
dev.failsafe.FailurePolicyBuilder<FallbackBuilder<R>,FallbackConfig<R>,R>
dev.failsafe.FallbackBuilder<R>
- Type Parameters:
R
- result type
- All Implemented Interfaces:
PolicyListeners<FallbackBuilder<R>,
R>
public class FallbackBuilder<R>
extends FailurePolicyBuilder<FallbackBuilder<R>,FallbackConfig<R>,R>
implements PolicyListeners<FallbackBuilder<R>,R>
Builds
Fallback
instances.
- By default, any exception is considered a failure and will be handled by the policy. You can override this by
specifying your own
handle
conditions. The default exception handling condition will only be overridden by another condition that handles failure exceptions such asFailurePolicyBuilder.handle(Class)
orFailurePolicyBuilder.handleIf(CheckedBiPredicate)
. Specifying a condition that only handles results, such asFailurePolicyBuilder.handleResult(Object)
orFailurePolicyBuilder.handleResultIf(CheckedPredicate)
will not replace the default exception handling condition. - If multiple
handle
conditions are specified, any condition that matches an execution result or failure will trigger policy handling.
Note:
- This class extends
FailurePolicyBuilder
which offers additional configuration. - This class is not threadsafe.
- See Also:
-
Field Summary
Fields inherited from class dev.failsafe.PolicyBuilder
config
-
Constructor Summary
ConstructorsConstructorDescriptionFallbackBuilder
(FallbackConfig<R> config) FallbackBuilder
(CheckedFunction<ExecutionAttemptedEvent<R>, R> fallback, CheckedFunction<ExecutionAttemptedEvent<R>, CompletableFuture<R>> fallbackStage) -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a newFallback
using the builder's configuration.onFailedAttempt
(EventListener<ExecutionAttemptedEvent<R>> listener) Registers thelistener
to be called when the last execution attempt prior to the fallback failed.Configures the fallback to run asynchronously.Methods inherited from class dev.failsafe.FailurePolicyBuilder
failurePredicateFor, failurePredicateFor, handle, handle, handle, handleIf, handleIf, handleResult, handleResultIf, resultPredicateFor, resultPredicateFor
Methods inherited from class dev.failsafe.PolicyBuilder
onFailure, onSuccess
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.failsafe.PolicyListeners
onFailure, onSuccess
-
Constructor Details
-
FallbackBuilder
FallbackBuilder(CheckedFunction<ExecutionAttemptedEvent<R>, R> fallback, CheckedFunction<ExecutionAttemptedEvent<R>, CompletableFuture<R>> fallbackStage) -
FallbackBuilder
FallbackBuilder(FallbackConfig<R> config)
-
-
Method Details
-
build
Builds a newFallback
using the builder's configuration. -
onFailedAttempt
Registers thelistener
to be called when the last execution attempt prior to the fallback failed. You can also useonFailure
to determine when the fallback attempt also fails.Note: Any exceptions that are thrown from within the
listener
are ignored.- Throws:
NullPointerException
- iflistener
is null
-
withAsync
Configures the fallback to run asynchronously.
-