/** * Records a failed execution and returns true if a retry can be performed for the {@code failure}, else returns false * and completes the execution. * <p> * Alias of {@link #canRetryOn(Throwable)} * * @throws NullPointerException if {@code failure} is null * @throws IllegalStateException if the execution is already complete */ public boolean recordFailure(Throwable failure) { return canRetryOn(failure); }
/** * Records and completes the execution successfully. * * @throws IllegalStateException if the execution is already complete */ public void complete() { postExecute(ExecutionResult.NONE); }
/** * Calls the {@code supplier} synchronously, handling results according to the configured policies. * * @throws FailsafeException if the {@code supplier} fails with a checked Exception or if interrupted while * waiting to perform a retry. * @throws CircuitBreakerOpenException if a configured circuit breaker is open */ @SuppressWarnings("unchecked") private <T> T call(Function<Execution, CheckedSupplier<?>> supplierFn) { Execution execution = new Execution(this); Supplier<ExecutionResult> supplier = Functions.resultSupplierOf(supplierFn.apply(execution), execution); ExecutionResult result = execution.executeSync(supplier); if (result.getFailure() != null) throw result.getFailure() instanceof RuntimeException ? (RuntimeException) result.getFailure() : new FailsafeException(result.getFailure()); return (T) result.getResult(); }
/** * Records an execution and returns true if a retry can be performed for the {@code result}, else returns false and * marks the execution as complete. * * @throws IllegalStateException if the execution is already complete */ public boolean canRetryFor(Object result) { return !postExecute(new ExecutionResult(result, null)); }
/** * Records and attempts to complete the execution with the {@code result}. Returns true on success, else false if * completion failed and execution should be retried. * * @throws IllegalStateException if the execution is already complete */ public boolean complete(Object result) { return postExecute(new ExecutionResult(result, null)); }
/** * Records an execution and returns true if a retry can be performed for the {@code result} or {@code failure}, else * returns false and marks the execution as complete. * * @throws IllegalStateException if the execution is already complete */ public boolean canRetryFor(Object result, Throwable failure) { return !postExecute(new ExecutionResult(result, failure)); }
/** * Records an execution and returns true if a retry can be performed for the {@code failure}, else returns false and * marks the execution as complete. * * @throws NullPointerException if {@code failure} is null * @throws IllegalStateException if the execution is already complete */ public boolean canRetryOn(Throwable failure) { Assert.notNull(failure, "failure"); return !postExecute(new ExecutionResult(null, failure)); }