forked from open-feature/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeatureProvider.java
84 lines (71 loc) · 3.09 KB
/
FeatureProvider.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package dev.openfeature.sdk;
import java.util.ArrayList;
import java.util.List;
/**
* The interface implemented by upstream flag providers to resolve flags for
* their service. If you want to support realtime events with your provider, you
* should extend {@link EventProvider}
*/
public interface FeatureProvider {
Metadata getMetadata();
default List<Hook> getProviderHooks() {
return new ArrayList<>();
}
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx);
ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx);
ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx);
ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx);
ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext ctx);
/**
* This method is called before a provider is used to evaluate flags. Providers
* can overwrite this method,
* if they have special initialization needed prior being called for flag
* evaluation.
* <p>
* It is ok if the method is expensive as it is executed in the background. All
* runtime exceptions will be
* caught and logged.
* </p>
*/
default void initialize(EvaluationContext evaluationContext) throws Exception {
// Intentionally left blank
}
/**
* This method is called when a new provider is about to be used to evaluate
* flags, or the SDK is shut down.
* Providers can overwrite this method, if they have special shutdown actions
* needed.
* <p>
* It is ok if the method is expensive as it is executed in the background. All
* runtime exceptions will be
* caught and logged.
* </p>
*/
default void shutdown() {
// Intentionally left blank
}
/**
* Returns a representation of the current readiness of the provider.
* If the provider needs to be initialized, it should return {@link ProviderState#NOT_READY}.
* If the provider is in an error state, it should return {@link ProviderState#ERROR}.
* If the provider is functioning normally, it should return {@link ProviderState#READY}.
*
* <p><i>Providers which do not implement this method are assumed to be ready immediately.</i></p>
*
* @return ProviderState
* @deprecated The state is handled by the SDK internally. Query the state from the {@link Client} instead.
*/
@Deprecated
default ProviderState getState() {
return ProviderState.READY;
}
/**
* Feature provider implementations can opt in for to support Tracking by implementing this method.
*
* @param eventName The name of the tracking event
* @param context Evaluation context used in flag evaluation (Optional)
* @param details Data pertinent to a particular tracking event (Optional)
*/
default void track(String eventName, EvaluationContext context, TrackingEventDetails details) {
}
}