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 helpful in test
scenarios (mocking) or for some dependency injection frameworks.
Modifier and Type | Method and Description |
---|---|
FeatureFlagsState |
allFlagsState(LDContext context,
FlagsStateOption... options)
Returns an object that encapsulates the state of all feature flags for a given context, which can be
passed to front-end code.
|
boolean |
boolVariation(java.lang.String key,
LDContext context,
boolean defaultValue)
Calculates the boolean value of a feature flag for a given context.
|
EvaluationDetail<java.lang.Boolean> |
boolVariationDetail(java.lang.String key,
LDContext context,
boolean defaultValue)
Calculates the boolean value of a feature flag for a given context, and returns an object that
describes the way the value was determined.
|
void |
close()
Closes the LaunchDarkly client event processing thread.
|
double |
doubleVariation(java.lang.String key,
LDContext context,
double defaultValue)
Calculates the floating-point numeric value of a feature flag for a given context.
|
EvaluationDetail<java.lang.Double> |
doubleVariationDetail(java.lang.String key,
LDContext context,
double defaultValue)
Calculates the floating-point numeric value of a feature flag for a given context, and returns an
object that describes the way the value was determined.
|
void |
flush()
Flushes all pending events.
|
BigSegmentStoreStatusProvider |
getBigSegmentStoreStatusProvider()
Returns an interface for tracking the status of the Big Segment store.
|
DataSourceStatusProvider |
getDataSourceStatusProvider()
Returns an interface for tracking the status of the data source.
|
DataStoreStatusProvider |
getDataStoreStatusProvider()
Returns an interface for tracking the status of a persistent data store.
|
FlagTracker |
getFlagTracker()
Returns an interface for tracking changes in feature flag configurations.
|
LDLogger |
getLogger()
Returns the logger instance used by this SDK instance.
|
void |
identify(LDContext context)
Reports details about an evaluation context.
|
int |
intVariation(java.lang.String key,
LDContext context,
int defaultValue)
Calculates the integer value of a feature flag for a given context.
|
EvaluationDetail<java.lang.Integer> |
intVariationDetail(java.lang.String key,
LDContext context,
int defaultValue)
Calculates the integer numeric value of a feature flag for a given context, 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 |
isInitialized()
Tests whether the client is ready to be used.
|
boolean |
isOffline()
Returns true if the client is in offline mode.
|
LDValue |
jsonValueVariation(java.lang.String key,
LDContext context,
LDValue defaultValue)
Calculates the value of a feature flag for a given context as any JSON value type.
|
EvaluationDetail<LDValue> |
jsonValueVariationDetail(java.lang.String key,
LDContext context,
LDValue defaultValue)
Calculates the value of a feature flag for a given context as any JSON value type, and returns an
object that describes the way the value was determined.
|
MigrationVariation |
migrationVariation(java.lang.String key,
LDContext context,
MigrationStage defaultStage)
Returns the migration stage of the migration feature flag for the given
evaluation context.
|
java.lang.String |
secureModeHash(LDContext context)
Creates a hash string that can be used by the JavaScript SDK to identify a context.
|
java.lang.String |
stringVariation(java.lang.String key,
LDContext context,
java.lang.String defaultValue)
Calculates the string value of a feature flag for a given context.
|
EvaluationDetail<java.lang.String> |
stringVariationDetail(java.lang.String key,
LDContext context,
java.lang.String defaultValue)
Calculates the string value of a feature flag for a given context, and returns an object
that describes the way the value was determined.
|
void |
track(java.lang.String eventName,
LDContext context)
Tracks that an application-defined event occurred.
|
void |
trackData(java.lang.String eventName,
LDContext context,
LDValue data)
Tracks that an application-defined event occurred.
|
void |
trackMetric(java.lang.String eventName,
LDContext context,
LDValue data,
double metricValue)
Tracks that an application-defined event occurred, and provides an additional numeric value for
custom metrics.
|
void |
trackMigration(MigrationOpTracker tracker)
Track the details of a migration.
|
java.lang.String |
version()
The current version string of the SDK.
|
boolean isInitialized()
void track(java.lang.String eventName, LDContext context)
This method creates a "custom" analytics event containing the specified event name (key)
and context properties. You may attach arbitrary data or a metric value to the event by calling
trackData(String, LDContext, LDValue)
or trackMetric(String, LDContext, LDValue, double)
instead.
Note that event delivery is asynchronous, so the event may not actually be sent until
later; see flush()
.
eventName
- the name of the eventcontext
- the context associated with the eventtrackData(String, LDContext, LDValue)
,
trackMetric(String, LDContext, LDValue, double)
void trackData(java.lang.String eventName, LDContext context, LDValue data)
This method creates a "custom" analytics event containing the specified event name (key),
context properties, and optional data. If you do not need custom data, pass LDValue.ofNull()
for the last parameter or simply omit the parameter. You may attach a metric value to the event by
calling trackMetric(String, LDContext, LDValue, double)
instead.
Note that event delivery is asynchronous, so the event may not actually be sent until
later; see flush()
.
eventName
- the name of the eventcontext
- the context associated with the eventdata
- additional data associated with the event, if anytrack(String, LDContext)
,
trackMetric(String, LDContext, LDValue, double)
void trackMetric(java.lang.String eventName, LDContext context, LDValue data, double metricValue)
This value is used by the LaunchDarkly experimentation feature in numeric custom metrics, and will also be returned as part of the custom event for Data Export.
Note that event delivery is asynchronous, so the event may not actually be sent until
later; see flush()
.
eventName
- the name of the eventcontext
- the context associated with the eventdata
- an LDValue
containing additional data associated with the event; if not applicable,
you may pass either null
or LDValue.ofNull()
metricValue
- a numeric value used by the LaunchDarkly experimentation feature in numeric custom
metricstrack(String, LDContext)
,
trackData(String, LDContext, LDValue)
void trackMigration(MigrationOpTracker tracker)
tracker
- Migration tracker which was used to track details of the migration operation.void identify(LDContext context)
This method simply creates an analytics event containing the context properties, to that LaunchDarkly will know about that context if it does not already.
Calling any evaluation method, such as boolVariation(String, LDContext, boolean)
,
also sends the context information to LaunchDarkly (if events are enabled), so you only
need to use this method if you want to identify the context without evaluating a flag.
Note that event delivery is asynchronous, so the event may not actually be sent until
later; see flush()
.
context
- the context to registerFeatureFlagsState allFlagsState(LDContext context, FlagsStateOption... options)
The object returned by this method contains the flag values as well as other metadata that is used by the LaunchDarkly JavaScript client, so it can be used for bootstrapping.
This method will not send analytics events back to LaunchDarkly.
context
- the evaluation contextoptions
- 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()
boolean boolVariation(java.lang.String key, LDContext context, boolean defaultValue)
If the flag variation does not have a boolean value, defaultValue
is returned.
If an error makes it impossible to evaluate the flag (for instance, the feature flag key
does not match any existing flag), defaultValue
is returned.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagdefaultValue
if the flag cannot be evaluatedint intVariation(java.lang.String key, LDContext context, int defaultValue)
If the flag variation has a numeric value that is not an integer, it is rounded toward zero (truncated).
If the flag variation does not have a numeric value, defaultValue
is returned.
If an error makes it impossible to evaluate the flag (for instance, the feature flag key
does not match any existing flag), defaultValue
is returned.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagdefaultValue
if the flag cannot be evaluateddouble doubleVariation(java.lang.String key, LDContext context, double defaultValue)
If the flag variation does not have a numeric value, defaultValue
is returned.
If an error makes it impossible to evaluate the flag (for instance, the feature flag key
does not match any existing flag), defaultValue
is returned.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagdefaultValue
if the flag cannot be evaluatedjava.lang.String stringVariation(java.lang.String key, LDContext context, java.lang.String defaultValue)
If the flag variation does not have a string value, defaultValue
is returned.
If an error makes it impossible to evaluate the flag (for instance, the feature flag key
does not match any existing flag), defaultValue
is returned.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagdefaultValue
if the flag cannot be evaluatedLDValue jsonValueVariation(java.lang.String key, LDContext context, LDValue defaultValue)
The type LDValue
is used to represent any of the value types that can
exist in JSON. Use LDValue
methods to examine its type and value.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagdefaultValue
if the flag cannot be evaluatedEvaluationDetail<java.lang.Boolean> boolVariationDetail(java.lang.String key, LDContext context, boolean defaultValue)
The EvaluationDetail.getReason()
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.
The behavior is otherwise identical to boolVariation(String, LDContext, boolean)
.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagEvaluationDetail
objectEvaluationDetail<java.lang.Integer> intVariationDetail(java.lang.String key, LDContext context, int defaultValue)
The EvaluationDetail.getReason()
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.
The behavior is otherwise identical to intVariation(String, LDContext, int)
.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagEvaluationDetail
objectEvaluationDetail<java.lang.Double> doubleVariationDetail(java.lang.String key, LDContext context, double defaultValue)
The EvaluationDetail.getReason()
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.
The behavior is otherwise identical to doubleVariation(String, LDContext, double)
.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagEvaluationDetail
objectEvaluationDetail<java.lang.String> stringVariationDetail(java.lang.String key, LDContext context, java.lang.String defaultValue)
The EvaluationDetail.getReason()
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.
The behavior is otherwise identical to stringVariation(String, LDContext, String)
.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagEvaluationDetail
objectEvaluationDetail<LDValue> jsonValueVariationDetail(java.lang.String key, LDContext context, LDValue defaultValue)
The EvaluationDetail.getReason()
property in the result will also be included in
analytics events, if you are capturing detailed event data for this flag.
The behavior is otherwise identical to jsonValueVariation(String, LDContext, LDValue)
.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultValue
- the default value of the flagEvaluationDetail
objectMigrationVariation migrationVariation(java.lang.String key, LDContext context, MigrationStage defaultStage)
If the evaluated value of the flag cannot be converted to an LDMigrationStage, then the default value will be returned and error will be logged.
key
- the unique key for the feature flagcontext
- the evaluation contextdefaultStage
- the default stage of the migrationboolean isFlagKnown(java.lang.String featureKey)
featureKey
- the unique key for the feature flagvoid close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
java.io.IOException
- if an exception is thrown by one of the underlying network servicesvoid flush()
boolean isOffline()
FlagTracker getFlagTracker()
The FlagTracker
contains methods for requesting notifications about feature flag changes using
an event listener model.
FlagTracker
BigSegmentStoreStatusProvider getBigSegmentStoreStatusProvider()
The returned object has methods for checking whether the Big Segment store is (as far as the
SDK knows) currently operational and tracking changes in this status. See
BigSegmentStoreStatusProvider
for more about this functionality.
BigSegmentStoreStatusProvider
DataSourceStatusProvider getDataSourceStatusProvider()
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 DataSourceStatusProvider
has methods
for checking whether the data source is (as far as the SDK knows) currently operational and tracking
changes in this status.
DataSourceStatusProvider
DataStoreStatusProvider getDataStoreStatusProvider()
The DataStoreStatusProvider
has 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.
DataStoreStatusProvider
LDLogger getLogger()
This allows for access to the logger by other LaunchDarkly components, such as the Migration
class.
It also allows for usage of the logger in wrapper implementations.
It is not intended for general purpose application logging.
LDLogger
java.lang.String secureModeHash(LDContext context)
See Secure mode in the JavaScript SDK Reference.
context
- the evaluation contextjava.lang.String version()