Package dev.failsafe
Class DelayablePolicyBuilder<S,C extends DelayablePolicyConfig<R>,R>
- java.lang.Object
-
- dev.failsafe.PolicyBuilder<S,C,R>
-
- dev.failsafe.FailurePolicyBuilder<S,C,R>
-
- dev.failsafe.DelayablePolicyBuilder<S,C,R>
-
- Type Parameters:
S- self typeC- config typeR- result type
- All Implemented Interfaces:
PolicyListeners<S,R>
- Direct Known Subclasses:
CircuitBreakerBuilder,RetryPolicyBuilder
public abstract class DelayablePolicyBuilder<S,C extends DelayablePolicyConfig<R>,R> extends FailurePolicyBuilder<S,C,R>
A builder of policies that can be delayed between executions.
-
-
Field Summary
-
Fields inherited from class dev.failsafe.PolicyBuilder
config
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDelayablePolicyBuilder(C config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SwithDelay(java.time.Duration delay)Sets thedelayto occur between execution attempts.SwithDelayFn(ContextualSupplier<R,java.time.Duration> delayFunction)Sets thedelayFunctionthat computes the next delay before allowing another execution.<F extends java.lang.Throwable>
SwithDelayFnOn(ContextualSupplier<R,java.time.Duration> delayFunction, java.lang.Class<F> exception)Sets thedelayFunctionthat computes the next delay before allowing another execution.SwithDelayFnWhen(ContextualSupplier<R,java.time.Duration> delayFunction, R result)Sets thedelayFunctionthat computes the next delay before allowing another execution.-
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
-
-
-
-
Constructor Detail
-
DelayablePolicyBuilder
protected DelayablePolicyBuilder(C config)
-
-
Method Detail
-
withDelay
public S withDelay(java.time.Duration delay)
Sets thedelayto occur between execution attempts.- Throws:
java.lang.NullPointerException- ifdelayis nulljava.lang.IllegalArgumentException- ifdelay<= 0
-
withDelayFn
public S withDelayFn(ContextualSupplier<R,java.time.Duration> delayFunction)
Sets thedelayFunctionthat computes the next delay before allowing another execution.The
delayFunctionmust complete quickly, not have side-effects, and always return the same result for the same input. Exceptions thrown by thedelayFunctionmethod will not be handled and will cause Failsafe's execution to abort.Notes:
- A negative return value will cause Failsafe to use a configured fixed or backoff delay
- Any configured jitter is still applied to DelayFunction provided values
- Any configured max duration is still applied to DelayFunction provided values
- The
ExecutionContextthat is provided to thedelayFunctionmay benullif the prior execution exception was manually recorded outside of a Failsafe execution.
- Throws:
java.lang.NullPointerException- ifdelayFunctionis null
-
withDelayFnOn
public <F extends java.lang.Throwable> S withDelayFnOn(ContextualSupplier<R,java.time.Duration> delayFunction, java.lang.Class<F> exception)
Sets thedelayFunctionthat computes the next delay before allowing another execution. Delays will only occur for exceptions that are assignable from theexception.The
delayFunctionmust complete quickly, not have side-effects, and always return the same result for the same input. Exceptions thrown by thedelayFunctionmethod will not be handled and will cause Failsafe's execution to abort.Notes:
- A negative return value will cause Failsafe to use a configured fixed or backoff delay
- Any configured jitter is still applied to DelayFunction provided values
- Any configured max duration is still applied to DelayFunction provided values
- The
ExecutionContextthat is provided to thedelayFunctionmay benullif the prior execution exception was manually recorded outside of a Failsafe execution.
- Type Parameters:
F- exception type- Parameters:
delayFunction- the function to use to compute the delay before a next attemptexception- the execution exception that is expected in order to trigger the delay- Throws:
java.lang.NullPointerException- ifdelayFunctionorexceptionare null
-
withDelayFnWhen
public S withDelayFnWhen(ContextualSupplier<R,java.time.Duration> delayFunction, R result)
Sets thedelayFunctionthat computes the next delay before allowing another execution. Delays will only occur for results that equal theresult.The
delayFunctionmust complete quickly, not have side-effects, and always return the same result for the same input. Exceptions thrown by thedelayFunctionmethod will not be handled and will cause Failsafe's execution to abort.Notes:
- A negative return value will cause Failsafe to use a configured fixed or backoff delay
- Any configured jitter is still applied to DelayFunction provided values
- Any configured max duration is still applied to DelayFunction provided values
- The
ExecutionContextthat is provided to thedelayFunctionmay benullif the prior execution exception was manually recorded outside of a Failsafe execution.
- Parameters:
delayFunction- the function to use to compute the delay before a next attemptresult- the execution result that is expected in order to trigger the delay- Throws:
java.lang.NullPointerException- ifdelayFunctionorresultare null
-
-