Class LDConfig.Builder
- Enclosing class:
- LDConfig
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enable / disable options for Auto Environment Attributes functionality. -
Constructor Summary
ConstructorDescriptionBuilder
(LDConfig.Builder.AutoEnvAttributes autoEnvAttributes) LDConfig.Builder constructor. -
Method Summary
Modifier and TypeMethodDescriptionapplicationInfo
(ApplicationInfoBuilder applicationInfoBuilder) Sets the SDK's application metadata, which may be used in LaunchDarkly analytics or other product features, but does not affect feature flag evaluations.build()
Returns the configuredLDConfig
object.dataSource
(ComponentConfigurer<DataSource> dataSourceConfigurer) Sets the configuration of the component that receives feature flag data from LaunchDarkly.diagnosticOptOut
(boolean diagnosticOptOut) Set to true to opt out of sending diagnostics data.disableBackgroundUpdating
(boolean disableBackgroundUpdating) Sets whether feature flag updates should be disabled when your app is in the background.evaluationReasons
(boolean evaluationReasons) If enabled, LaunchDarkly will provide additional information about how flag values were calculated.events
(ComponentConfigurer<EventProcessor> eventsConfigurer) Sets the implementation ofEventProcessor
to be used for processing analytics events.generateAnonymousKeys
(boolean generateAnonymousKeys) Set totrue
to make the SDK provide unique keys for anonymous contexts.http
(ComponentConfigurer<HttpConfiguration> httpConfigurer) Sets the SDK's networking configuration, using a configuration builder.logAdapter
(LDLogAdapter logAdapter) Specifies the implementation of logging to use.loggerName
(String loggerName) Specifies a custom logger name/tag for the SDK.logLevel
(LDLogLevel logLevel) Specifies the lowest level of logging to enable.maxCachedContexts
(int maxCachedContexts) Sets the maximum number of evaluation contexts to cache the flag values for locally in the device's SharedPreferences.Sets the key for authenticating with LaunchDarkly.offline
(boolean offline) Disables all network calls from the LaunchDarkly client.secondaryMobileKeys
(Map<String, String> secondaryMobileKeys) Sets the secondary keys for authenticating to additional LaunchDarkly environments.serviceEndpoints
(ServiceEndpointsBuilder serviceEndpointsBuilder) Sets the base service URIs used by SDK components.
-
Constructor Details
-
Builder
LDConfig.Builder constructor. Configurable values are all set to their default values. The client app can modify these values as desired.- Parameters:
autoEnvAttributes
- - Enable / disable Auto Environment Attributes functionality. When enabled, the SDK will automatically provide data about the mobile environment where the application is running. This data makes it simpler to target your mobile customers based on application name or version, or on device characteristics including manufacturer, model, operating system, locale, and so on. We recommend enabling this when you configure the SDK. See TKTK for more documentation.
-
-
Method Details
-
mobileKey
Sets the key for authenticating with LaunchDarkly. This is required unless you're using the client in offline mode.- Parameters:
mobileKey
- Get this from the LaunchDarkly web app under Team Settings.- Returns:
- the builder
-
secondaryMobileKeys
Sets the secondary keys for authenticating to additional LaunchDarkly environments.- Parameters:
secondaryMobileKeys
- A map of identifying names to unique mobile keys to access secondary environments- Returns:
- the builder
-
serviceEndpoints
Sets the base service URIs used by SDK components.This object is a configuration builder obtained from
Components.serviceEndpoints()
, which has methods for setting each external endpoint to a custom URI.LDConfig config = new LDConfig.Builder().mobileKey("key") .serviceEndpoints( Components.serviceEndpoints().relayProxy("http://my-relay-proxy-host") );
- Parameters:
serviceEndpointsBuilder
- a configuration builder object returned byComponents.serviceEndpoints()
- Returns:
- the builder
- Since:
- 4.0.0
-
applicationInfo
Sets the SDK's application metadata, which may be used in LaunchDarkly analytics or other product features, but does not affect feature flag evaluations.This object is normally a configuration builder obtained from
Components.applicationInfo()
, which has methods for setting individual metadata properties.- Parameters:
applicationInfoBuilder
- a configuration builder object returned byComponents.applicationInfo()
- Returns:
- the builder
- Since:
- 4.1.0
-
dataSource
Sets the configuration of the component that receives feature flag data from LaunchDarkly.The default is
Components.streamingDataSource()
; you may instead useComponents.pollingDataSource()
, or a test fixture such asTestData
. SeeComponents.streamingDataSource()
andComponents.pollingDataSource()
for details on how to configure them with options that are specific to streaming or polling mode.Setting
offline(boolean)
totrue
will supersede this setting and completely disable all data sources.// Setting custom options when using streaming mode LDConfig config = new LDConfig.Builder() .dataSource( Components.streamingDataSource() .initialReconnectDelayMillis(100) ) .build(); // Using polling mode instead of streaming, and setting custom options for polling LDConfig config = new LDConfig.Builder() .dataSource( Components.pollingDataSource() .pollingIntervalMillis(60_000) ) .build();
- Parameters:
dataSourceConfigurer
- the data source configuration builder- Returns:
- the main configuration builder
- Since:
- 3.3.0
- See Also:
-
events
Sets the implementation ofEventProcessor
to be used for processing analytics events.The default is
Components.sendEvents()
with no custom options. You may instead callComponents.sendEvents()
and then set custom options for event processing; or, disable events withComponents.noEvents()
; or, choose to use a custom implementation (for instance, a test fixture).Setting
offline(boolean)
totrue
will supersede this setting and completely disable network requests.// Setting custom event processing options LDConfig config = new LDConfig.Builder() .events(Components.sendEvents().capacity(100)) .build(); // Disabling events LDConfig config = new LDConfig.Builder() .events(Components.noEvents()) .build();
- Parameters:
eventsConfigurer
- the events configuration builder- Returns:
- the main configuration builder
- Since:
- 3.3.0
- See Also:
-
http
Sets the SDK's networking configuration, using a configuration builder. This builder is obtained fromComponents.httpConfiguration()
, and has methods for setting individual HTTP-related properties.LDConfig config = new LDConfig.Builder() .http(Components.httpConfiguration().connectTimeoutMillis(5000)) .build();
- Parameters:
httpConfigurer
- the HTTP configuration builder- Returns:
- the main configuration builder
- Since:
- 3.3.0
- See Also:
-
disableBackgroundUpdating
Sets whether feature flag updates should be disabled when your app is in the background.The default value is false (flag updates will be done in the background).
- Parameters:
disableBackgroundUpdating
- true if the client should skip updating flags when in the background- Returns:
- the builder
-
offline
Disables all network calls from the LaunchDarkly client.This can also be specified after the client has been created, using
LDClientInterface.setOffline()
.The default value is true (the client will make network calls).
- Parameters:
offline
- true if the client should run in offline mode- Returns:
- the builder
-
evaluationReasons
If enabled, LaunchDarkly will provide additional information about how flag values were calculated. The additional information will then be available through the client's "detail" methods (LDClientInterface.boolVariationDetail(String, boolean)
, etc.). Since this increases the size of network requests, the default is false (detail information will not be sent).- Parameters:
evaluationReasons
- true if detail/reason information should be made available- Returns:
- the builder
-
diagnosticOptOut
Set to true to opt out of sending diagnostics data. Unless the diagnosticOptOut field is set to true, the client will send some diagnostics data to the LaunchDarkly servers in order to assist in the development of future SDK improvements. These diagnostics consist of an initial payload containing some details of SDK in use, the SDK's configuration, and the platform the SDK is being run on; as well as payloads sent periodically with information on irregular occurrences such as dropped events.- Parameters:
diagnosticOptOut
- true if you want to opt out of sending any diagnostics data.- Returns:
- the builder
-
maxCachedContexts
Sets the maximum number of evaluation contexts to cache the flag values for locally in the device's SharedPreferences.Note that the active evaluation context is not considered part of this limit, as it will always be served from the backing SharedPreferences.
If not specified, the default is
LDConfig.DEFAULT_MAX_CACHED_CONTEXTS
(5).- Parameters:
maxCachedContexts
- The maximum number of evaluation contexts to cache; negative values represent allowing an unlimited number of cached contexts- Returns:
- the builder
-
generateAnonymousKeys
Set totrue
to make the SDK provide unique keys for anonymous contexts.If enabled, this option changes the SDK's behavior whenever the
LDContext
(as given to methods likeLDClient.init(android.app.Application, LDConfig, LDContext, int)
orLDClient.identify(LDContext)
) has anLDContext.isAnonymous()
property oftrue
, as follows:- The first time this happens in the application, the SDK will generate a
pseudo-random GUID and overwrite the context's
key
with this string. - The SDK will then cache this key so that the same key will be reused next time.
- This uses the same persistent storage (shared preferences) mechanism as the caching of flag values, so that the key can persist across restarts.
If you use multiple
ContextKind
s, this behavior is per-kind: that is, a separate randomized key is generated and cached for each context kind.Every
LDContext
must always have a key, even if the key will later be overwritten by the SDK, so if you use this functionality you must still provide a placeholder key. This ensures that if the SDK configuration is changed sogenerateAnonymousKeys
is no longer enabled, the SDK will still be able to use the context for evaluations.- Parameters:
generateAnonymousKeys
- true to enable automatic anonymous key generation- Returns:
- the same builder
- Since:
- 4.0.0
- The first time this happens in the application, the SDK will generate a
pseudo-random GUID and overwrite the context's
-
logAdapter
Specifies the implementation of logging to use.The
com.launchdarkly.logging
API defines theLDLogAdapter
interface to specify where log output should be sent. By default, it is set toLDTimberLogging.adapter()
, meaning that output will be sent to the Timber framework and controlled by whatever Timber configuration the application has created. You may change this toLDAndroidLogging.adapter()
to bypass Timber and use Android native logging directly; or, use theLogs
factory methods, or a custom implementation, to handle log output differently.Specifying
logAdapter(Logs.none())
completely disables log output.For more about logging adapters, see the SDK reference guide and the API documentation for
com.launchdarkly.logging
.- Parameters:
logAdapter
- anLDLogAdapter
for the desired logging implementation- Returns:
- the builder
- Since:
- 3.2.0
- See Also:
-
logLevel
Specifies the lowest level of logging to enable.This is only applicable when using an implementation of logging that does not have its own external filter/configuration mechanism, such as
LDAndroidLogging
. It adds a log level filter so that log messages at lower levels are suppressed. The default isLDLogLevel.INFO
, meaning thatINFO
,WARN
, andERROR
levels are enabled, butDEBUG
is disabled. To enableDEBUG
level as well:LDConfig config = new LDConfig.Builder() .logAdapter(LDAndroidLogging.adapter()) .level(LDLogLevel.DEBUG) .build();
Or, to raise the logging threshold so that only WARN and ERROR levels are enabled, and DEBUG and INFO are disabled:
LDConfig config = new LDConfig.Builder() .logAdapter(LDAndroidLogging.adapter()) .level(LDLogLevel.WARN) .build();
When using
LDTimberLogging
, Timber has its own mechanism for determining whether to enable debug-level logging, so this method has no effect.- Parameters:
logLevel
- the lowest level of logging to enable- Returns:
- the builder
- Since:
- 3.2.0
- See Also:
-
loggerName
Specifies a custom logger name/tag for the SDK.When using Timber or native Android logging, this becomes the tag for all SDK log output. If you have specified a different logging implementation with
logAdapter(LDLogAdapter)
, the meaning of the logger name depends on the logging framework.If not specified, the default is "LaunchDarklySdk".
- Parameters:
loggerName
- the logger name or tag- Returns:
- the builder
- Since:
- 3.2.0
- See Also:
-
build
Returns the configuredLDConfig
object.- Returns:
- the configuration
-