public final class ExperimentHandler extends Object
ExperimentState
based on the data contained in the current
ExperimentSpace
.
The handler is the link between an ExperimentState
and the currently configured ExperimentSpace
.
As new requests are passed to the handle(AbstractExperimentState)
method, the ExperimentHandler
diverts them into experiments that modifies their flag value calculators that are used for the rest of the request
by calling the ExperimentState.get(ExperimentFlag)
methods:
static ExperimentFlag<Boolean> AWESOME_FEATURE_ON = Experiments.declare("awesome", false);
public void doStuff(Request request) {
MyExperimentState state = new MyExperimentState(request);
Experiments.getHandler().handle(state);
if (state.get(AWESOME_FEATURE_ON)) {
// enable *AWESOME* feature
} else {
// enable feature suggested by product manager
}
}
New ExperimentSpace
configurations may be updated asynchronously by the ExperimentSpaceLoader
that is configured for use with this ExperimentHandler
in the Experiments
namespace. Subsequent
calls to the handle(AbstractExperimentState)
method will use the latest updates to the
ExperimentSpace
for processing requests, and the ExperimentHandler
is thread-safe.
Modifier and Type | Method and Description |
---|---|
boolean |
disable(int experimentId)
Disables the experiment with the given id, preventing it from diverting any traffic.
|
String |
getVersionIdentifier()
Returns the version string for the
ExperimentSpace that is currently being used
by this instance to handle requests. |
void |
handle(AbstractExperimentState state)
Diverts the given
ExperimentState into one or more experiments across the
Layer instances in the current ExperimentSpace . |
public void handle(AbstractExperimentState state)
ExperimentState
into one or more experiments across the
Layer
instances in the current ExperimentSpace
.
A given ExperimentState
can only be diverted into one experiment per layer;
attempting to re-divert an instance that has already been diverted has no effect on
the flag values or experiment ids associated with the state.
state
- the request to divertpublic boolean disable(int experimentId)
experimentId
- id of the experiment to disablepublic String getVersionIdentifier()
ExperimentSpace
that is currently being used
by this instance to handle requests.ExperimentSpace
Copyright © 2013. All rights reserved.