Skip to content

Commit 821122f

Browse files
committed
Add Failsafe.with(Policy[]) for backwards binary compatibility
1 parent b3a70bd commit 821122f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 2.4.3
2+
3+
### Bug Fixes
4+
5+
- Fixed #289 - Binary imcompatibility with code that was compiled against previous Failsafe versions.
6+
17
# 2.4.2
28

39
### Improvements

src/main/java/net/jodah/failsafe/Failsafe.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.jodah.failsafe.internal.util.Assert;
1919

2020
import java.util.ArrayList;
21+
import java.util.Arrays;
2122
import java.util.Collections;
2223
import java.util.List;
2324

@@ -60,6 +61,38 @@ public static <R, P extends Policy<R>> FailsafeExecutor<R> with(P outerPolicy, P
6061
return new FailsafeExecutor<>(policyList);
6162
}
6263

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+
6396
/**
6497
* Creates and returns a new {@link FailsafeExecutor} instance that will handle failures according to the given {@code
6598
* policies}. The {@code policies} are composed around an execution and will handle execution results in reverse, with

0 commit comments

Comments
 (0)