-
public interface ExperimentClientAn experiment client manages a set of experiments and flags for a given user.
-
-
Method Summary
Modifier and Type Method Description abstract Future<ExperimentClient>start(ExperimentUser user)Start the SDK by getting flag configurations from the server and fetching variants for the user. abstract Unitstop()Stop the local flag configuration poller. abstract Future<ExperimentClient>fetch(ExperimentUser user)Assign the given user to the SDK and asynchronously fetch all variants from the server. abstract Future<ExperimentClient>fetch(ExperimentUser user, FetchOptions options)Assign the given user to the SDK and asynchronously fetch all variants from the server. abstract Variantvariant(String key)Returns the stored variant for the provided key. abstract Variantvariant(String key, Variant fallback)Returns the stored variant for the provided key. abstract Map<String, Variant>all()Returns all variants for the user. abstract Unitclear()Clear all variants in the cache and storage. abstract Unitexposure(String key)Track an exposure event for the variant associated with the flag/experiment key through the analytics provider. abstract ExperimentUsergetUser()Get the user for the experiment client. abstract UnitsetUser(ExperimentUser user)Set the user within the client. abstract ExperimentUserProvidergetUserProvider()Get the user provider if it exists. abstract ExperimentClientsetUserProvider(ExperimentUserProvider provider)Sets a user provider that will inject identity information into the user for fetch requests. -
-
Method Detail
-
start
abstract Future<ExperimentClient> start(ExperimentUser user)
Start the SDK by getting flag configurations from the server and fetching variants for the user. The future returned by this function resolves when local flag configurations have been updated, and the fetch() result has been received (if the request was made).
To force this function not to fetch variants, set the {@link fetchOnStart} configuration option to
falsewhen initializing the SDK.Finally, this function will start polling for flag configurations at a fixed interval. To disable polling, set the pollOnStart configuration option to
falseon initialization.- Parameters:
user- The user to set in the SDK.
-
fetch
abstract Future<ExperimentClient> fetch(ExperimentUser user)
Assign the given user to the SDK and asynchronously fetch all variants from the server. Subsequent calls may omit the user from the argument to use the user from the previous call, or set previously using setUser.
If an ExperimentUserProvider has been set, the argument user will be merged with the provider user, preferring user fields from the argument user and falling back on the provider for fields which are null or undefined.
- Parameters:
user- The user to fetch variants for.
-
fetch
abstract Future<ExperimentClient> fetch(ExperimentUser user, FetchOptions options)
Assign the given user to the SDK and asynchronously fetch all variants from the server. Subsequent calls may omit the user from the argument to use the user from the previous call, or set previously using setUser.
If an ExperimentUserProvider has been set, the argument user will be merged with the provider user, preferring user fields from the argument user and falling back on the provider for fields which are null or undefined.
- Parameters:
user- The user to fetch variants for.options- Optional fetch options, could config to fetch subset flags.
-
variant
abstract Variant variant(String key)
Returns the stored variant for the provided key.
Fetches all variants from the Source then falling back, ExperimentConfig.fallbackVariant.
- Parameters:
key- The flag or experiment key to get the assigned variant for.
-
variant
abstract Variant variant(String key, Variant fallback)
Returns the stored variant for the provided key.
Fetches variants from the Source, falling back to fallback if not null, and finally to the configured ExperimentConfig.fallbackVariant.
- Parameters:
key- The flag or experiment key to get the assigned variant for.fallback- The highest priority fallback if not null.
-
all
abstract Map<String, Variant> all()
Returns all variants for the user.
The primary source of variants is based on the Source configured in the ExperimentConfig.source.
-
exposure
abstract Unit exposure(String key)
Track an exposure event for the variant associated with the flag/experiment key through the analytics provider.
This method requires that an ExperimentAnalyticsProvider be configured when this client is initialized, either manually, or through the Amplitude Analytics SDK integration from set up using Experiment.initializeWithAmplitudeAnalytics.
- Parameters:
key- the flag/experiment key to track an exposure for.
-
getUser
abstract ExperimentUser getUser()
-
setUser
abstract Unit setUser(ExperimentUser user)
Set the user within the client. This user will be used to fetch variants if the user passed into fetch is null or missing.
-
getUserProvider
@Deprecated(message = Use ExperimentConfig.userProvider instead) abstract ExperimentUserProvider getUserProvider()
Get the user provider if it exists.
-
setUserProvider
@Deprecated(message = Use ExperimentConfig.userProvider instead) abstract ExperimentClient setUserProvider(ExperimentUserProvider provider)
Sets a user provider that will inject identity information into the user for fetch requests. The user provider will only set user fields in outgoing requests which are null or undefined.
-
-
-
-