Package 

Interface ExperimentClient


  • 
    public interface ExperimentClient
    
                        

    An experiment client manages a set of experiments and flags for a given user.

    • 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 false when 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 false on initialization.

        Parameters:
        user - The user to set in the SDK.
      • stop

         abstract Unit stop()

        Stop the local flag configuration poller.

      • 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, 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.
      • clear

         abstract Unit clear()

        Clear all variants in the cache and storage.

      • 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()

        Get the user for the experiment client. The user can be set by calling fetch with a user argument, or by explicitly setting the user via setUser.

      • 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.

      • 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.