|
18 | 18 | import net.jodah.failsafe.internal.util.Assert; |
19 | 19 |
|
20 | 20 | import java.util.ArrayList; |
| 21 | +import java.util.Arrays; |
21 | 22 | import java.util.Collections; |
22 | 23 | import java.util.List; |
23 | 24 |
|
@@ -60,6 +61,38 @@ public static <R, P extends Policy<R>> FailsafeExecutor<R> with(P outerPolicy, P |
60 | 61 | return new FailsafeExecutor<>(policyList); |
61 | 62 | } |
62 | 63 |
|
| 64 | + /** |
| 65 | + * Creates and returns a new {@link FailsafeExecutor} instance that will handle failures according to the given {@code |
| 66 | + * policies}. The {@code policies} are composed around an execution and will handle execution results in reverse, with |
| 67 | + * the last policy being applied first. For example, consider: |
| 68 | + * <p> |
| 69 | + * <pre> |
| 70 | + * Failsafe.with(fallback, retryPolicy, circuitBreaker).get(supplier); |
| 71 | + * </pre> |
| 72 | + * </p> |
| 73 | + * This results in the following internal composition when executing the {@code supplier} and handling its result: |
| 74 | + * <p> |
| 75 | + * <pre> |
| 76 | + * Fallback(RetryPolicy(CircuitBreaker(Supplier))) |
| 77 | + * </pre> |
| 78 | + * </p> |
| 79 | + * This means the {@code CircuitBreaker} is first to evaluate the {@code Supplier}'s result, then the {@code |
| 80 | + * RetryPolicy}, then the {@code Fallback}. Each policy makes its own determination as to whether the result |
| 81 | + * represents a failure. This allows different policies to be used for handling different types of failures. |
| 82 | + * |
| 83 | + * @param <R> result type |
| 84 | + * @param <P> policy type |
| 85 | + * @throws NullPointerException if {@code policies} is null |
| 86 | + * @throws IllegalArgumentException if {@code policies} is empty |
| 87 | + * @deprecated Use {@link #with(Policy, Policy[])} instead |
| 88 | + */ |
| 89 | + @Deprecated |
| 90 | + public static <R, P extends Policy<R>> FailsafeExecutor<R> with(P[] policies) { |
| 91 | + Assert.notNull(policies, "policies"); |
| 92 | + Assert.isTrue(policies.length > 0, "At least one policy must be supplied"); |
| 93 | + return new FailsafeExecutor<>(Arrays.asList(policies)); |
| 94 | + } |
| 95 | + |
63 | 96 | /** |
64 | 97 | * Creates and returns a new {@link FailsafeExecutor} instance that will handle failures according to the given {@code |
65 | 98 | * policies}. The {@code policies} are composed around an execution and will handle execution results in reverse, with |
|
0 commit comments