Package dev.failsafe
Class FallbackBuilder<R>
- java.lang.Object
-
- dev.failsafe.PolicyBuilder<S,C,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>
BuildsFallbackinstances.- 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:
FallbackConfig
-
-
Field Summary
-
Fields inherited from class dev.failsafe.PolicyBuilder
config
-
-
Constructor Summary
Constructors Constructor Description FallbackBuilder(FallbackConfig<R> config)FallbackBuilder(CheckedFunction<ExecutionAttemptedEvent<R>,R> fallback, CheckedFunction<ExecutionAttemptedEvent<R>,java.util.concurrent.CompletableFuture<R>> fallbackStage)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Fallback<R>build()Builds a newFallbackusing the builder's configuration.FallbackBuilder<R>onFailedAttempt(EventListener<ExecutionAttemptedEvent<R>> listener)Registers thelistenerto be called when the last execution attempt prior to the fallback failed.FallbackBuilder<R>withAsync()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 Detail
-
FallbackBuilder
FallbackBuilder(CheckedFunction<ExecutionAttemptedEvent<R>,R> fallback, CheckedFunction<ExecutionAttemptedEvent<R>,java.util.concurrent.CompletableFuture<R>> fallbackStage)
-
FallbackBuilder
FallbackBuilder(FallbackConfig<R> config)
-
-
Method Detail
-
onFailedAttempt
public FallbackBuilder<R> onFailedAttempt(EventListener<ExecutionAttemptedEvent<R>> listener)
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:
java.lang.NullPointerException- iflisteneris null
-
withAsync
public FallbackBuilder<R> withAsync()
Configures the fallback to run asynchronously.
-
-