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
handleconditions. 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
handleconditions are specified, any condition that matches an execution result or failure will trigger policy handling.
Note:
- This class extends
FailurePolicyBuilderwhich 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 newFallbackusing the builder's configuration.onFailedAttempt(EventListener<ExecutionAttemptedEvent<R>> listener) Registers thelistenerto 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, resultPredicateForMethods inherited from class dev.failsafe.PolicyBuilder
onFailure, onSuccessMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 newFallbackusing the builder's configuration. -
onFailedAttempt
Registers thelistenerto be called when the last execution attempt prior to the fallback failed. You can also useonFailureto determine when the fallback attempt also fails.Note: Any exceptions that are thrown from within the
listenerare ignored.- Throws:
NullPointerException- iflisteneris null
-
withAsync
Configures the fallback to run asynchronously.
-