Interface LifecycleHook<R,E extends LifecycleEvent>
- Type Parameters:
E
- The lifecycle event class to post this hook.
- All Known Subinterfaces:
QualificationLifecycleHook
,TargetingLifecycleHook
getLifecycleEventClass()
,
this hook is posted via the post(LifecycleEvent)
method.
Lifecycle hooks are defined in the experiment schema at the meta, state or experiment level. Those hooks, defined
at the meta level are schema-scoped and are applicable to all states and experiments in the schema.
Hooks defined at the state level are state-scoped and are only applicable to the state where
they are defined. Finally, hooks defined at the experiment level are experiment-scoped and are only applicable
to the experiment where they are defined. It is an error to define a state-scoped hook which listens to a non-
StateAwareLifecycleEvent
. Likewise, is an error to define a experiment-scoped hook which listens to a non-
ExperimentAwareLifecycleEvent
. Whenever a lifecycle event of type T is raised, Variant server posts
all hooks whose getLifecycleEventClass()
returns either T or its subclass.
If multiple hooks are to be posted by the same lifecycle event, they form a hook chain, and Variant server will
post them in the order they were defined in the schema. Hooks are posted one after another, until the
post(LifecycleEvent)
method returns a non-empty value. If no user defined hook returned a non-empty value,
the default hook is posted, which is guaranteed to return a value.
An implementation must provide at least one public constructor:
- If no state initialization is required, a nullary constructor is sufficient.
- If you need to pass an initial state to the newly constructed hook object, you must provide a constructor
which takes the single argument of type com.typesafe.config.Config.
Variant will invoke this constructor and pass it the parsed value of the
'init'
property.
Variant creates a new instance of the implementing class for each raised event.
- Since:
- 0.5
-
Method Summary
-
Method Details
-
getLifecycleEventClass
Implementation must tell the server what life cycle event type(s) it wants to be posted on. If this method returns a super-type, this hook will be posted for it and all its descendant event types.- Returns:
- A
Class
object associated with the life cycle event type(s) of interest. - Since:
- 0.5
-
post
The first hook on the chain that returns a non-empty Optional short-circuits the rest of the chain.- Throws:
Exception
- Since:
- 0.7
-