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)
ExperimentState
Clients 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 ExperimentState
diversionId
- The unique id of the requested diversion criterionpublic Set<Integer> forceExperimentIds()
ExperimentState
ExperimentState
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 ExperimentState
public <T> T get(ExperimentFlag<T> flag)
ExperimentState
ExperimentFlag
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 ExperimentState
flag
- the flag whose value is returnedpublic int getInt(ExperimentFlag<Long> longFlag)
ExperimentState
ExperimentFlag<Long>
as an int
.getInt
in interface ExperimentState
longFlag
- the flagpublic float getFloat(ExperimentFlag<Double> doubleFlag)
ExperimentState
ExperimentFlag<Double>
as a float
.getFloat
in interface ExperimentState
doubleFlag
- the flagpublic Set<Integer> getExperimentIds()
ExperimentState
getExperimentIds
in interface ExperimentState
public boolean isDiverted()
ExperimentState
ExperimentState
has been passed to ExperimentHandler.handle(com.cloudera.gertrude.AbstractExperimentState)
.isDiverted
in interface ExperimentState
public long getRequestTimeMsec()
ExperimentState
ExperimentState
instance was created in milliseconds. Used for
determining whether a particular experiment should be active or inactive for this request.getRequestTimeMsec
in interface ExperimentState
Copyright © 2013. All rights reserved.