Package com.launchdarkly.sdk.android
Interface LDClientInterface
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
- All Known Implementing Classes:
LDClient
public interface LDClientInterface extends java.io.Closeable
The interface for the LaunchDarkly SDK client.To obtain a client instance, use
LDClient
methods such asLDClient.init(Application, LDConfig, LDUser)
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Map<java.lang.String,LDValue>
allFlags()
Returns a map of all feature flags for the current user.boolean
boolVariation(java.lang.String flagKey, boolean defaultValue)
Returns the flag value for the current user.EvaluationDetail<java.lang.Boolean>
boolVariationDetail(java.lang.String flagKey, boolean defaultValue)
Returns the flag value for the current user, along with information about how it was calculated.double
doubleVariation(java.lang.String flagKey, double defaultValue)
Returns the flag value for the current user.EvaluationDetail<java.lang.Double>
doubleVariationDetail(java.lang.String flagKey, double defaultValue)
Returns the flag value for the current user, along with information about how it was calculated.void
flush()
Sends all pending events to LaunchDarkly.ConnectionInformation
getConnectionInformation()
Gets aConnectionInformation
object from the client representing the current state of the clients connection.java.lang.String
getVersion()
Returns the version of the SDK, for instance "2.7.0".java.util.concurrent.Future<java.lang.Void>
identify(LDUser user)
Sets the current user, retrieves flags for that user, then sends an Identify Event to LaunchDarkly.int
intVariation(java.lang.String flagKey, int defaultValue)
Returns the flag value for the current user.EvaluationDetail<java.lang.Integer>
intVariationDetail(java.lang.String flagKey, int defaultValue)
Returns the flag value for the current user, along with information about how it was calculated.boolean
isDisableBackgroundPolling()
Checks whetherLDConfig.Builder.disableBackgroundUpdating(boolean)
was set totrue
in the configuration.boolean
isInitialized()
Checks whether the client is ready to return feature flag values.boolean
isOffline()
Checks whether the client has been put into offline mode.LDValue
jsonValueVariation(java.lang.String flagKey, LDValue defaultValue)
Returns the flag value for the current user.EvaluationDetail<LDValue>
jsonValueVariationDetail(java.lang.String flagKey, LDValue defaultValue)
Returns the flag value for the current user, 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(java.lang.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
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.void
setOnline()
Restores network connectivity for the client, if the client was previously in offline mode.java.lang.String
stringVariation(java.lang.String flagKey, java.lang.String defaultValue)
Returns the flag value for the current user.EvaluationDetail<java.lang.String>
stringVariationDetail(java.lang.String flagKey, java.lang.String defaultValue)
Returns the flag value for the current user, along with information about how it was calculated.void
track(java.lang.String eventName)
Tracks that a user performed an event.void
trackData(java.lang.String eventName, LDValue data)
Tracks that a user performed an event, and provides additional custom data.void
trackMetric(java.lang.String eventName, LDValue data, double metricValue)
Tracks that a user performed an event, 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(java.lang.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 Detail
-
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
void trackMetric(java.lang.String eventName, LDValue data, double metricValue)
Tracks that a user performed an event, and provides an additional numeric value for custom metrics.- 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.
-
trackData
void trackData(java.lang.String eventName, LDValue data)
Tracks that a user performed an event, and provides additional custom data.- Parameters:
eventName
- the name of the eventdata
- anLDValue
containing additional data associated with the event
-
track
void track(java.lang.String eventName)
Tracks that a user performed an event.- Parameters:
eventName
- the name of the event
-
identify
java.util.concurrent.Future<java.lang.Void> identify(LDUser user)
Sets the current user, retrieves flags for that user, then sends an Identify Event to LaunchDarkly. The 5 most recent users' flag settings are kept locally.- Parameters:
user
- The user for evaluation and event reporting- Returns:
- Future whose success indicates this user's flag settings have been stored locally and are ready for evaluation.
-
flush
void flush()
Sends all pending events to LaunchDarkly.
-
allFlags
java.util.Map<java.lang.String,LDValue> allFlags()
Returns a map of all feature flags for the current user. No events are sent to LaunchDarkly.- Returns:
- a map of all feature flags
-
boolVariation
boolean boolVariation(java.lang.String flagKey, boolean defaultValue)
Returns the flag value for the current user. ReturnsdefaultValue
when one of the following occurs:- Flag is missing
- The flag is not of a boolean type
- Any other error
- 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
EvaluationDetail<java.lang.Boolean> boolVariationDetail(java.lang.String flagKey, boolean defaultValue)
Returns the flag value for the current user, 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.- 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
int intVariation(java.lang.String flagKey, int defaultValue)
Returns the flag value for the current user. ReturnsdefaultValue
when one of the following occurs:- Flag is missing
- The flag is not of a numeric type
- Any other error
- 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
EvaluationDetail<java.lang.Integer> intVariationDetail(java.lang.String flagKey, int defaultValue)
Returns the flag value for the current user, 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.- 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
double doubleVariation(java.lang.String flagKey, double defaultValue)
Returns the flag value for the current user. ReturnsdefaultValue
when one of the following occurs:- Flag is missing
- The flag is not of a numeric type
- Any other error
- 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
EvaluationDetail<java.lang.Double> doubleVariationDetail(java.lang.String flagKey, double defaultValue)
Returns the flag value for the current user, 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.- 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
java.lang.String stringVariation(java.lang.String flagKey, java.lang.String defaultValue)
Returns the flag value for the current user. Returnsdefault
when one of the following occurs:- Flag is missing
- The flag is not of a string type
- Any other error
- 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
EvaluationDetail<java.lang.String> stringVariationDetail(java.lang.String flagKey, java.lang.String defaultValue)
Returns the flag value for the current user, 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.- 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
void registerFeatureFlagListener(java.lang.String flagKey, FeatureFlagChangeListener listener)
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:
unregisterFeatureFlagListener(String, FeatureFlagChangeListener)
-
jsonValueVariation
LDValue jsonValueVariation(java.lang.String flagKey, LDValue defaultValue)
Returns the flag value for the current user. ReturnsdefualtValue
when one of the following occurs:- Flag is missing
- Any other error
- 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
EvaluationDetail<LDValue> jsonValueVariationDetail(java.lang.String flagKey, LDValue defaultValue)
Returns the flag value for the current user, 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.- 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
void unregisterFeatureFlagListener(java.lang.String flagKey, FeatureFlagChangeListener listener)
Unregisters aFeatureFlagChangeListener
for theflagKey
.- Parameters:
flagKey
- the flag key to remove the listener fromlistener
- the listener to remove from the flag key- See Also:
registerFeatureFlagListener(String, FeatureFlagChangeListener)
-
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
void unregisterStatusListener(LDStatusListener LDStatusListener)
Unregisters aLDStatusListener
so it will no longer be called on connection status updates.- Parameters:
LDStatusListener
- the listener to be removed
-
registerStatusListener
void registerStatusListener(LDStatusListener LDStatusListener)
Registers aLDStatusListener
to be called on connection status updates.- Parameters:
LDStatusListener
- the listener to be called on a connection status update
-
registerAllFlagsListener
void registerAllFlagsListener(LDAllFlagsListener allFlagsListener)
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
void unregisterAllFlagsListener(LDAllFlagsListener allFlagsListener)
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
java.lang.String getVersion()
Returns the version of the SDK, for instance "2.7.0".- Returns:
- the version string
- Since:
- 2.7.0
-
-