public final class Experiments extends Object
Most clients will get started with Gertrude by declaring ExperimentFlag
instances in
their code that reference parameters that can be calculated by the framework:
ExperimentFlag<Boolean> featureOn = Experiments.declare("feature", false);
ExperimentFlag<Long> upperLimit = Experiments.declare("limit", 1729L);
ExperimentFlag<Double> threshold = Experiments.declare("threshold_for_model", 0.05);
ExperimentFlag<String> background = Experiments.declare("background_color", "white");
At server startup time, Gertrude needs some additional classes configured so that the framework can load and process new experiments from external sources:
ConditionFactory
for mapping from names of Condition
functions to implementations,
ExperimentSpaceDeserializer
for processing the serialized form of an ExperimentSpace
,
ExperimentSpaceLoader
that is configured with the location of the serialized ExperimentSpace
,
MetricRegistry
for tracking experiment requests and diversions.
After these instances are configured, the ExperimentHandler
for the server can be accessed via the
getHandler()
method and used to divert client requests (represented by a subclass of
AbstractExperimentState
) into experiments that modify parameter values as specified in the configuration
of the ExperimentSpace
.
Modifier and Type | Method and Description |
---|---|
static ExperimentFlag<Boolean> |
declare(String name,
boolean defaultValue)
Declares a boolean experiment flag with the given name and default value.
|
static ExperimentFlag<Double> |
declare(String name,
double defaultValue)
Declares a double experiment flag with the given name and default value.
|
static ExperimentFlag<Long> |
declare(String name,
long defaultValue)
Declares a long experiment flag with the given name and default value.
|
static ExperimentFlag<String> |
declare(String name,
String defaultValue)
Declares a string experiment flag with the given name and default value.
|
static ExperimentHandler |
getHandler() |
static boolean |
registerConditionFactory(ConditionFactory factory)
Register the given
ConditionFactory for creating new Condition instances from the serialized
ExperimentSpace configuration. |
static boolean |
registerDeserializer(ExperimentSpaceDeserializer deserializer)
Register the given
ExperimentSpaceDeserializer for creating and validating new ExperimentSpace
instances. |
static boolean |
registerLoader(ExperimentSpaceLoader loader)
Register the given
ExperimentSpaceLoader for retrieving serialized ExperimentSpace
instances. |
static boolean |
registerMetricRegistry(com.codahale.metrics.MetricRegistry registry)
Register the given
MetricRegistry for stat tracking with the framework. |
public static ExperimentFlag<Boolean> declare(String name, boolean defaultValue)
name
- the name of the flagdefaultValue
- the default value of the flagExperimentFlag
for the name and default valuepublic static ExperimentFlag<Long> declare(String name, long defaultValue)
name
- the name of the flagdefaultValue
- the default value of the flagExperimentFlag
for the name and default valuepublic static ExperimentFlag<Double> declare(String name, double defaultValue)
name
- the name of the flagdefaultValue
- the default value of the flagExperimentFlag
for the name and default valuepublic static ExperimentFlag<String> declare(String name, String defaultValue)
name
- the name of the flagdefaultValue
- the default value of the flagExperimentFlag
for the name and default valuepublic static boolean registerConditionFactory(ConditionFactory factory)
ConditionFactory
for creating new Condition
instances from the serialized
ExperimentSpace
configuration.
If no factory is provided before the call to getHandler()
, an IllegalStateException
will be thrown.
factory
- the configured factorypublic static boolean registerLoader(ExperimentSpaceLoader loader)
ExperimentSpaceLoader
for retrieving serialized ExperimentSpace
instances.
If no loader is provided before the call to getHandler()
, an IllegalStateException
will be thrown.
loader
- the configured loaderpublic static boolean registerDeserializer(ExperimentSpaceDeserializer deserializer)
ExperimentSpaceDeserializer
for creating and validating new ExperimentSpace
instances.
If no deserializer is provided before the call to getHandler()
, an IllegalStateException
will be thrown.
deserializer
- the configured deserializerpublic static boolean registerMetricRegistry(com.codahale.metrics.MetricRegistry registry)
MetricRegistry
for stat tracking with the framework.
If no registry is provided before the call to getHandler()
, the framework will create its
own instance and use that one.
registry
- the registry instance to usepublic static ExperimentHandler getHandler()
Copyright © 2013. All rights reserved.