Package dev.failsafe

Class DelayablePolicyBuilder<S,​C extends DelayablePolicyConfig<R>,​R>

    • Constructor Detail

      • DelayablePolicyBuilder

        protected DelayablePolicyBuilder​(C config)
    • Method Detail

      • withDelay

        public S withDelay​(java.time.Duration delay)
        Sets the delay to occur between execution attempts.
        Throws:
        java.lang.NullPointerException - if delay is null
        java.lang.IllegalArgumentException - if delay <= 0
      • withDelayFn

        public S withDelayFn​(ContextualSupplier<R,​java.time.Duration> delayFunction)
        Sets the delayFunction that computes the next delay before allowing another execution.

        The delayFunction must complete quickly, not have side-effects, and always return the same result for the same input. Exceptions thrown by the delayFunction method 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 ExecutionContext that is provided to the delayFunction may be null if the prior execution exception was manually recorded outside of a Failsafe execution.

        Throws:
        java.lang.NullPointerException - if delayFunction is null
      • withDelayFnOn

        public <F extends java.lang.Throwable> S withDelayFnOn​(ContextualSupplier<R,​java.time.Duration> delayFunction,
                                                               java.lang.Class<F> exception)
        Sets the delayFunction that computes the next delay before allowing another execution. Delays will only occur for exceptions that are assignable from the exception.

        The delayFunction must complete quickly, not have side-effects, and always return the same result for the same input. Exceptions thrown by the delayFunction method 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 ExecutionContext that is provided to the delayFunction may be null if 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 attempt
        exception - the execution exception that is expected in order to trigger the delay
        Throws:
        java.lang.NullPointerException - if delayFunction or exception are null
      • withDelayFnWhen

        public S withDelayFnWhen​(ContextualSupplier<R,​java.time.Duration> delayFunction,
                                 R result)
        Sets the delayFunction that computes the next delay before allowing another execution. Delays will only occur for results that equal the result.

        The delayFunction must complete quickly, not have side-effects, and always return the same result for the same input. Exceptions thrown by the delayFunction method 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 ExecutionContext that is provided to the delayFunction may be null if 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 attempt
        result - the execution result that is expected in order to trigger the delay
        Throws:
        java.lang.NullPointerException - if delayFunction or result are null