Package com.configcat

Class ConfigCatClient

  • All Implemented Interfaces:
    ConfigurationProvider, java.io.Closeable, java.lang.AutoCloseable

    public final class ConfigCatClient
    extends java.lang.Object
    implements ConfigurationProvider
    A client for handling configurations provided by ConfigCat.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearDefaultUser()
      Set default user value to null.
      void close()  
      static void closeAll()
      Close all ConfigCatClient instances.
      RefreshResult forceRefresh()
      Initiates a force refresh synchronously on the cached configuration.
      java.util.concurrent.CompletableFuture<RefreshResult> forceRefreshAsync()
      Initiates a force refresh asynchronously on the cached configuration.
      static ConfigCatClient get​(java.lang.String sdkKey)
      Get a singleton ConfigCat Client for the sdk key, create a new client if not existed yet.
      static ConfigCatClient get​(java.lang.String sdkKey, java.util.function.Consumer<ConfigCatClient.Options> optionsCallback)
      Creates a new or gets an already existing ConfigCatClient for the given sdkKey.
      java.util.Collection<java.lang.String> getAllKeys()
      Gets a collection of all setting keys.
      java.util.concurrent.CompletableFuture<java.util.Collection<java.lang.String>> getAllKeysAsync()
      Gets a collection of all setting keys asynchronously.
      java.util.List<EvaluationDetails<java.lang.Object>> getAllValueDetails()
      Gets the detailed values of all feature flags or settings synchronously.
      java.util.List<EvaluationDetails<java.lang.Object>> getAllValueDetails​(User user)
      Gets the detailed values of all feature flags or settings synchronously.
      java.util.concurrent.CompletableFuture<java.util.List<EvaluationDetails<java.lang.Object>>> getAllValueDetailsAsync()
      Gets the detailed values of all feature flags or settings asynchronously.
      java.util.concurrent.CompletableFuture<java.util.List<EvaluationDetails<java.lang.Object>>> getAllValueDetailsAsync​(User user)
      Gets the detailed values of all feature flags or settings asynchronously.
      java.util.Map<java.lang.String,​java.lang.Object> getAllValues()
      Gets the values of all feature flags or settings synchronously.
      java.util.Map<java.lang.String,​java.lang.Object> getAllValues​(User user)
      Gets the values of all feature flags or settings synchronously.
      java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.lang.Object>> getAllValuesAsync()
      Gets the values of all feature flags or settings asynchronously.
      java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.lang.Object>> getAllValuesAsync​(User user)
      Gets the values of all feature flags or settings asynchronously.
      ConfigCatHooks getHooks()
      Access to hooks for event subscription.
      <T> java.util.Map.Entry<java.lang.String,​T> getKeyAndValue​(java.lang.Class<T> classOfT, java.lang.String variationId)
      Gets the key of a setting and its value identified by the given Variation ID (analytics).
      <T> java.util.concurrent.CompletableFuture<java.util.Map.Entry<java.lang.String,​T>> getKeyAndValueAsync​(java.lang.Class<T> classOfT, java.lang.String variationId)
      Gets the key of a setting and its value identified by the given Variation ID (analytics).
      <T> T getValue​(java.lang.Class<T> classOfT, java.lang.String key, User user, T defaultValue)
      Gets the value of a feature flag or setting as T identified by the given key.
      <T> T getValue​(java.lang.Class<T> classOfT, java.lang.String key, T defaultValue)
      Gets the value of a feature flag or setting as T identified by the given key.
      <T> java.util.concurrent.CompletableFuture<T> getValueAsync​(java.lang.Class<T> classOfT, java.lang.String key, User user, T defaultValue)
      Gets the value of a feature flag or setting as T asynchronously identified by the given key.
      <T> java.util.concurrent.CompletableFuture<T> getValueAsync​(java.lang.Class<T> classOfT, java.lang.String key, T defaultValue)
      Gets the value of a feature flag or setting as T asynchronously identified by the given key.
      <T> EvaluationDetails<T> getValueDetails​(java.lang.Class<T> classOfT, java.lang.String key, User user, T defaultValue)
      Gets the value of a feature flag or setting as T identified by the given key.
      <T> EvaluationDetails<T> getValueDetails​(java.lang.Class<T> classOfT, java.lang.String key, T defaultValue)
      Gets the value of a feature flag or setting as T identified by the given key.
      <T> java.util.concurrent.CompletableFuture<EvaluationDetails<T>> getValueDetailsAsync​(java.lang.Class<T> classOfT, java.lang.String key, User user, T defaultValue)
      Gets the value of a feature flag or setting as T asynchronously identified by the given key.
      <T> java.util.concurrent.CompletableFuture<EvaluationDetails<T>> getValueDetailsAsync​(java.lang.Class<T> classOfT, java.lang.String key, T defaultValue)
      Gets the value of a feature flag or setting as T asynchronously identified by the given key.
      boolean isClosed()
      Get the client closed status.
      boolean isOffline()
      Get the client offline mode status.
      void setDefaultUser​(User defaultUser)
      Sets defaultUser value.
      void setOffline()
      Set the client to offline mode.
      void setOnline()
      Set the client to online mode.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getValue

        public <T> T getValue​(java.lang.Class<T> classOfT,
                              java.lang.String key,
                              T defaultValue)
        Description copied from interface: ConfigurationProvider
        Gets the value of a feature flag or setting as T identified by the given key.
        Specified by:
        getValue in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        key - the identifier of the feature flag or setting.
        defaultValue - in case of any failure, this value will be returned.
        Returns:
        the configuration value identified by the given key.
      • getValue

        public <T> T getValue​(java.lang.Class<T> classOfT,
                              java.lang.String key,
                              User user,
                              T defaultValue)
        Description copied from interface: ConfigurationProvider
        Gets the value of a feature flag or setting as T identified by the given key.
        Specified by:
        getValue in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        key - the identifier of the feature flag or setting.
        user - the user object.
        defaultValue - in case of any failure, this value will be returned.
        Returns:
        the configuration value identified by the given key.
      • getValueAsync

        public <T> java.util.concurrent.CompletableFuture<T> getValueAsync​(java.lang.Class<T> classOfT,
                                                                           java.lang.String key,
                                                                           T defaultValue)
        Description copied from interface: ConfigurationProvider
        Gets the value of a feature flag or setting as T asynchronously identified by the given key.
        Specified by:
        getValueAsync in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        key - the identifier of the feature flag or setting.
        defaultValue - in case of any failure, this value will be returned.
        Returns:
        a future which computes the configuration value identified by the given key.
      • getValueAsync

        public <T> java.util.concurrent.CompletableFuture<T> getValueAsync​(java.lang.Class<T> classOfT,
                                                                           java.lang.String key,
                                                                           User user,
                                                                           T defaultValue)
        Description copied from interface: ConfigurationProvider
        Gets the value of a feature flag or setting as T asynchronously identified by the given key.
        Specified by:
        getValueAsync in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        key - the identifier of the feature flag or setting.
        user - the user object.
        defaultValue - in case of any failure, this value will be returned.
        Returns:
        a future which computes the configuration value identified by the given key.
      • getValueDetails

        public <T> EvaluationDetails<T> getValueDetails​(java.lang.Class<T> classOfT,
                                                        java.lang.String key,
                                                        T defaultValue)
        Description copied from interface: ConfigurationProvider
        Gets the value of a feature flag or setting as T identified by the given key.
        Specified by:
        getValueDetails in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        key - the identifier of the feature flag or setting.
        defaultValue - in case of any failure, this value will be returned.
        Returns:
        the result of the evaluation.
      • getValueDetails

        public <T> EvaluationDetails<T> getValueDetails​(java.lang.Class<T> classOfT,
                                                        java.lang.String key,
                                                        User user,
                                                        T defaultValue)
        Description copied from interface: ConfigurationProvider
        Gets the value of a feature flag or setting as T identified by the given key.
        Specified by:
        getValueDetails in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        key - the identifier of the feature flag or setting.
        user - the user object.
        defaultValue - in case of any failure, this value will be returned.
        Returns:
        the result of the evaluation.
      • getValueDetailsAsync

        public <T> java.util.concurrent.CompletableFuture<EvaluationDetails<T>> getValueDetailsAsync​(java.lang.Class<T> classOfT,
                                                                                                     java.lang.String key,
                                                                                                     T defaultValue)
        Description copied from interface: ConfigurationProvider
        Gets the value of a feature flag or setting as T asynchronously identified by the given key.
        Specified by:
        getValueDetailsAsync in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        key - the identifier of the feature flag or setting.
        defaultValue - in case of any failure, this value will be returned.
        Returns:
        a future which computes the evaluation details.
      • getValueDetailsAsync

        public <T> java.util.concurrent.CompletableFuture<EvaluationDetails<T>> getValueDetailsAsync​(java.lang.Class<T> classOfT,
                                                                                                     java.lang.String key,
                                                                                                     User user,
                                                                                                     T defaultValue)
        Description copied from interface: ConfigurationProvider
        Gets the value of a feature flag or setting as T asynchronously identified by the given key.
        Specified by:
        getValueDetailsAsync in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        key - the identifier of the feature flag or setting.
        user - the user object.
        defaultValue - in case of any failure, this value will be returned.
        Returns:
        a future which computes the evaluation details.
      • getAllValues

        public java.util.Map<java.lang.String,​java.lang.Object> getAllValues()
        Description copied from interface: ConfigurationProvider
        Gets the values of all feature flags or settings synchronously.
        Specified by:
        getAllValues in interface ConfigurationProvider
        Returns:
        a collection of all values.
      • getAllValues

        public java.util.Map<java.lang.String,​java.lang.Object> getAllValues​(User user)
        Description copied from interface: ConfigurationProvider
        Gets the values of all feature flags or settings synchronously.
        Specified by:
        getAllValues in interface ConfigurationProvider
        Parameters:
        user - the user object.
        Returns:
        a collection of all values.
      • getAllValuesAsync

        public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.lang.Object>> getAllValuesAsync()
        Description copied from interface: ConfigurationProvider
        Gets the values of all feature flags or settings asynchronously.
        Specified by:
        getAllValuesAsync in interface ConfigurationProvider
        Returns:
        a future which computes the collection of all values.
      • getAllValuesAsync

        public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​java.lang.Object>> getAllValuesAsync​(User user)
        Description copied from interface: ConfigurationProvider
        Gets the values of all feature flags or settings asynchronously.
        Specified by:
        getAllValuesAsync in interface ConfigurationProvider
        Parameters:
        user - the user object.
        Returns:
        a future which computes the collection of all values.
      • getAllValueDetails

        public java.util.List<EvaluationDetails<java.lang.Object>> getAllValueDetails​(User user)
        Description copied from interface: ConfigurationProvider
        Gets the detailed values of all feature flags or settings synchronously.
        Specified by:
        getAllValueDetails in interface ConfigurationProvider
        Parameters:
        user - the user object.
        Returns:
        a collection of all the evaluation results with details
      • getAllValueDetailsAsync

        public java.util.concurrent.CompletableFuture<java.util.List<EvaluationDetails<java.lang.Object>>> getAllValueDetailsAsync()
        Description copied from interface: ConfigurationProvider
        Gets the detailed values of all feature flags or settings asynchronously.
        Specified by:
        getAllValueDetailsAsync in interface ConfigurationProvider
        Returns:
        a future which computes the collection of all detailed values.
      • getAllValueDetailsAsync

        public java.util.concurrent.CompletableFuture<java.util.List<EvaluationDetails<java.lang.Object>>> getAllValueDetailsAsync​(User user)
        Description copied from interface: ConfigurationProvider
        Gets the detailed values of all feature flags or settings asynchronously.
        Specified by:
        getAllValueDetailsAsync in interface ConfigurationProvider
        Parameters:
        user - the user object.
        Returns:
        a future which computes the collection of all detailed values.
      • getKeyAndValue

        public <T> java.util.Map.Entry<java.lang.String,​T> getKeyAndValue​(java.lang.Class<T> classOfT,
                                                                                java.lang.String variationId)
        Description copied from interface: ConfigurationProvider
        Gets the key of a setting and its value identified by the given Variation ID (analytics).
        Specified by:
        getKeyAndValue in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        variationId - the Variation ID.
        Returns:
        the key of a setting and its value.
      • getKeyAndValueAsync

        public <T> java.util.concurrent.CompletableFuture<java.util.Map.Entry<java.lang.String,​T>> getKeyAndValueAsync​(java.lang.Class<T> classOfT,
                                                                                                                             java.lang.String variationId)
        Description copied from interface: ConfigurationProvider
        Gets the key of a setting and its value identified by the given Variation ID (analytics).
        Specified by:
        getKeyAndValueAsync in interface ConfigurationProvider
        Type Parameters:
        T - the type of the desired feature flag or setting.
        Parameters:
        classOfT - the class of T. Only String, Integer, Double or Boolean types are supported.
        variationId - the Variation ID.
        Returns:
        a future which computes the key of a setting and its value.
      • getAllKeys

        public java.util.Collection<java.lang.String> getAllKeys()
        Description copied from interface: ConfigurationProvider
        Gets a collection of all setting keys.
        Specified by:
        getAllKeys in interface ConfigurationProvider
        Returns:
        a collection of all setting keys.
      • getAllKeysAsync

        public java.util.concurrent.CompletableFuture<java.util.Collection<java.lang.String>> getAllKeysAsync()
        Description copied from interface: ConfigurationProvider
        Gets a collection of all setting keys asynchronously.
        Specified by:
        getAllKeysAsync in interface ConfigurationProvider
        Returns:
        a collection of all setting keys.
      • setDefaultUser

        public void setDefaultUser​(User defaultUser)
        Description copied from interface: ConfigurationProvider
        Sets defaultUser value. If no user specified in the following calls {getValue}, {getAllValues}, {getValueDetails}, {getAllValueDetails} the default user value will be used.
        Specified by:
        setDefaultUser in interface ConfigurationProvider
        Parameters:
        defaultUser - The new default user.
      • isOffline

        public boolean isOffline()
        Description copied from interface: ConfigurationProvider
        Get the client offline mode status.
        Specified by:
        isOffline in interface ConfigurationProvider
        Returns:
        True if the client is in offline mode, otherwise false.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • closeAll

        public static void closeAll()
                             throws java.io.IOException
        Close all ConfigCatClient instances.
        Throws:
        java.io.IOException - If client resource close fails.
      • get

        public static ConfigCatClient get​(java.lang.String sdkKey)
        Get a singleton ConfigCat Client for the sdk key, create a new client if not existed yet.
        Parameters:
        sdkKey - the client sdk key.
        Returns:
        a singleton client.
      • get

        public static ConfigCatClient get​(java.lang.String sdkKey,
                                          java.util.function.Consumer<ConfigCatClient.Options> optionsCallback)
        Creates a new or gets an already existing ConfigCatClient for the given sdkKey.
        Parameters:
        sdkKey - the SDK Key for to communicate with the ConfigCat services.
        optionsCallback - the options callback to set up the created ConfigCatClient instance.
        Returns:
        the ConfigCatClient instance.