public final class LDClient extends java.lang.Object implements LDClientInterface
LDClient
for the lifetime of their application.Constructor and Description |
---|
LDClient(java.lang.String sdkKey)
Creates a new client instance that connects to LaunchDarkly with the default configuration.
|
LDClient(java.lang.String sdkKey,
LDConfig config)
Creates a new client to connect to LaunchDarkly with a custom configuration.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,com.google.gson.JsonElement> |
allFlags(LDUser user)
Returns a map from feature flag keys to
JsonElement feature flag values for a given user. |
FeatureFlagsState |
allFlagsState(LDUser user,
FlagsStateOption... options)
Returns an object that encapsulates the state of all feature flags for a given user, including the flag
values and also metadata that can be used on the front end.
|
boolean |
boolVariation(java.lang.String featureKey,
LDUser user,
boolean defaultValue)
Calculates the value of a feature flag for a given user.
|
EvaluationDetail<java.lang.Boolean> |
boolVariationDetail(java.lang.String featureKey,
LDUser user,
boolean defaultValue)
Calculates the value of a feature flag for a given user, and returns an object that describes the
way the value was determined.
|
void |
close()
Closes the LaunchDarkly client event processing thread.
|
java.lang.Double |
doubleVariation(java.lang.String featureKey,
LDUser user,
java.lang.Double defaultValue)
Calculates the floating point numeric value of a feature flag for a given user.
|
EvaluationDetail<java.lang.Double> |
doubleVariationDetail(java.lang.String featureKey,
LDUser user,
double defaultValue)
Calculates the value of a feature flag for a given user, and returns an object that describes the
way the value was determined.
|
void |
flush()
Flushes all pending events.
|
void |
identify(LDUser user)
Registers the user.
|
boolean |
initialized() |
java.lang.Integer |
intVariation(java.lang.String featureKey,
LDUser user,
int defaultValue)
Calculates the integer value of a feature flag for a given user.
|
EvaluationDetail<java.lang.Integer> |
intVariationDetail(java.lang.String featureKey,
LDUser user,
int defaultValue)
Calculates the value of a feature flag for a given user, and returns an object that describes the
way the value was determined.
|
boolean |
isFlagKnown(java.lang.String featureKey)
Returns true if the specified feature flag currently exists.
|
boolean |
isOffline()
Returns true if the client is in offline mode.
|
com.google.gson.JsonElement |
jsonVariation(java.lang.String featureKey,
LDUser user,
com.google.gson.JsonElement defaultValue)
Calculates the
JsonElement value of a feature flag for a given user. |
EvaluationDetail<com.google.gson.JsonElement> |
jsonVariationDetail(java.lang.String featureKey,
LDUser user,
com.google.gson.JsonElement defaultValue)
Calculates the value of a feature flag for a given user, and returns an object that describes the
way the value was determined.
|
java.lang.String |
secureModeHash(LDUser user)
For more info: https://github.com/launchdarkly/js-client#secure-mode
|
java.lang.String |
stringVariation(java.lang.String featureKey,
LDUser user,
java.lang.String defaultValue)
Calculates the String value of a feature flag for a given user.
|
EvaluationDetail<java.lang.String> |
stringVariationDetail(java.lang.String featureKey,
LDUser user,
java.lang.String defaultValue)
Calculates the value of a feature flag for a given user, and returns an object that describes the
way the value was determined.
|
void |
track(java.lang.String eventName,
LDUser user)
Tracks that a user performed an event.
|
void |
track(java.lang.String eventName,
LDUser user,
com.google.gson.JsonElement data)
Tracks that a user performed an event.
|
java.lang.String |
version()
Returns the current version string of the client library.
|
public LDClient(java.lang.String sdkKey)
sdkKey
- the SDK key for your LaunchDarkly environmentpublic LDClient(java.lang.String sdkKey, LDConfig config)
sdkKey
- the SDK key for your LaunchDarkly environmentconfig
- a client configuration objectpublic boolean initialized()
initialized
in interface LDClientInterface
public void track(java.lang.String eventName, LDUser user, com.google.gson.JsonElement data)
LDClientInterface
track
in interface LDClientInterface
eventName
- the name of the eventuser
- the user that performed the eventdata
- a JSON object containing additional data associated with the eventpublic void track(java.lang.String eventName, LDUser user)
LDClientInterface
track
in interface LDClientInterface
eventName
- the name of the eventuser
- the user that performed the eventpublic void identify(LDUser user)
LDClientInterface
identify
in interface LDClientInterface
user
- the user to registerpublic java.util.Map<java.lang.String,com.google.gson.JsonElement> allFlags(LDUser user)
LDClientInterface
JsonElement
feature flag values for a given user.
If the result of a flag's evaluation would have returned the default variation, it will have a null entry
in the map. If the client is offline, has not been initialized, or a null user or user with null/empty user key a null
map will be returned.
This method will not send analytics events back to LaunchDarkly.
The most common use case for this method is to bootstrap a set of client-side feature flags from a back-end service.
allFlags
in interface LDClientInterface
user
- the end user requesting the feature flagsJsonElement
for the specified userpublic FeatureFlagsState allFlagsState(LDUser user, FlagsStateOption... options)
LDClientInterface
The most common use case for this method is to bootstrap a set of client-side feature flags from a back-end service.
allFlagsState
in interface LDClientInterface
user
- the end user requesting the feature flagsoptions
- optional FlagsStateOption
values affecting how the state is computed - for
instance, to filter the set of flags to only include the client-side-enabled onesFeatureFlagsState
object (will never be null; see FeatureFlagsState.isValid()
public boolean boolVariation(java.lang.String featureKey, LDUser user, boolean defaultValue)
LDClientInterface
boolVariation
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagdefaultValue
if the flag is disabled in the LaunchDarkly control panelpublic java.lang.Integer intVariation(java.lang.String featureKey, LDUser user, int defaultValue)
LDClientInterface
intVariation
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagdefaultValue
if the flag is disabled in the LaunchDarkly control panelpublic java.lang.Double doubleVariation(java.lang.String featureKey, LDUser user, java.lang.Double defaultValue)
LDClientInterface
doubleVariation
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagdefaultValue
if the flag is disabled in the LaunchDarkly control panelpublic java.lang.String stringVariation(java.lang.String featureKey, LDUser user, java.lang.String defaultValue)
LDClientInterface
stringVariation
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagdefaultValue
if the flag is disabled in the LaunchDarkly control panelpublic com.google.gson.JsonElement jsonVariation(java.lang.String featureKey, LDUser user, com.google.gson.JsonElement defaultValue)
LDClientInterface
JsonElement
value of a feature flag for a given user.jsonVariation
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagdefaultValue
if the flag is disabled in the LaunchDarkly control panelpublic EvaluationDetail<java.lang.Boolean> boolVariationDetail(java.lang.String featureKey, LDUser user, boolean defaultValue)
LDClientInterface
reason
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.boolVariationDetail
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagEvaluationDetail
objectpublic EvaluationDetail<java.lang.Integer> intVariationDetail(java.lang.String featureKey, LDUser user, int defaultValue)
LDClientInterface
reason
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.intVariationDetail
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagEvaluationDetail
objectpublic EvaluationDetail<java.lang.Double> doubleVariationDetail(java.lang.String featureKey, LDUser user, double defaultValue)
LDClientInterface
reason
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.doubleVariationDetail
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagEvaluationDetail
objectpublic EvaluationDetail<java.lang.String> stringVariationDetail(java.lang.String featureKey, LDUser user, java.lang.String defaultValue)
LDClientInterface
reason
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.stringVariationDetail
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagEvaluationDetail
objectpublic EvaluationDetail<com.google.gson.JsonElement> jsonVariationDetail(java.lang.String featureKey, LDUser user, com.google.gson.JsonElement defaultValue)
LDClientInterface
reason
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.jsonVariationDetail
in interface LDClientInterface
featureKey
- the unique key for the feature flaguser
- the end user requesting the flagdefaultValue
- the default value of the flagEvaluationDetail
objectpublic boolean isFlagKnown(java.lang.String featureKey)
LDClientInterface
isFlagKnown
in interface LDClientInterface
featureKey
- the unique key for the feature flagpublic void close() throws java.io.IOException
LDClientInterface
close
in interface LDClientInterface
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if an exception is thrown by one of the underlying network servicespublic void flush()
LDClientInterface
flush
in interface LDClientInterface
public boolean isOffline()
LDClientInterface
isOffline
in interface LDClientInterface
public java.lang.String secureModeHash(LDUser user)
LDClientInterface
secureModeHash
in interface LDClientInterface
user
- the user to be hashed along with the SDK keypublic java.lang.String version()
version
in interface LDClientInterface