Package com.configcat
Class ConfigCatClient
- java.lang.Object
-
- com.configcat.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConfigCatClient.OptionsOptions for configuringConfigCatClientinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearDefaultUser()Set default user value to null.voidclose()static voidcloseAll()Close all ConfigCatClient instances.RefreshResultforceRefresh()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 ConfigCatClientget(java.lang.String sdkKey)Get a singleton ConfigCat Client for the sdk key, create a new client if not existed yet.static ConfigCatClientget(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.ConfigCatHooksgetHooks()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> TgetValue(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 givenkey.<T> TgetValue(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 givenkey.<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 givenkey.<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 givenkey.<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 givenkey.<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 givenkey.<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 givenkey.<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 givenkey.booleanisClosed()Get the client closed status.booleanisOffline()Get the client offline mode status.voidsetDefaultUser(User defaultUser)Sets defaultUser value.voidsetOffline()Set the client to offline mode.voidsetOnline()Set the client to online mode.
-
-
-
Method Detail
-
getValue
public <T> T getValue(java.lang.Class<T> classOfT, java.lang.String key, T defaultValue)Description copied from interface:ConfigurationProviderGets the value of a feature flag or setting as T identified by the givenkey.- Specified by:
getValuein interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets the value of a feature flag or setting as T identified by the givenkey.- Specified by:
getValuein interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets the value of a feature flag or setting as T asynchronously identified by the givenkey.- Specified by:
getValueAsyncin interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets the value of a feature flag or setting as T asynchronously identified by the givenkey.- Specified by:
getValueAsyncin interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets the value of a feature flag or setting as T identified by the givenkey.- Specified by:
getValueDetailsin interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets the value of a feature flag or setting as T identified by the givenkey.- Specified by:
getValueDetailsin interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets the value of a feature flag or setting as T asynchronously identified by the givenkey.- Specified by:
getValueDetailsAsyncin interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets the value of a feature flag or setting as T asynchronously identified by the givenkey.- Specified by:
getValueDetailsAsyncin interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets the values of all feature flags or settings synchronously.- Specified by:
getAllValuesin interfaceConfigurationProvider- Returns:
- a collection of all values.
-
getAllValues
public java.util.Map<java.lang.String,java.lang.Object> getAllValues(User user)
Description copied from interface:ConfigurationProviderGets the values of all feature flags or settings synchronously.- Specified by:
getAllValuesin interfaceConfigurationProvider- 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:ConfigurationProviderGets the values of all feature flags or settings asynchronously.- Specified by:
getAllValuesAsyncin interfaceConfigurationProvider- 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:ConfigurationProviderGets the values of all feature flags or settings asynchronously.- Specified by:
getAllValuesAsyncin interfaceConfigurationProvider- 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()
Description copied from interface:ConfigurationProviderGets the detailed values of all feature flags or settings synchronously.- Specified by:
getAllValueDetailsin interfaceConfigurationProvider- Returns:
- a collection of all the evaluation results with details
-
getAllValueDetails
public java.util.List<EvaluationDetails<java.lang.Object>> getAllValueDetails(User user)
Description copied from interface:ConfigurationProviderGets the detailed values of all feature flags or settings synchronously.- Specified by:
getAllValueDetailsin interfaceConfigurationProvider- 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:ConfigurationProviderGets the detailed values of all feature flags or settings asynchronously.- Specified by:
getAllValueDetailsAsyncin interfaceConfigurationProvider- 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:ConfigurationProviderGets the detailed values of all feature flags or settings asynchronously.- Specified by:
getAllValueDetailsAsyncin interfaceConfigurationProvider- 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:ConfigurationProviderGets the key of a setting and its value identified by the given Variation ID (analytics).- Specified by:
getKeyAndValuein interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets the key of a setting and its value identified by the given Variation ID (analytics).- Specified by:
getKeyAndValueAsyncin interfaceConfigurationProvider- Type Parameters:
T- the type of the desired feature flag or setting.- Parameters:
classOfT- the class of T. OnlyString,Integer,DoubleorBooleantypes 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:ConfigurationProviderGets a collection of all setting keys.- Specified by:
getAllKeysin interfaceConfigurationProvider- Returns:
- a collection of all setting keys.
-
getAllKeysAsync
public java.util.concurrent.CompletableFuture<java.util.Collection<java.lang.String>> getAllKeysAsync()
Description copied from interface:ConfigurationProviderGets a collection of all setting keys asynchronously.- Specified by:
getAllKeysAsyncin interfaceConfigurationProvider- Returns:
- a collection of all setting keys.
-
forceRefresh
public RefreshResult forceRefresh()
Description copied from interface:ConfigurationProviderInitiates a force refresh synchronously on the cached configuration.- Specified by:
forceRefreshin interfaceConfigurationProvider- Returns:
- the refresh result.
-
forceRefreshAsync
public java.util.concurrent.CompletableFuture<RefreshResult> forceRefreshAsync()
Description copied from interface:ConfigurationProviderInitiates a force refresh asynchronously on the cached configuration.- Specified by:
forceRefreshAsyncin interfaceConfigurationProvider- Returns:
- the future which executes the refresh.
-
setDefaultUser
public void setDefaultUser(User defaultUser)
Description copied from interface:ConfigurationProviderSets defaultUser value. If no user specified in the following calls {getValue}, {getAllValues}, {getValueDetails}, {getAllValueDetails} the default user value will be used.- Specified by:
setDefaultUserin interfaceConfigurationProvider- Parameters:
defaultUser- The new default user.
-
clearDefaultUser
public void clearDefaultUser()
Description copied from interface:ConfigurationProviderSet default user value to null.- Specified by:
clearDefaultUserin interfaceConfigurationProvider
-
isClosed
public boolean isClosed()
Description copied from interface:ConfigurationProviderGet the client closed status.- Specified by:
isClosedin interfaceConfigurationProvider- Returns:
- True if the client is closed.
-
setOnline
public void setOnline()
Description copied from interface:ConfigurationProviderSet the client to online mode. HTTP calls are allowed.- Specified by:
setOnlinein interfaceConfigurationProvider
-
setOffline
public void setOffline()
Description copied from interface:ConfigurationProviderSet the client to offline mode. HTTP calls are not allowed.- Specified by:
setOfflinein interfaceConfigurationProvider
-
isOffline
public boolean isOffline()
Description copied from interface:ConfigurationProviderGet the client offline mode status.- Specified by:
isOfflinein interfaceConfigurationProvider- Returns:
- True if the client is in offline mode, otherwise false.
-
getHooks
public ConfigCatHooks getHooks()
Description copied from interface:ConfigurationProviderAccess to hooks for event subscription.- Specified by:
getHooksin interfaceConfigurationProvider- Returns:
- the hooks object used for event subscription.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
closeAll
public static void closeAll() throws java.io.IOExceptionClose 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.
-
-