Class Components

java.lang.Object
com.launchdarkly.sdk.android.Components

public abstract class Components extends Object
Provides configurable factories for the standard implementations of LaunchDarkly component interfaces.

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, apply any desired configuration change to the object that that method returns, and then use the corresponding method in LDConfig.Builder to use that configured component in the SDK.

Since:
3.3.0
  • Method Details

    • applicationInfo

      public static ApplicationInfoBuilder applicationInfo()
      Returns a configuration builder for the SDK's application metadata.

      Passing this to LDConfig.Builder.applicationInfo(com.launchdarkly.sdk.android.integrations.ApplicationInfoBuilder), after setting any desired properties on the builder, applies this configuration to the SDK.

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .applicationInfo(
                   Components.applicationInfo()
                       .applicationId("authentication-service")
                       .applicationVersion("1.0.0")
               )
               .build();
       
      Returns:
      a builder object
      Since:
      4.1.0
      See Also:
    • httpConfiguration

      public static HttpConfigurationBuilder httpConfiguration()
      Returns a configuration builder for the SDK's networking configuration.

      Passing this to LDConfig.Builder.http(ComponentConfigurer) applies this configuration to all HTTP/HTTPS requests made by the SDK.

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .http(
                    Components.httpConfiguration()
                        .connectTimeoutMillis(3000)
                        .proxyHostAndPort("my-proxy", 8080)
               )
               .build();
       
      Returns:
      a factory object
      See Also:
    • noEvents

      public static ComponentConfigurer<EventProcessor> noEvents()
      Returns a configuration object that disables analytics events.

      Passing this to LDConfig.Builder.events(ComponentConfigurer) causes the SDK to discard all analytics events and not send them to LaunchDarkly, regardless of any other configuration.

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .events(Components.noEvents())
               .build();
       
      Returns:
      a configuration object
      See Also:
    • pollingDataSource

      public static PollingDataSourceBuilder pollingDataSource()
      Returns a configuration builder for using polling 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 PollingDataSourceBuilder methods, and pass it to LDConfig.Builder.dataSource(ComponentConfigurer):

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .dataSource(Components.pollingDataSource().pollIntervalMillis(900_000))
               .build();
       

      Setting LDConfig.Builder.offline(boolean) to true will supersede this setting and completely disable network requests.

      Returns:
      a builder for setting polling connection properties
      See Also:
    • 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(AutoEnvAttributes.Enabled)
               .events(Components.sendEvents().capacity(500).flushIntervalMillis(2000))
               .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 event-related options
      See Also:
    • serviceEndpoints

      public static ServiceEndpointsBuilder serviceEndpoints()
      Returns a builder for configuring custom service URIs.

      Passing this to LDConfig.Builder.serviceEndpoints(com.launchdarkly.sdk.android.integrations.ServiceEndpointsBuilder), after setting any desired properties on the builder, applies this configuration to the SDK.

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .serviceEndpoints(
                   Components.serviceEndpoints()
                       .relayProxy("http://my-relay-hostname:80")
               )
               .build();
       
      Returns:
      a builder object
      See Also:
    • streamingDataSource

      public static StreamingDataSourceBuilder streamingDataSource()
      Returns a configuration builder 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(AutoEnvAttributes.Enabled)
               .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
      See Also:
    • hooks

      public static HooksConfigurationBuilder hooks()
      Returns a builder for configuring hooks. Passing this to LDConfig.Builder.hooks(com.launchdarkly.sdk.android.integrations.HooksConfigurationBuilder), after setting any desired hooks on the builder, applies this configuration to the SDK.
      
           List hooks = myCreateHooksFunc();
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .hooks(
                   Components.hooks()
                       .setHooks(hooks)
               )
               .build();
       
      Returns:
      a HooksConfigurationBuilder that can be used for customization
    • plugins

      public static PluginsConfigurationBuilder plugins()
      Returns a builder for configuring plugins. Passing this to LDConfig.Builder.plugins(com.launchdarkly.sdk.android.integrations.PluginsConfigurationBuilder), after setting any desired plugins on the builder, applies this configuration to the SDK.
      
           List plugins = getPluginsFunc();
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .plugins(
                   Components.plugins()
                       .setPlugins(plugins)
               )
               .build();
       
      Returns:
      a PluginsConfigurationBuilder for plugins configuration
    • dataSystem

      public static DataSystemBuilder dataSystem()
      Returns a builder for configuring the data system.

      The data system controls how the SDK acquires and maintains feature flag data across different platform states (foreground, background, offline). It uses connection modes, each with its own pipeline of initializers and synchronizers.

      When called with no further customization, the data system uses sensible defaults: streaming with polling fallback in the foreground and low-frequency polling in the background.

      This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is in early access. If you want access to this feature please join the EAP. https://launchdarkly.com/docs/sdk/features/data-saving-mode

      Example — opting in to use the default data system:

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .mobileKey("my-key")
               .dataSystem(Components.dataSystem())
               .build();
       

      Example — customize background polling to once every 6 hours:

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .mobileKey("my-key")
               .dataSystem(
                   Components.dataSystem()
                       .customizeConnectionMode(ConnectionMode.BACKGROUND,
                           DataSystemComponents.customMode()
                               .initializers(DataSystemComponents.pollingInitializer())
                               .synchronizers(
                                   DataSystemComponents.pollingSynchronizer()
                                       .pollIntervalMillis(21_600_000))))
               .build();
       

      Example — use polling instead of streaming in the foreground:

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .mobileKey("my-key")
               .dataSystem(
                   Components.dataSystem()
                       .foregroundConnectionMode(ConnectionMode.POLLING))
               .build();
       

      Example — disable automatic mode switching:

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .mobileKey("my-key")
               .dataSystem(
                   Components.dataSystem()
                       .automaticModeSwitching(AutomaticModeSwitchingConfig.disabled())
                       .foregroundConnectionMode(ConnectionMode.STREAMING))
               .build();
       

      Example — disable lifecycle switching but keep network switching:

      
           LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
               .mobileKey("my-key")
               .dataSystem(
                   Components.dataSystem()
                       .automaticModeSwitching(
                           DataSystemComponents.automaticModeSwitching()
                               .lifecycle(false)
                               .network(true)
                               .build()))
               .build();
       

      Setting LDConfig.Builder.dataSystem(DataSystemBuilder) is mutually exclusive with LDConfig.Builder.dataSource(ComponentConfigurer). The data system uses the FDv2 protocol, while dataSource() uses the legacy FDv1 protocol.

      Returns:
      a builder for configuring the data system
      See Also: