Class Components

    • Method Detail

      • bigSegments

        public static BigSegmentsConfigurationBuilder bigSegments​(ComponentConfigurer<BigSegmentStore> storeConfigurer)
        Returns a configuration builder for the SDK's Big Segments feature.

        Big Segments are a specific type of user segments. For more information, read the LaunchDarkly documentation.

        After configuring this object, use LDConfig.Builder.bigSegments(ComponentConfigurer) to store it in your SDK configuration. For example, using the Redis integration:

        
             LDConfig config = new LDConfig.Builder()
                 .bigSegments(Components.bigSegments(Redis.dataStore().prefix("app1"))
                     .userCacheSize(2000))
                 .build();
         

        You must always specify the storeFactory parameter, to tell the SDK what database you are using. Several database integrations exist for the LaunchDarkly SDK, each with its own behavior and options specific to that database; this is described via some implementation of BigSegmentStore. The BigSegmentsConfigurationBuilder adds configuration options for aspects of SDK behavior that are independent of the database. In the example above, prefix is an option specifically for the Redis integration, whereas userCacheSize is an option that can be used for any data store type.

        Parameters:
        storeConfigurer - the factory for the underlying data store
        Returns:
        a BigSegmentsConfigurationBuilder
        Since:
        5.7.0
        See Also:
        bigSegments(ComponentConfigurer)
      • inMemoryDataStore

        public static ComponentConfigurer<DataStore> inMemoryDataStore()
        Returns a configuration object for using the default in-memory implementation of a data store.

        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.

        Returns:
        a factory object
        Since:
        4.12.0
        See Also:
        LDConfig.Builder.dataStore(ComponentConfigurer)
      • persistentDataStore

        public static PersistentDataStoreBuilder persistentDataStore​(ComponentConfigurer<PersistentDataStore> storeConfigurer)
        Returns a configuration builder for some implementation of a persistent data store.

        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.

        Parameters:
        storeConfigurer - the factory/builder for the specific kind of persistent data store
        Returns:
        a PersistentDataStoreBuilder
        Since:
        4.12.0
        See Also:
        LDConfig.Builder.dataStore(ComponentConfigurer)
      • sendEvents

        public static EventProcessorBuilder sendEvents()
        Returns a configuration builder for analytics event delivery.

        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(ComponentConfigurer):

        
             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.

        Returns:
        a builder for setting streaming connection properties
        Since:
        4.12.0
        See Also:
        noEvents(), LDConfig.Builder.events
      • streamingDataSource

        public static StreamingDataSourceBuilder streamingDataSource()
        Returns a configurable factory for using streaming mode to get feature flag data.

        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(ComponentConfigurer):

         
             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.

        Returns:
        a builder for setting streaming connection properties
        Since:
        4.12.0
        See Also:
        LDConfig.Builder.dataSource(ComponentConfigurer)
      • pollingDataSource

        public static PollingDataSourceBuilder pollingDataSource()
        Returns a configurable factory for using polling mode to get feature flag data.

        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(ComponentConfigurer):

        
             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.

        Returns:
        a builder for setting polling properties
        Since:
        4.12.0
        See Also:
        LDConfig.Builder.dataSource(ComponentConfigurer)
      • externalUpdatesOnly

        public static ComponentConfigurer<DataSource> externalUpdatesOnly()
        Returns a configuration object that disables a direct connection with LaunchDarkly for feature flag updates.

        Passing this to LDConfig.Builder.dataSource(ComponentConfigurer) 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();
         
        Returns:
        a factory object
        Since:
        4.12.0
        See Also:
        LDConfig.Builder.dataSource(ComponentConfigurer)
      • httpBasicAuthentication

        public static HttpAuthentication httpBasicAuthentication​(java.lang.String username,
                                                                 java.lang.String password)
        Configures HTTP basic authentication, for use with a proxy server.
        
             LDConfig config = new LDConfig.Builder()
                 .http(
                      Components.httpConfiguration()
                          .proxyHostAndPort("my-proxy", 8080)
                          .proxyAuthentication(Components.httpBasicAuthentication("username", "password"))
                 )
                 .build();
         
        Parameters:
        username - the username
        password - the password
        Returns:
        the basic authentication strategy
        Since:
        4.13.0
        See Also:
        HttpConfigurationBuilder.proxyAuth(HttpAuthentication)
      • logging

        public static LoggingConfigurationBuilder logging​(LDLogAdapter logAdapter)
        Returns a configuration builder for the SDK's logging configuration, specifying the implementation of logging to use.

        This is a shortcut for Components.logging().adapter(logAdapter). The com.launchdarkly.logging API defines the LDLogAdapter interface to specify where log output should be sent.

        The default logging destination, if no adapter is specified, depends on whether SLF4J is present in the classpath. If it is, then the SDK uses LDSLF4J.adapter(), causing output to go to SLF4J; what happens to the output then is determined by the SLF4J configuration. If SLF4J is not present in the classpath, the SDK uses Logs.toConsole() instead, causing output to go to the System.err stream.

        You may use the Logs factory methods, or a custom implementation, to handle log output differently. For instance, you may specify Logs.toJavaUtilLogging() to use the java.util.logging framework.

        Passing this to LDConfig.Builder.logging(ComponentConfigurer), after setting any desired properties on the builder, applies this configuration to the SDK.

        
             LDConfig config = new LDConfig.Builder()
                 .logging(
                      Components.logging(Logs.basic())
                 )
                 .build();
         
        Parameters:
        logAdapter - the log adapter
        Returns:
        a configuration builder
        Since:
        5.10.0
        See Also:
        LDConfig.Builder.logging(ComponentConfigurer), LoggingConfigurationBuilder.adapter(LDLogAdapter)
      • wrapperInfo

        public static WrapperInfoBuilder wrapperInfo()
        Returns a wrapper information builder.

        This is intended for use by LaunchDarkly in the development of wrapper SDKs.

        Returns:
        a builder object
        Since:
        7.1.0