public class LDClient extends java.lang.Object implements LDClientInterface, java.io.Closeable
init(Application, LDConfig, LDUser)
method.Modifier | Constructor and Description |
---|---|
protected |
LDClient(android.app.Application application,
LDConfig config) |
protected |
LDClient(android.app.Application application,
LDConfig config,
java.lang.String environmentName) |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,?> |
allFlags()
Returns a map of all feature flags for the current user.
|
java.lang.Boolean |
boolVariation(java.lang.String flagKey,
java.lang.Boolean fallback)
Returns the flag value for the current user.
|
EvaluationDetail<java.lang.Boolean> |
boolVariationDetail(java.lang.String flagKey,
java.lang.Boolean fallback)
Returns the flag value for the current user, along with information about how it was calculated.
|
void |
close()
Closes the client.
|
java.lang.Float |
floatVariation(java.lang.String flagKey,
java.lang.Float fallback)
Returns the flag value for the current user.
|
EvaluationDetail<java.lang.Float> |
floatVariationDetail(java.lang.String flagKey,
java.lang.Float fallback)
Returns the flag value for the current user, along with information about how it was calculated.
|
void |
flush()
Sends all pending events to LaunchDarkly.
|
static LDClient |
get() |
ConnectionInformation |
getConnectionInformation()
Gets a
ConnectionInformation object from the client representing the current state
of the clients connection. |
static LDClient |
getForMobileKey(java.lang.String keyName) |
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.
|
static java.util.concurrent.Future<LDClient> |
init(android.app.Application application,
LDConfig config,
LDUser user)
Initializes the singleton/primary instance.
|
static LDClient |
init(android.app.Application application,
LDConfig config,
LDUser user,
int startWaitSeconds)
Initializes the singleton instance and blocks for up to
startWaitSeconds seconds
until the client has been initialized. |
java.lang.Integer |
intVariation(java.lang.String flagKey,
java.lang.Integer fallback)
Returns the flag value for the current user.
|
EvaluationDetail<java.lang.Integer> |
intVariationDetail(java.lang.String flagKey,
java.lang.Integer fallback)
Returns the flag value for the current user, along with information about how it was calculated.
|
boolean |
isDisableBackgroundPolling()
Checks whether
LDConfig.Builder.setDisableBackgroundUpdating(boolean) was set to
true 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.
|
com.google.gson.JsonElement |
jsonVariation(java.lang.String flagKey,
com.google.gson.JsonElement fallback)
Returns the flag value for the current user.
|
EvaluationDetail<com.google.gson.JsonElement> |
jsonVariationDetail(java.lang.String flagKey,
com.google.gson.JsonElement fallback)
Returns the flag value for the current user, along with information about how it was calculated.
|
void |
registerAllFlagsListener(LDAllFlagsListener allFlagsListener)
Registers a
LDAllFlagsListener to be called when a flag update is processed by the
SDK. |
void |
registerFeatureFlagListener(java.lang.String flagKey,
FeatureFlagChangeListener listener)
Registers a
FeatureFlagChangeListener to be called when the flagKey changes
from its current value. |
void |
registerStatusListener(LDStatusListener LDStatusListener) |
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 until
setOnline() 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 fallback)
Returns the flag value for the current user.
|
EvaluationDetail<java.lang.String> |
stringVariationDetail(java.lang.String flagKey,
java.lang.String fallback)
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 |
track(java.lang.String eventName,
com.google.gson.JsonElement data)
Tracks that a user performed an event.
|
void |
unregisterAllFlagsListener(LDAllFlagsListener allFlagsListener)
Unregisters a
LDAllFlagsListener so it will no longer be called on flag updates. |
void |
unregisterFeatureFlagListener(java.lang.String flagKey,
FeatureFlagChangeListener listener)
Unregisters a
FeatureFlagChangeListener for the flagKey . |
void |
unregisterStatusListener(LDStatusListener LDStatusListener) |
protected LDClient(android.app.Application application, LDConfig config)
protected LDClient(android.app.Application application, LDConfig config, java.lang.String environmentName)
public static java.util.concurrent.Future<LDClient> init(android.app.Application application, LDConfig config, LDUser user)
Future
which
will complete once the client has been initialized with the latest feature flag values. For
immediate access to the Client (possibly with out of date feature flags), it is safe to ignore
the return value of this method, and afterward call get()
If the client has already been initialized, is configured for offline mode, or the device is
not connected to the internet, this method will return a Future
that is
already in the completed state.application
- Your Android application.config
- Configuration used to set up the clientuser
- The user used in evaluating feature flagsFuture
which will complete once the client has been initialized.public static LDClient init(android.app.Application application, LDConfig config, LDUser user, int startWaitSeconds)
startWaitSeconds
seconds
until the client has been initialized. If the client does not initialize within
startWaitSeconds
seconds, it is returned anyway and can be used, but may not
have fetched the most recent feature flag values.application
- Your Android application.config
- Configuration used to set up the clientuser
- The user used in evaluating feature flagsstartWaitSeconds
- Maximum number of seconds to wait for the client to initializepublic static LDClient get() throws LaunchDarklyException
LaunchDarklyException
- if init(Application, LDConfig, LDUser)
has not been called.public static LDClient getForMobileKey(java.lang.String keyName) throws LaunchDarklyException
keyName
- The name to lookup the instance by.LaunchDarklyException
- if init(Application, LDConfig, LDUser)
has not been called.public void track(java.lang.String eventName, com.google.gson.JsonElement data)
LDClientInterface
track
in interface LDClientInterface
eventName
- the name of the eventdata
- a JSON object containing additional data associated with the eventpublic void track(java.lang.String eventName)
LDClientInterface
track
in interface LDClientInterface
eventName
- the name of the eventpublic java.util.concurrent.Future<java.lang.Void> identify(LDUser user)
LDClientInterface
identify
in interface LDClientInterface
user
- The user for evaluation and event reportingpublic java.util.Map<java.lang.String,?> allFlags()
LDClientInterface
allFlags
in interface LDClientInterface
public java.lang.Boolean boolVariation(java.lang.String flagKey, java.lang.Boolean fallback)
LDClientInterface
fallback
when one of the following occurs:
boolVariation
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flagpublic EvaluationDetail<java.lang.Boolean> boolVariationDetail(java.lang.String flagKey, java.lang.Boolean fallback)
LDClientInterface
evaluationReasons
to true in
LDConfig.Builder.evaluationReasons
. Otherwise, the reason
property of the result
will be null.boolVariationDetail
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flag (see LDClientInterface.boolVariation(String, Boolean)
)EvaluationDetail
object containing the value and other information.public java.lang.Integer intVariation(java.lang.String flagKey, java.lang.Integer fallback)
LDClientInterface
fallback
when one of the following occurs:
intVariation
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flagpublic EvaluationDetail<java.lang.Integer> intVariationDetail(java.lang.String flagKey, java.lang.Integer fallback)
LDClientInterface
evaluationReasons
to true in
LDConfig.Builder.evaluationReasons
. Otherwise, the reason
property of the result
will be null.intVariationDetail
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flag (see LDClientInterface.intVariation(String, Integer)
)EvaluationDetail
object containing the value and other information.public java.lang.Float floatVariation(java.lang.String flagKey, java.lang.Float fallback)
LDClientInterface
fallback
when one of the following occurs:
floatVariation
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flagpublic EvaluationDetail<java.lang.Float> floatVariationDetail(java.lang.String flagKey, java.lang.Float fallback)
LDClientInterface
evaluationReasons
to true in
LDConfig.Builder.evaluationReasons
. Otherwise, the reason
property of the result
will be null.floatVariationDetail
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flag (see LDClientInterface.floatVariation(String, Float)
)EvaluationDetail
object containing the value and other information.public java.lang.String stringVariation(java.lang.String flagKey, java.lang.String fallback)
LDClientInterface
fallback
when one of the following occurs:
stringVariation
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flagpublic EvaluationDetail<java.lang.String> stringVariationDetail(java.lang.String flagKey, java.lang.String fallback)
LDClientInterface
evaluationReasons
to true in
LDConfig.Builder.evaluationReasons
. Otherwise, the reason
property of the result
will be null.stringVariationDetail
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flag (see LDClientInterface.stringVariation(String, String)
)EvaluationDetail
object containing the value and other information.public com.google.gson.JsonElement jsonVariation(java.lang.String flagKey, com.google.gson.JsonElement fallback)
LDClientInterface
fallback
when one of the following occurs:
jsonVariation
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flagpublic EvaluationDetail<com.google.gson.JsonElement> jsonVariationDetail(java.lang.String flagKey, com.google.gson.JsonElement fallback)
LDClientInterface
evaluationReasons
to true in
LDConfig.Builder.evaluationReasons
. Otherwise, the reason
property of the result
will be null.jsonVariationDetail
in interface LDClientInterface
flagKey
- key for the flag to evaluatefallback
- fallback value in case of errors evaluating the flag (see LDClientInterface.jsonVariation(String, JsonElement)
)EvaluationDetail
object containing the value and other information.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public void flush()
LDClientInterface
flush
in interface LDClientInterface
public boolean isInitialized()
LDClientInterface
isInitialized
in interface LDClientInterface
public boolean isOffline()
LDClientInterface
LDClientInterface.setOffline()
was called, or if the configuration had LDConfig.Builder.setOffline(boolean)
set to true,
not if the client is simply offline due to a loss of network connectivity.isOffline
in interface LDClientInterface
public void setOffline()
LDClientInterface
setOnline()
is called.
Note: The client automatically monitors the device's network connectivity and app foreground
status, so calling setOffline()
or setOnline()
is normally
unnecessary in most situations.setOffline
in interface LDClientInterface
public void setOnline()
LDClientInterface
setOffline()
or setOnline()
is normally
unnecessary in most situations.setOnline
in interface LDClientInterface
public void registerFeatureFlagListener(java.lang.String flagKey, FeatureFlagChangeListener listener)
LDClientInterface
FeatureFlagChangeListener
to be called when the flagKey
changes
from its current value. If the feature flag is deleted, the listener
will be unregistered.registerFeatureFlagListener
in interface LDClientInterface
flagKey
- the flag key to attach the listener tolistener
- the listener to attach to the flag keyLDClientInterface.unregisterFeatureFlagListener(String, FeatureFlagChangeListener)
public void unregisterFeatureFlagListener(java.lang.String flagKey, FeatureFlagChangeListener listener)
LDClientInterface
FeatureFlagChangeListener
for the flagKey
.unregisterFeatureFlagListener
in interface LDClientInterface
flagKey
- the flag key to remove the listener fromlistener
- the listener to remove from the flag keyLDClientInterface.registerFeatureFlagListener(String, FeatureFlagChangeListener)
public boolean isDisableBackgroundPolling()
LDClientInterface
LDConfig.Builder.setDisableBackgroundUpdating(boolean)
was set to
true
in the configuration.isDisableBackgroundPolling
in interface LDClientInterface
public ConnectionInformation getConnectionInformation()
LDClientInterface
ConnectionInformation
object from the client representing the current state
of the clients connection.getConnectionInformation
in interface LDClientInterface
public void registerStatusListener(LDStatusListener LDStatusListener)
registerStatusListener
in interface LDClientInterface
public void unregisterStatusListener(LDStatusListener LDStatusListener)
unregisterStatusListener
in interface LDClientInterface
public void registerAllFlagsListener(LDAllFlagsListener allFlagsListener)
LDClientInterface
LDAllFlagsListener
to be called when a flag update is processed by the
SDK.registerAllFlagsListener
in interface LDClientInterface
allFlagsListener
- the listener to be called on a flag updatepublic void unregisterAllFlagsListener(LDAllFlagsListener allFlagsListener)
LDClientInterface
LDAllFlagsListener
so it will no longer be called on flag updates.unregisterAllFlagsListener
in interface LDClientInterface
allFlagsListener
- the listener to be removedpublic java.lang.String getVersion()
LDClientInterface
getVersion
in interface LDClientInterface