public abstract class Hook
extends java.lang.Object
Hook
interface.
Hook currently defines an "evaluation" series, which is composed of two stages: "beforeEvaluation" and "afterEvaluation". These are executed by the SDK before and after the evaluation of a feature flag.
Multiple hooks may be configured in the SDK. By default, the SDK will execute each hook's beforeEvaluation stage in the order they were configured, and afterEvaluation in reverse order. (i.e. myHook1.beforeEvaluation, myHook2.beforeEvaluation, myHook2.afterEvaluation, myHook1.afterEvaluation)
Constructor and Description |
---|
Hook(java.lang.String name)
Creates an instance of
Hook with the given name which will be put into its metadata. |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
afterEvaluation(EvaluationSeriesContext seriesContext,
java.util.Map<java.lang.String,java.lang.Object> seriesData,
EvaluationDetail<LDValue> evaluationDetail)
afterEvaluation(EvaluationSeriesContext, Map, EvaluationDetail) is executed by the SDK at the after the
evaluation of a feature flag. |
java.util.Map<java.lang.String,java.lang.Object> |
beforeEvaluation(EvaluationSeriesContext seriesContext,
java.util.Map<java.lang.String,java.lang.Object> seriesData)
beforeEvaluation(EvaluationSeriesContext, Map) is executed by the SDK at the start of the evaluation of
a feature flag. |
HookMetadata |
getMetadata() |
public Hook(java.lang.String name)
Hook
with the given name which will be put into its metadata.name
- a friendly naem for the hookspublic HookMetadata getMetadata()
public java.util.Map<java.lang.String,java.lang.Object> beforeEvaluation(EvaluationSeriesContext seriesContext, java.util.Map<java.lang.String,java.lang.Object> seriesData)
beforeEvaluation(EvaluationSeriesContext, Map)
is executed by the SDK at the start of the evaluation of
a feature flag. It will not be executed as part of a call to
LDClient.allFlagsState(LDContext, FlagsStateOption...)
.
To provide custom data to the series which will be given back to your Hook
at the next stage of the
series, return a map containing the custom data. You should initialize this map from the seriesData
.
HashMap<String, Object> customData = new HashMap<>(seriesData);
customData.put("foo", "bar");
return Collections.unmodifiableMap(customData);
seriesContext
- container of parameters associated with this evaluationseriesData
- immutable data from the previous stage in evaluation series. beforeEvaluation(EvaluationSeriesContext, Map)
is the first stage in this series, so this will be an immutable empty map.public java.util.Map<java.lang.String,java.lang.Object> afterEvaluation(EvaluationSeriesContext seriesContext, java.util.Map<java.lang.String,java.lang.Object> seriesData, EvaluationDetail<LDValue> evaluationDetail)
afterEvaluation(EvaluationSeriesContext, Map, EvaluationDetail)
is executed by the SDK at the after the
evaluation of a feature flag. It will not be executed as part of a call to
LDClient.allFlagsState(LDContext, FlagsStateOption...)
.
This is currently the last stage of the evaluation series in the Hook
, but that may not be the case in
the future. To ensure forward compatibility, return the seriesData
unmodified.
String value = (String) seriesData.get("foo");
doAThing(value);
return seriesData;
seriesContext
- container of parameters associated with this evaluationseriesData
- immutable data from the previous stage in evaluation series. beforeEvaluation(EvaluationSeriesContext, Map)
is the first stage in this series, so this will be an immutable empty map.evaluationDetail
- the result of the evaluation that took place before this hook was invoked