public abstract class Components
extends java.lang.Object
Some of the configuration options in LDConfig.Builder
affect the entire SDK, but others are
specific to one area of functionality, such as how the SDK receives feature flag updates or processes
analytics events. For the latter, the standard way to specify a configuration is to call one of the
static methods in Components
(such as streamingDataSource()
), apply any desired
configuration change to the object that that method returns (such as StreamingDataSourceBuilder.initialReconnectDelay(java.time.Duration)
,
and then use the corresponding method in LDConfig.Builder
(such as LDConfig.Builder.dataSource(DataSourceFactory)
)
to use that configured component in the SDK.
Modifier and Type | Method and Description |
---|---|
static DataSourceFactory |
externalUpdatesOnly()
Returns a configuration object that disables a direct connection with LaunchDarkly for feature flag updates.
|
static HttpAuthentication |
httpBasicAuthentication(java.lang.String username,
java.lang.String password)
Configures HTTP basic authentication, for use with a proxy server.
|
static HttpConfigurationBuilder |
httpConfiguration()
Returns a configuration builder for the SDK's networking configuration.
|
static DataStoreFactory |
inMemoryDataStore()
Returns a configuration object for using the default in-memory implementation of a data store.
|
static LoggingConfigurationBuilder |
logging()
Returns a configuration builder for the SDK's logging configuration.
|
static EventProcessorFactory |
noEvents()
Returns a configuration object that disables analytics events.
|
static PersistentDataStoreBuilder |
persistentDataStore(PersistentDataStoreFactory storeFactory)
Returns a configuration builder for some implementation of a persistent data store.
|
static PollingDataSourceBuilder |
pollingDataSource()
Returns a configurable factory for using polling mode to get feature flag data.
|
static EventProcessorBuilder |
sendEvents()
Returns a configuration builder for analytics event delivery.
|
static StreamingDataSourceBuilder |
streamingDataSource()
Returns a configurable factory for using streaming mode to get feature flag data.
|
public static DataStoreFactory inMemoryDataStore()
Since it is the default, you do not normally need to call this method, unless you need to create a data store instance for testing purposes.
LDConfig.Builder.dataStore(DataStoreFactory)
public static PersistentDataStoreBuilder persistentDataStore(PersistentDataStoreFactory storeFactory)
This method is used in conjunction with another factory object provided by specific components
such as the Redis integration. The latter provides builder methods for options that are specific
to that integration, while the PersistentDataStoreBuilder
provides options that are
applicable to any persistent data store (such as caching). For example:
LDConfig config = new LDConfig.Builder()
.dataStore(
Components.persistentDataStore(
Redis.dataStore().url("redis://my-redis-host")
).cacheSeconds(15)
)
.build();
See PersistentDataStoreBuilder
for more on how this method is used.
For more information on the available persistent data store implementations, see the reference guide on Using a persistent feature store.
storeFactory
- the factory/builder for the specific kind of persistent data storePersistentDataStoreBuilder
LDConfig.Builder.dataStore(DataStoreFactory)
public static EventProcessorBuilder sendEvents()
The default configuration has events enabled with default settings. If you want to
customize this behavior, call this method to obtain a builder, change its properties
with the EventProcessorBuilder
properties, and pass it to LDConfig.Builder.events(EventProcessorFactory)
:
LDConfig config = new LDConfig.Builder()
.events(Components.sendEvents().capacity(5000).flushIntervalSeconds(2))
.build();
To completely disable sending analytics events, use noEvents()
instead.
Setting LDConfig.Builder.offline(boolean)
to true
will supersede this setting and completely
disable network requests.
noEvents()
,
LDConfig.Builder.events(com.launchdarkly.sdk.server.interfaces.EventProcessorFactory)
public static EventProcessorFactory noEvents()
Passing this to LDConfig.Builder.events(EventProcessorFactory)
causes the SDK
to discard all analytics events and not send them to LaunchDarkly, regardless of any other configuration.
LDConfig config = new LDConfig.Builder()
.events(Components.noEvents())
.build();
sendEvents()
,
LDConfig.Builder.events(EventProcessorFactory)
public static StreamingDataSourceBuilder streamingDataSource()
By default, the SDK uses a streaming connection to receive feature flag data from LaunchDarkly. To use the
default behavior, you do not need to call this method. However, if you want to customize the behavior of
the connection, call this method to obtain a builder, change its properties with the
StreamingDataSourceBuilder
methods, and pass it to LDConfig.Builder.dataSource(DataSourceFactory)
:
LDConfig config = new LDConfig.Builder()
.dataSource(Components.streamingDataSource().initialReconnectDelayMillis(500))
.build();
Setting LDConfig.Builder.offline(boolean)
to true
will supersede this setting and completely
disable network requests.
LDConfig.Builder.dataSource(DataSourceFactory)
public static PollingDataSourceBuilder pollingDataSource()
This is not the default behavior; by default, the SDK uses a streaming connection to receive feature flag data from LaunchDarkly. In polling mode, the SDK instead makes a new HTTP request to LaunchDarkly at regular intervals. HTTP caching allows it to avoid redundantly downloading data if there have been no changes, but polling is still less efficient than streaming and should only be used on the advice of LaunchDarkly support.
To use polling mode, call this method to obtain a builder, change its properties with the
PollingDataSourceBuilder
methods, and pass it to LDConfig.Builder.dataSource(DataSourceFactory)
:
LDConfig config = new LDConfig.Builder()
.dataSource(Components.pollingDataSource().pollIntervalMillis(45000))
.build();
Setting LDConfig.Builder.offline(boolean)
to true
will supersede this setting and completely
disable network requests.
LDConfig.Builder.dataSource(DataSourceFactory)
public static DataSourceFactory externalUpdatesOnly()
Passing this to LDConfig.Builder.dataSource(DataSourceFactory)
causes the SDK
not to retrieve feature flag data from LaunchDarkly, regardless of any other configuration.
This is normally done if you are using the Relay Proxy
in "daemon mode", where an external process-- the Relay Proxy-- connects to LaunchDarkly and populates
a persistent data store with the feature flag data. The data store could also be populated by
another process that is running the LaunchDarkly SDK. If there is no external process updating
the data store, then the SDK will not have any feature flag data and will return application
default values only.
LDConfig config = new LDConfig.Builder()
.dataSource(Components.externalUpdatesOnly())
.dataStore(Components.persistentDataStore(Redis.dataStore())) // assuming the Relay Proxy is using Redis
.build();
(Note that the interface is still named DataSourceFactory
, but in a future version it
will be renamed to DataSourceFactory
.)
LDConfig.Builder.dataSource(DataSourceFactory)
public static HttpConfigurationBuilder httpConfiguration()
Passing this to LDConfig.Builder.http(com.launchdarkly.sdk.server.interfaces.HttpConfigurationFactory)
applies this configuration to all HTTP/HTTPS requests made by the SDK.
LDConfig config = new LDConfig.Builder()
.http(
Components.httpConfiguration()
.connectTimeoutMillis(3000)
.proxyHostAndPort("my-proxy", 8080)
)
.build();
LDConfig.Builder.http(com.launchdarkly.sdk.server.interfaces.HttpConfigurationFactory)
public static HttpAuthentication httpBasicAuthentication(java.lang.String username, java.lang.String password)
LDConfig config = new LDConfig.Builder()
.http(
Components.httpConfiguration()
.proxyHostAndPort("my-proxy", 8080)
.proxyAuthentication(Components.httpBasicAuthentication("username", "password"))
)
.build();
username
- the usernamepassword
- the passwordHttpConfigurationBuilder.proxyAuth(HttpAuthentication)
public static LoggingConfigurationBuilder logging()
Passing this to LDConfig.Builder.logging(com.launchdarkly.sdk.server.interfaces.LoggingConfigurationFactory)
,
after setting any desired properties on the builder, applies this configuration to the SDK.
LDConfig config = new LDConfig.Builder()
.logging(
Components.logging()
.logDataSourceOutageAsErrorAfter(Duration.ofSeconds(120))
)
.build();
LDConfig.Builder.logging(com.launchdarkly.sdk.server.interfaces.LoggingConfigurationFactory)