Class Hook
Hook
interface.
Multiple hooks may be configured in the SDK. By default, the SDK will execute each hook's before stages in the order they were configured, and each hook's after stages in reverse order. (i.e. myHook1.beforeEvaluation, myHook2.beforeEvaluation, myHook2.afterEvaluation, myHook1.afterEvaluation)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionafterEvaluation
(EvaluationSeriesContext seriesContext, Map<String, Object> seriesData, EvaluationDetail<LDValue> evaluationDetail) afterEvaluation(EvaluationSeriesContext, Map, EvaluationDetail)
is executed by the SDK at the after the evaluation of a feature flag.afterIdentify
(IdentifySeriesContext seriesContext, Map<String, Object> seriesData, IdentifySeriesResult result) afterIdentify(IdentifySeriesContext, Map, IdentifySeriesResult)
is called during the execution of the identify process, after the operation completes.void
afterTrack
(TrackSeriesContext seriesContext) afterTrack(TrackSeriesContext)
is called during the execution of the track process after the event has been enqueued.beforeEvaluation
(EvaluationSeriesContext seriesContext, Map<String, Object> seriesData) beforeEvaluation(EvaluationSeriesContext, Map)
is executed by the SDK at the start of the evaluation of a feature flag.beforeIdentify
(IdentifySeriesContext seriesContext, Map<String, Object> seriesData) beforeIdentify(IdentifySeriesContext, Map)
is called during the execution of the identify process before the operation completes, but after any context modifications are performed.
-
Constructor Details
-
Hook
Creates an instance ofHook
with the given name which will be put into its metadata.- Parameters:
name
- a friendly name for the hooks
-
-
Method Details
-
getMetadata
- Returns:
- the hooks metadata
-
beforeEvaluation
public Map<String,Object> beforeEvaluation(EvaluationSeriesContext seriesContext, Map<String, 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 toLDClient.allFlags()
.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 theseriesData
.HashMap<String, Object> customData = new HashMap<>(seriesData); customData.put("foo", "bar"); return Collections.unmodifiableMap(customData);
- Parameters:
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.- Returns:
- a map containing custom data that will be carried through to the next stage of the series
-
afterEvaluation
public Map<String,Object> afterEvaluation(EvaluationSeriesContext seriesContext, Map<String, 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 toLDClient.allFlags()
.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 theseriesData
unmodified.String value = (String) seriesData.get("foo"); doAThing(value); return seriesData;
- Parameters:
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- Returns:
- a map containing custom data that will be carried through to the next stage of the series (if added in the future)
-
beforeIdentify
public Map<String,Object> beforeIdentify(IdentifySeriesContext seriesContext, Map<String, Object> seriesData) beforeIdentify(IdentifySeriesContext, Map)
is called during the execution of the identify process before the operation completes, but after any context modifications are performed.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 theseriesData
.HashMap<String, Object> customData = new HashMap<>(seriesData); customData.put("foo", "bar"); return Collections.unmodifiableMap(customData);
- Parameters:
seriesContext
- Contains information about the evaluation being performed. This is not mutable.seriesData
- A record associated with each stage of hook invocations. Each stage is called with the data of the previous stage for a series. The input record should not be modified.- Returns:
- a map containing custom data that will be carried through to the next stage of the series
-
afterIdentify
public Map<String,Object> afterIdentify(IdentifySeriesContext seriesContext, Map<String, Object> seriesData, IdentifySeriesResult result) afterIdentify(IdentifySeriesContext, Map, IdentifySeriesResult)
is called during the execution of the identify process, after the operation completes.This is currently the last stage of the identify series in the
Hook
, but that may not be the case in the future. To ensure forward compatibility, return theseriesData
unmodified.String value = (String) seriesData.get("foo"); doAThing(value); return seriesData;
- Parameters:
seriesContext
- Contains information about the evaluation being performed. This is not mutable.seriesData
- A record associated with each stage of hook invocations. Each stage is called with the data of the previous stage for a series. The input record should not be modified.result
- The result of the identify operation.- Returns:
- a map containing custom data that will be carried through to the next stage of the series (if added in the future)
-
afterTrack
afterTrack(TrackSeriesContext)
is called during the execution of the track process after the event has been enqueued.- Parameters:
seriesContext
- Contains information about the track operation being performed. This is not mutable.
-