|
4 | 4 |
|
5 | 5 | import java.util.Optional;
|
6 | 6 |
|
| 7 | +/** |
| 8 | + * An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic |
| 9 | + * to the lifecycle of flag evaluation. |
| 10 | + * @param <T> The type of the flag being evaluated. |
| 11 | + */ |
7 | 12 | public interface Hook<T> {
|
| 13 | + /** |
| 14 | + * Runs before flag is resolved. |
| 15 | + * @param ctx Information about the particular flag evaluation |
| 16 | + * @param hints An immutable mapping of data for users to communicate to the hooks. |
| 17 | + * @return An optional {@link EvaluationContext}. If returned, it will be merged with the EvaluationContext instances from other hooks, the client and API. |
| 18 | + */ |
8 | 19 | default Optional<EvaluationContext> before(HookContext<T> ctx, ImmutableMap<String, Object> hints) {
|
9 | 20 | return Optional.empty();
|
10 | 21 | }
|
| 22 | + |
| 23 | + /** |
| 24 | + * Runs after a flag is resolved. |
| 25 | + * @param ctx Information about the particular flag evaluation |
| 26 | + * @param details Information about how the flag was resolved, including any resolved values. |
| 27 | + * @param hints An immutable mapping of data for users to communicate to the hooks. |
| 28 | + */ |
11 | 29 | default void after(HookContext<T> ctx, FlagEvaluationDetails<T> details, ImmutableMap<String, Object> hints) {}
|
| 30 | + |
| 31 | + /** |
| 32 | + * Run when evaluation encounters an error. This will always run. Errors thrown will be swallowed. |
| 33 | + * @param ctx Information about the particular flag evaluation |
| 34 | + * @param error The exception that was thrown. |
| 35 | + * @param hints An immutable mapping of data for users to communicate to the hooks. |
| 36 | + */ |
12 | 37 | default void error(HookContext<T> ctx, Exception error, ImmutableMap<String, Object> hints) {}
|
| 38 | + |
| 39 | + /** |
| 40 | + * Run after flag evaluation, including any error processing. This will always run. Errors will be swallowed. |
| 41 | + * @param ctx Information about the particular flag evaluation |
| 42 | + * @param hints An immutable mapping of data for users to communicate to the hooks. |
| 43 | + */ |
13 | 44 | default void finallyAfter(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
|
14 | 45 | }
|
0 commit comments