public abstract class AbstractExperimentState extends Object implements ExperimentState
ExperimentState interface.
Clients should create their own ExperimentState implementations that use this instance as a base
class, since there are core methods in the framework (such as ExperimentHandler.handle(AbstractExperimentState)
that expect to operate on a subclass of AbstractExperimentState. More details on the purpose of this
split are described in the documentation of the ExperimentState interface.| Constructor and Description |
|---|
AbstractExperimentState() |
| Modifier and Type | Method and Description |
|---|---|
Set<Integer> |
forceExperimentIds()
Indicate a set of experiment IDs that this
ExperimentState should be forced
into by the ExperimentHandler.handle(AbstractExperimentState) method. |
<T> T |
get(ExperimentFlag<T> flag)
Returns the value of the given
ExperimentFlag for this ExperimentState. |
abstract com.google.common.base.Optional<String> |
getDiversionIdentifier(int diversionId)
Return the identifier to use for this instance with the diversion criterion that
has the given identifer.
|
Set<Integer> |
getExperimentIds()
Returns the integer identifiers for the experiments that this state was diverted into.
|
float |
getFloat(ExperimentFlag<Double> doubleFlag)
A convenience method for acccessing the value of a
ExperimentFlag<Double> as a float. |
int |
getInt(ExperimentFlag<Long> longFlag)
A convenience method for acccessing the value of a
ExperimentFlag<Long> as an int. |
long |
getRequestTimeMsec()
Returns the time that this
ExperimentState instance was created in milliseconds. |
boolean |
isDiverted()
Indicates whether or not this
ExperimentState has been passed to ExperimentHandler.handle(com.cloudera.gertrude.AbstractExperimentState). |
public abstract com.google.common.base.Optional<String> getDiversionIdentifier(int diversionId)
ExperimentStateClients must override this method in order to specify the identifiers that they support for a given request, and what the values of those identifiers are for each request.
Remember that these identifiers are used for randomly diverting requests into experiments, so they should be unique for each entity that we are experimenting on. For example, using the country that a request comes from is a relatively poor choice of a diversion identifier compared to a random account ID or browser cookie.
getDiversionIdentifier in interface ExperimentStatediversionId - The unique id of the requested diversion criterionpublic Set<Integer> forceExperimentIds()
ExperimentStateExperimentState should be forced
into by the ExperimentHandler.handle(AbstractExperimentState) method.
By default, this method returns an empty set. Subclasses may override this method to provide clients with a way to force a request to be in a certain experiment in order to test or debug a scenario.
forceExperimentIds in interface ExperimentStatepublic <T> T get(ExperimentFlag<T> flag)
ExperimentStateExperimentFlag for this ExperimentState.
If the FlagValue that was calculated for this flag can be cached on a per-request
basis, then this instance will keep the calculated value in a cache so that it is not
re-computed unnecessarily during the same request.
If this state has not yet been diverted by the ExperimentHandler, then the
default value of the flag is returned, but not stored in the cache.
get in interface ExperimentStateflag - the flag whose value is returnedpublic int getInt(ExperimentFlag<Long> longFlag)
ExperimentStateExperimentFlag<Long> as an int.getInt in interface ExperimentStatelongFlag - the flagpublic float getFloat(ExperimentFlag<Double> doubleFlag)
ExperimentStateExperimentFlag<Double> as a float.getFloat in interface ExperimentStatedoubleFlag - the flagpublic Set<Integer> getExperimentIds()
ExperimentStategetExperimentIds in interface ExperimentStatepublic boolean isDiverted()
ExperimentStateExperimentState has been passed to ExperimentHandler.handle(com.cloudera.gertrude.AbstractExperimentState).isDiverted in interface ExperimentStatepublic long getRequestTimeMsec()
ExperimentStateExperimentState instance was created in milliseconds. Used for
determining whether a particular experiment should be active or inactive for this request.getRequestTimeMsec in interface ExperimentStateCopyright © 2013. All rights reserved.