-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathHook.java
57 lines (51 loc) · 2.15 KB
/
Hook.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dev.openfeature.sdk;
import java.util.Map;
import java.util.Optional;
/**
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
* @param <T> The type of the flag being evaluated.
*/
public interface Hook<T> {
/**
* Runs before flag is resolved.
*
* @param ctx Information about the particular flag evaluation
* @param hints An immutable mapping of data for users to communicate to the hooks.
* @return An optional {@link EvaluationContext}. If returned, it will be merged with the EvaluationContext
* instances from other hooks, the client and API.
*/
default Optional<EvaluationContext> before(HookContext<T> ctx, Map<String, Object> hints) {
return Optional.empty();
}
/**
* Runs after a flag is resolved.
*
* @param ctx Information about the particular flag evaluation
* @param details Information about how the flag was resolved, including any resolved values.
* @param hints An immutable mapping of data for users to communicate to the hooks.
*/
default void after(HookContext<T> ctx, FlagEvaluationDetails<T> details, Map<String, Object> hints) {
}
/**
* Run when evaluation encounters an error. This will always run. Errors thrown will be swallowed.
*
* @param ctx Information about the particular flag evaluation
* @param error The exception that was thrown.
* @param hints An immutable mapping of data for users to communicate to the hooks.
*/
default void error(HookContext<T> ctx, Exception error, Map<String, Object> hints) {
}
/**
* Run after flag evaluation, including any error processing. This will always run. Errors will be swallowed.
*
* @param ctx Information about the particular flag evaluation
* @param hints An immutable mapping of data for users to communicate to the hooks.
*/
default void finallyAfter(HookContext<T> ctx, Map<String, Object> hints) {
}
default boolean supportsFlagValueType(FlagValueType flagValueType) {
return true;
}
}