Class PolicyExecutor<R>

    • Field Detail

      • policyIndex

        private final int policyIndex
        Index of the policy relative to other policies in a composition, innermost first
      • failurePolicy

        private final FailurePolicy<R> failurePolicy
        Optional APIs for policies that support them
    • Constructor Detail

      • PolicyExecutor

        protected PolicyExecutor​(Policy<R> policy,
                                 int policyIndex)
    • Method Detail

      • getPolicyIndex

        public int getPolicyIndex()
        Returns the index of the policy relative to other policies in a composition, where the innermost policy in a composition has an index of 0.
      • preExecute

        protected ExecutionResult<R> preExecute()
        Called before execution to return an alternative result or exception such as if execution is not allowed or needed.
      • preExecuteAsync

        protected java.util.concurrent.CompletableFuture<ExecutionResult<R>> preExecuteAsync​(Scheduler scheduler,
                                                                                             FailsafeFuture<R> future)
        Called before an async execution to return an alternative result or exception such as if execution is not allowed or needed. Returns null if pre execution is not performed. If the resulting future is completed with a non-result, then execution and post-execution should still be performed. If the resulting future is completed with null, then the execution is assumed to have been cancelled.
      • applyAsync

        public java.util.function.Function<AsyncExecutionInternal<R>,​java.util.concurrent.CompletableFuture<ExecutionResult<R>>> applyAsync​(java.util.function.Function<AsyncExecutionInternal<R>,​java.util.concurrent.CompletableFuture<ExecutionResult<R>>> innerFn,
                                                                                                                                                  Scheduler scheduler,
                                                                                                                                                  FailsafeFuture<R> future)
        Performs an async execution by calling pre-execute else calling the supplier and doing a post-execute. Implementors must handle a null result from a supplier, which indicates that an async execution has occurred, that a result will be recorded separately, and that postExecute handling should not be performed.
      • isFailure

        protected boolean isFailure​(ExecutionResult<R> result)
        Returns whether the result is a success according to the policy. If the {code result} has no result, it is not a failure.