Class FailurePolicyBuilder<S, C extends FailurePolicyConfig<R>, R>
java.lang.Object
dev.failsafe.PolicyBuilder<S,C,R>
dev.failsafe.FailurePolicyBuilder<S,C,R>
- Type Parameters:
S- self typeC- config typeR- result type
- All Implemented Interfaces:
PolicyListeners<S,R>
- Direct Known Subclasses:
DelayablePolicyBuilder, FallbackBuilder
public abstract class FailurePolicyBuilder<S, C extends FailurePolicyConfig<R>, R>
extends PolicyBuilder<S,C,R>
A Policy that allows configurable conditions to determine whether an execution is a failure.
- 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 ashandle(Class)orhandleIf(CheckedBiPredicate). Specifying a condition that only handles results, such ashandleResult(Object)orhandleResultIf(CheckedPredicate)will not replace the default exception handling condition. - If multiple
handleconditions are specified, any condition that matches an execution result or exception will trigger policy handling.
-
Field Summary
Fields inherited from class PolicyBuilder
config -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static <R> CheckedBiPredicate<R, Throwable> failurePredicateFor(CheckedPredicate<? extends Throwable> failurePredicate) Returns a predicate that evaluates thefailurePredicateagainst a failure.(package private) static <R> CheckedBiPredicate<R, Throwable> failurePredicateFor(List<Class<? extends Throwable>> failures) Returns a predicate that returns whether any of thefailuresare assignable from an execution failure.Specifies the exception to handle as a failure.final SSpecifies the exceptions to handle as failures.Specifies the exceptions to handle as failures.handleIf(CheckedBiPredicate<R, ? extends Throwable> resultPredicate) Specifies that a failure has occurred if theresultPredicatematches the execution result.handleIf(CheckedPredicate<? extends Throwable> failurePredicate) Specifies that a failure has occurred if thefailurePredicatematches the exception.handleResult(R result) Specifies that a failure has occurred if theresultmatches the execution result.handleResultIf(CheckedPredicate<R> resultPredicate) Specifies that a failure has occurred if theresultPredicatematches the execution result.(package private) static <R> CheckedBiPredicate<R, Throwable> resultPredicateFor(CheckedPredicate<R> resultPredicate) Returns a predicate that evaluates theresultPredicateagainst a result, when present.(package private) static <R> CheckedBiPredicate<R, Throwable> resultPredicateFor(R result) Returns a predicate that evaluates whether theresultequals an execution result.Methods inherited from class PolicyBuilder
onFailure, onSuccess
-
Constructor Details
-
FailurePolicyBuilder
-
-
Method Details
-
handle
Specifies the exception to handle as a failure. Any exception that is assignable from theexceptionwill be handled.- Throws:
NullPointerException- ifexceptionis null
-
handle
Specifies the exceptions to handle as failures. Any exceptions that are assignable from theexceptionswill be handled.- Throws:
NullPointerException- ifexceptionsis nullIllegalArgumentException- if exceptions is empty
-
handle
Specifies the exceptions to handle as failures. Any exceptions that are assignable from theexceptionswill be handled.- Throws:
NullPointerException- ifexceptionsis nullIllegalArgumentException- if exceptions is null or empty
-
handleIf
Specifies that a failure has occurred if thefailurePredicatematches the exception. Any exception thrown from thefailurePredicateis treated as afalseresult.- Throws:
NullPointerException- iffailurePredicateis null
-
handleIf
Specifies that a failure has occurred if theresultPredicatematches the execution result. Any exception thrown from theresultPredicateis treated as afalseresult.- Throws:
NullPointerException- ifresultPredicateis null
-
handleResult
-
handleResultIf
Specifies that a failure has occurred if theresultPredicatematches the execution result. This method is only considered when a result is returned from an execution, not when an exception is thrown. To handle results or exceptions with the same condition, usehandleIf(CheckedBiPredicate). Any exception thrown from theresultPredicateis treated as afalseresult.- Throws:
NullPointerException- ifresultPredicateis null
-
resultPredicateFor
Returns a predicate that evaluates whether theresultequals an execution result. -
failurePredicateFor
static <R> CheckedBiPredicate<R, Throwable> failurePredicateFor(CheckedPredicate<? extends Throwable> failurePredicate) Returns a predicate that evaluates thefailurePredicateagainst a failure. -
resultPredicateFor
Returns a predicate that evaluates theresultPredicateagainst a result, when present.Short-circuits to false without invoking
resultPredicate, when result is not present (i.e. BiPredicate.test(null, Throwable)). -
failurePredicateFor
static <R> CheckedBiPredicate<R, Throwable> failurePredicateFor(List<Class<? extends Throwable>> failures) Returns a predicate that returns whether any of thefailuresare assignable from an execution failure.
-