Interface LDClientInterface
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable
- All Known Implementing Classes:
LDClient
public interface LDClientInterface
extends java.io.Closeable
LDClient.
Applications will normally interact directly with LDClient, and must use its constructor to
initialize the SDK, but being able to refer to it indirectly via an interface may be helpul in test
scenarios (mocking) or for some dependency injection frameworks.
-
Method Summary
Modifier and Type Method Description FeatureFlagsStateallFlagsState(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.booleanboolVariation(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.voidclose()Closes the LaunchDarkly client event processing thread.doubledoubleVariation(java.lang.String featureKey, LDUser user, 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.voidflush()Flushes all pending events.DataSourceStatusProvidergetDataSourceStatusProvider()Returns an interface for tracking the status of the data source.DataStoreStatusProvidergetDataStoreStatusProvider()Returns an interface for tracking the status of a persistent data store.FlagTrackergetFlagTracker()Returns an interface for tracking changes in feature flag configurations.voididentify(LDUser user)Registers the user.intintVariation(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.booleanisFlagKnown(java.lang.String featureKey)Returns true if the specified feature flag currently exists.booleanisInitialized()Tests whether the client is ready to be used.booleanisOffline()Returns true if the client is in offline mode.LDValuejsonValueVariation(java.lang.String featureKey, LDUser user, LDValue defaultValue)Calculates theLDValuevalue of a feature flag for a given user.EvaluationDetail<LDValue>jsonValueVariationDetail(java.lang.String featureKey, LDUser user, LDValue defaultValue)Calculates theLDValuevalue of a feature flag for a given user.java.lang.StringsecureModeHash(LDUser user)For more info: https://github.com/launchdarkly/js-client#secure-modejava.lang.StringstringVariation(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.voidtrack(java.lang.String eventName, LDUser user)Tracks that a user performed an event.voidtrackData(java.lang.String eventName, LDUser user, LDValue data)Tracks that a user performed an event, and provides additional custom data.voidtrackMetric(java.lang.String eventName, LDUser user, LDValue data, double metricValue)Tracks that a user performed an event, and provides an additional numeric value for custom metrics.java.lang.Stringversion()The current version string of the SDK.
-
Method Details
-
isInitialized
boolean isInitialized()Tests whether the client is ready to be used.- Returns:
- true if the client is ready, or false if it is still initializing
-
track
Tracks that a user performed an event.To add custom data to the event, use
trackData(String, LDUser, LDValue).- Parameters:
eventName- the name of the eventuser- the user that performed the event
-
trackData
Tracks that a user performed an event, and provides additional custom data.- Parameters:
eventName- the name of the eventuser- the user that performed the eventdata- anLDValuecontaining additional data associated with the event- Since:
- 4.8.0
-
trackMetric
Tracks that a user performed an event, and provides an additional numeric value for custom metrics.- Parameters:
eventName- the name of the eventuser- the user that performed the eventdata- anLDValuecontaining additional data associated with the event; if not applicable, you may pass eithernullorLDValue.ofNull()metricValue- a numeric value used by the LaunchDarkly experimentation feature in numeric custom metrics. Can be omitted if this event is used by only non-numeric metrics. This field will also be returned as part of the custom event for Data Export.- Since:
- 4.9.0
-
identify
Registers the user.- Parameters:
user- the user to register
-
allFlagsState
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. This method does 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.
- Parameters:
user- the end user requesting the feature flagsoptions- optionalFlagsStateOptionvalues affecting how the state is computed - for instance, to filter the set of flags to only include the client-side-enabled ones- Returns:
- a
FeatureFlagsStateobject (will never be null; seeFeatureFlagsState.isValid() - Since:
- 4.3.0
-
boolVariation
Calculates the value of a feature flag for a given user.- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- whether or not the flag should be enabled, or
defaultValueif the flag is disabled in the LaunchDarkly control panel
-
intVariation
Calculates the integer value of a feature flag for a given user.If the flag variation has a numeric value that is not an integer, it is rounded toward zero (truncated).
- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- the variation for the given user, or
defaultValueif the flag is disabled in the LaunchDarkly control panel
-
doubleVariation
Calculates the floating point numeric value of a feature flag for a given user.- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- the variation for the given user, or
defaultValueif the flag is disabled in the LaunchDarkly control panel
-
stringVariation
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.- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- the variation for the given user, or
defaultValueif the flag is disabled in the LaunchDarkly control panel
-
jsonValueVariation
Calculates theLDValuevalue of a feature flag for a given user.- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- the variation for the given user, or
defaultValueif the flag is disabled in the LaunchDarkly control panel; will never be a null reference, but may beLDValue.ofNull() - Since:
- 4.8.0
-
boolVariationDetail
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. Thereasonproperty in the result will also be included in analytics events, if you are capturing detailed event data for this flag.- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
EvaluationDetailobject - Since:
- 2.3.0
-
intVariationDetail
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. Thereasonproperty in the result will also be included in analytics events, if you are capturing detailed event data for this flag.If the flag variation has a numeric value that is not an integer, it is rounded toward zero (truncated).
- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
EvaluationDetailobject - Since:
- 2.3.0
-
doubleVariationDetail
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. Thereasonproperty in the result will also be included in analytics events, if you are capturing detailed event data for this flag.- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
EvaluationDetailobject - Since:
- 2.3.0
-
stringVariationDetail
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. Thereasonproperty in the result will also be included in analytics events, if you are capturing detailed event data for this flag.- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
EvaluationDetailobject - Since:
- 2.3.0
-
jsonValueVariationDetail
EvaluationDetail<LDValue> jsonValueVariationDetail(java.lang.String featureKey, LDUser user, LDValue defaultValue)Calculates theLDValuevalue of a feature flag for a given user.- Parameters:
featureKey- the unique key for the feature flaguser- the end user requesting the flagdefaultValue- the default value of the flag- Returns:
- an
EvaluationDetailobject - Since:
- 4.8.0
-
isFlagKnown
boolean isFlagKnown(java.lang.String featureKey)Returns true if the specified feature flag currently exists.- Parameters:
featureKey- the unique key for the feature flag- Returns:
- true if the flag exists
-
close
void close() throws java.io.IOExceptionCloses the LaunchDarkly client event processing thread. This should only be called on application shutdown.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException- if an exception is thrown by one of the underlying network services
-
flush
void flush()Flushes all pending events. -
isOffline
boolean isOffline()Returns true if the client is in offline mode.- Returns:
- whether the client is in offline mode
-
getFlagTracker
FlagTracker getFlagTracker()Returns an interface for tracking changes in feature flag configurations.The
FlagTrackercontains methods for requesting notifications about feature flag changes using an event listener model.- Returns:
- a
FlagTracker - Since:
- 5.0.0
-
getDataSourceStatusProvider
DataSourceStatusProvider getDataSourceStatusProvider()Returns an interface for tracking the status of the data source.The data source is the mechanism that the SDK uses to get feature flag configurations, such as a streaming connection (the default) or poll requests. The
DataSourceStatusProviderhas methods for checking whether the data source is (as far as the SDK knows) currently operational and tracking changes in this status.- Returns:
- a
DataSourceStatusProvider - Since:
- 5.0.0
-
getDataStoreStatusProvider
DataStoreStatusProvider getDataStoreStatusProvider()Returns an interface for tracking the status of a persistent data store.The
DataStoreStatusProviderhas methods for checking whether the data store is (as far as the SDK knows) currently operational, tracking changes in this status, and getting cache statistics. These are only relevant for a persistent data store; if you are using an in-memory data store, then this method will return a stub object that provides no information.- Returns:
- a
DataStoreStatusProvider - Since:
- 5.0.0
-
secureModeHash
For more info: https://github.com/launchdarkly/js-client#secure-mode- Parameters:
user- the user to be hashed along with the SDK key- Returns:
- the hash, or null if the hash could not be calculated
-
version
java.lang.String version()The current version string of the SDK.- Returns:
- a string in Semantic Versioning 2.0.0 format
-