Interface LDClientInterface
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
LDClient
To obtain a client instance, use LDClient
methods such as LDClient.init(Application, LDConfig, LDContext)
.
-
Method Summary
Modifier and TypeMethodDescriptionallFlags()
Returns a map of all feature flags for the current evaluation context.boolean
boolVariation
(String flagKey, boolean defaultValue) Returns the boolean value of a feature flag for the current evaluation context.boolVariationDetail
(String flagKey, boolean defaultValue) Returns the boolean value of a feature flag for the current evaluation context, along with information about how it was calculated.double
doubleVariation
(String flagKey, double defaultValue) Returns the double-precision floating-point numeric value of a feature flag for the current evaluation context.doubleVariationDetail
(String flagKey, double defaultValue) Returns the double-precision floating-point numeric value of a feature flag for the current evaluation context, along with information about how it was calculated.void
flush()
Sends all pending events to LaunchDarkly.Gets aConnectionInformation
object from the client representing the current state of the clients connection.Returns the version of the SDK, for instance "2.7.0".Changes the current evaluation context, requests flags for that context from LaunchDarkly if we are online, and generates an analytics event to tell LaunchDarkly about the context.int
intVariation
(String flagKey, int defaultValue) Returns the integer value of a feature flag for the current evaluation context.intVariationDetail
(String flagKey, int defaultValue) Returns the integer value of a feature flag for the current evaluation context, along with information about how it was calculated.boolean
Checks whetherLDConfig.Builder.disableBackgroundUpdating(boolean)
was set totrue
in the configuration.boolean
Checks whether the client is ready to return feature flag values.boolean
Checks whether the client has been put into offline mode.jsonValueVariation
(String flagKey, LDValue defaultValue) Returns the value of a feature flag for the current evaluation context, which may be of any type.jsonValueVariationDetail
(String flagKey, LDValue defaultValue) Returns the value of a feature flag for the current evaluation context, which may be of any type, along with information about how it was calculated.void
registerAllFlagsListener
(LDAllFlagsListener allFlagsListener) Registers aLDAllFlagsListener
to be called when a flag update is processed by the SDK.void
registerFeatureFlagListener
(String flagKey, FeatureFlagChangeListener listener) Registers aFeatureFlagChangeListener
to be called when theflagKey
changes from its current value.void
registerStatusListener
(LDStatusListener LDStatusListener) Registers aLDStatusListener
to be called on connection status updates.void
Shuts down any network connections maintained by the client and puts the client in offline mode, preventing the client from opening new network connections untilsetOnline()
is called.void
Restores network connectivity for the client, if the client was previously in offline mode.stringVariation
(String flagKey, String defaultValue) Returns the string value of a feature flag for the current evaluation context.stringVariationDetail
(String flagKey, String defaultValue) Returns the string value of a feature flag for the current evaluation context, along with information about how it was calculated.void
Tracks that an application-defined event occurred.void
Tracks that an application-defined event occurred, and provides additional custom data.void
trackMetric
(String eventName, LDValue data, double metricValue) Tracks that an application-defined event occurred, and provides an additional numeric value for custom metrics.void
unregisterAllFlagsListener
(LDAllFlagsListener allFlagsListener) Unregisters aLDAllFlagsListener
so it will no longer be called on flag updates.void
unregisterFeatureFlagListener
(String flagKey, FeatureFlagChangeListener listener) Unregisters aFeatureFlagChangeListener
for theflagKey
.void
unregisterStatusListener
(LDStatusListener LDStatusListener) Unregisters aLDStatusListener
so it will no longer be called on connection status updates.
-
Method Details
-
isInitialized
boolean isInitialized()Checks whether the client is ready to return feature flag values. This is true if either the client has successfully connected to LaunchDarkly and received feature flags, or the client has been put into offline mode (in which case it will return only default flag values).- Returns:
- true if the client is initialized or offline
-
isOffline
boolean isOffline()Checks whether the client has been put into offline mode. This is true only ifsetOffline()
was called, or if the configuration hadLDConfig.Builder.offline(boolean)
set to true, not if the client is simply offline due to a loss of network connectivity.- Returns:
- true if the client is in offline mode
-
setOffline
void setOffline()Shuts down any network connections maintained by the client and puts the client in offline mode, preventing the client from opening new network connections untilsetOnline()
is called.Note: The client automatically monitors the device's network connectivity and app foreground status, so calling
setOffline()
orsetOnline()
is normally unnecessary in most situations. -
setOnline
void setOnline()Restores network connectivity for the client, if the client was previously in offline mode. This operation may be throttled if it is called too frequently.Note: The client automatically monitors the device's network connectivity and app foreground status, so calling
setOffline()
orsetOnline()
is normally unnecessary in most situations. -
trackMetric
Tracks that an application-defined event occurred, and provides an additional numeric value for custom metrics.This method creates a "custom" analytics event containing the specified event name (key) the current evaluation context, optional custom data, and a numeric metric value.
Note that event delivery is asynchronous, so the event may not actually be sent until later; see
flush()
.- Parameters:
eventName
- the name of the eventdata
- anLDValue
containing additional data associated with the event; if not applicable, you may pass eithernull
orLDValue.ofNull()
metricValue
- a numeric value used by the LaunchDarkly experimentation feature in numeric custom metrics; this field will also be returned as part of the custom event for Data Export- See Also:
-
trackData
Tracks that an application-defined event occurred, and provides additional custom data.This method creates a "custom" analytics event containing the specified event name (key) the current evaluation context, and optional custom data. To specify a numeric metric, use
trackMetric(String, LDValue, double)
instead.Note that event delivery is asynchronous, so the event may not actually be sent until later; see
flush()
.- Parameters:
eventName
- the name of the eventdata
- anLDValue
containing additional data associated with the event; if not applicable, you may pass eithernull
orLDValue.ofNull()
- See Also:
-
track
Tracks that an application-defined event occurred.This method creates a "custom" analytics event containing the specified event name (key) and the current evaluation context. You may attach other data to the event by calling
trackData(String, LDValue)
ortrackMetric(String, LDValue, double)
instead.Note that event delivery is asynchronous, so the event may not actually be sent until later; see
flush()
.- Parameters:
eventName
- the name of the event- See Also:
-
identify
Changes the current evaluation context, requests flags for that context from LaunchDarkly if we are online, and generates an analytics event to tell LaunchDarkly about the context.If the SDK is online, the returned
Future
is completed once the SDK has received feature flag values for the new context from LaunchDarkly, or received an unrecoverable error. If the SDK is offline, the returnedFuture
is completed immediately.The SDK normally caches flag settings for recently used evaluation contexts; this behavior can be configured with
LDConfig.Builder.maxCachedContexts(int)
.- Parameters:
context
- the new evaluation context; seeLDClient
for more about setting the context and optionally requesting a unique key for it- Returns:
- a Future whose success indicates the flag values for the new evaluation context have been stored locally and are ready for use
- Since:
- 3.0.0
-
flush
void flush()Sends all pending events to LaunchDarkly. -
allFlags
Returns a map of all feature flags for the current evaluation context. No events are sent to LaunchDarkly.- Returns:
- a map of all feature flags
-
boolVariation
Returns the boolean value of a feature flag for the current evaluation context.If the flag variation does not have a boolean value, or if an error makes it impossible to evaluate the flag (for instance, if
flagKey
does not match any existing flag),defaultValue
is returned.- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag- Returns:
- value of the flag or the default value
-
boolVariationDetail
Returns the boolean value of a feature flag for the current evaluation context, along with information about how it was calculated.Note that this will only work if you have set
evaluationReasons
to true withLDConfig.Builder.evaluationReasons(boolean)
. Otherwise, thereason
property of the result will be null.The evaluation reason will also be included in analytics events, if you are capturing detailed event data for this flag.
- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag (seeboolVariation(String, boolean)
)- Returns:
- an
EvaluationDetail
object containing the value and other information - Since:
- 2.7.0
-
intVariation
Returns the integer value of a feature flag for the current evaluation context.If the flag variation has a numeric value that is not an integer, it is rounded toward zero.
If the flag variation does not have a numeric value, or if an error makes it impossible to evaluate the flag (for instance, if
flagKey
does not match any existing flag),defaultValue
is returned.- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag- Returns:
- value of the flag or the default value
-
intVariationDetail
Returns the integer value of a feature flag for the current evaluation context, along with information about how it was calculated.Note that this will only work if you have set
evaluationReasons
to true withLDConfig.Builder.evaluationReasons(boolean)
. Otherwise, thereason
property of the result will be null.The evaluation reason will also be included in analytics events, if you are capturing detailed event data for this flag.
The behavior is otherwise identical to
intVariation(java.lang.String, int)
.- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag (seeintVariation(String, int)
)- Returns:
- an
EvaluationDetail
object containing the value and other information - Since:
- 2.7.0
-
doubleVariation
Returns the double-precision floating-point numeric value of a feature flag for the current evaluation context.If the flag variation does not have a numeric value, or if an error makes it impossible to evaluate the flag (for instance, if
flagKey
does not match any existing flag),defaultValue
is returned.- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag- Returns:
- value of the flag or the default value
-
doubleVariationDetail
Returns the double-precision floating-point numeric value of a feature flag for the current evaluation context, along with information about how it was calculated. Note that this will only work if you have setevaluationReasons
to true withLDConfig.Builder.evaluationReasons(boolean)
. Otherwise, thereason
property of the result will be null.The evaluation reason will also be included in analytics events, if you are capturing detailed event data for this flag.
The behavior is otherwise identical to
doubleVariation(java.lang.String, double)
.- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag (seedoubleVariation(String, double)
)- Returns:
- an
EvaluationDetail
object containing the value and other information.
-
stringVariation
Returns the string value of a feature flag for the current evaluation context.If the flag variation does not have a string value, or if an error makes it impossible to evaluate the flag (for instance, if
flagKey
does not match any existing flag),defaultValue
is returned.- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag- Returns:
- value of the flag or the default value
-
stringVariationDetail
Returns the string value of a feature flag for the current evaluation context, along with information about how it was calculated.Note that this will only work if you have set
evaluationReasons
to true withLDConfig.Builder.evaluationReasons(boolean)
. Otherwise, thereason
property of the result will be null.The evaluation reason will also be included in analytics events, if you are capturing detailed event data for this flag.
The behavior is otherwise identical to
stringVariation(java.lang.String, java.lang.String)
.- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag (seestringVariation(String, String)
)- Returns:
- an
EvaluationDetail
object containing the value and other information. - Since:
- 2.7.0
-
registerFeatureFlagListener
Registers aFeatureFlagChangeListener
to be called when theflagKey
changes from its current value. If the feature flag is deleted, thelistener
will be unregistered.- Parameters:
flagKey
- the flag key to attach the listener tolistener
- the listener to attach to the flag key- See Also:
-
jsonValueVariation
Returns the value of a feature flag for the current evaluation context, which may be of any type.The type
LDValue
is used to represent any of the value types that can exist in JSON. UseLDValue
methods to examine its type and value.- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag- Returns:
- value of the flag or the default value. Result will never be null, but may be LDValue#ofNull()
-
jsonValueVariationDetail
Returns the value of a feature flag for the current evaluation context, which may be of any type, along with information about how it was calculated.The type
LDValue
is used to represent any of the value types that can exist in JSON. UseLDValue
methods to examine its type and value.Note that this will only work if you have set
evaluationReasons
to true withLDConfig.Builder.evaluationReasons(boolean)
. Otherwise, thereason
property of the result will be null.The evaluation reason will also be included in analytics events, if you are capturing detailed event data for this flag.
The behavior is otherwise identical to
jsonValueVariation(java.lang.String, com.launchdarkly.sdk.LDValue)
.- Parameters:
flagKey
- key for the flag to evaluatedefaultValue
- default value in case of errors evaluating the flag (seejsonValueVariation(String, LDValue)
)- Returns:
- an
EvaluationDetail
object containing the value and other information.
-
unregisterFeatureFlagListener
Unregisters aFeatureFlagChangeListener
for theflagKey
.- Parameters:
flagKey
- the flag key to remove the listener fromlistener
- the listener to remove from the flag key- See Also:
-
getConnectionInformation
ConnectionInformation getConnectionInformation()Gets aConnectionInformation
object from the client representing the current state of the clients connection.- Returns:
- An object representing the status of the connection to LaunchDarkly.
-
unregisterStatusListener
Unregisters aLDStatusListener
so it will no longer be called on connection status updates.- Parameters:
LDStatusListener
- the listener to be removed
-
registerStatusListener
Registers aLDStatusListener
to be called on connection status updates.- Parameters:
LDStatusListener
- the listener to be called on a connection status update
-
registerAllFlagsListener
Registers aLDAllFlagsListener
to be called when a flag update is processed by the SDK.- Parameters:
allFlagsListener
- the listener to be called with a list of flag keys on a flag update
-
unregisterAllFlagsListener
Unregisters aLDAllFlagsListener
so it will no longer be called on flag updates.- Parameters:
allFlagsListener
- the listener to be removed
-
isDisableBackgroundPolling
boolean isDisableBackgroundPolling()Checks whetherLDConfig.Builder.disableBackgroundUpdating(boolean)
was set totrue
in the configuration.- Returns:
- true if background polling is disabled
-
getVersion
String getVersion()Returns the version of the SDK, for instance "2.7.0".- Returns:
- the version string
- Since:
- 2.7.0
-