Class LDConfig.Builder

  • Enclosing class:
    LDConfig

    public static class LDConfig.Builder
    extends java.lang.Object
    A builder that helps construct LDConfig objects. Builder calls can be chained, enabling the following pattern:
     LDConfig config = new LDConfig.Builder()
              .mobileKey("mobile-key")
              .evaluationReasons(true)
              .build();
     
    • Constructor Detail

      • Builder

        public Builder()
    • Method Detail

      • mobileKey

        public LDConfig.Builder mobileKey​(java.lang.String 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

        public LDConfig.Builder secondaryMobileKeys​(java.util.Map<java.lang.String,​java.lang.String> 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
      • dataSource

        public LDConfig.Builder dataSource​(ComponentConfigurer<DataSource> dataSourceConfigurer)
        Sets the configuration of the component that receives feature flag data from LaunchDarkly.

        The default is Components.streamingDataSource(); you may instead use Components.pollingDataSource(). See those methods for details on how to configure them with options that are specific to streaming or polling mode.

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

        
             // 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:
        Components.streamingDataSource(), Components.pollingDataSource()
      • events

        public LDConfig.Builder events​(ComponentConfigurer<EventProcessor> eventsConfigurer)
        Sets the implementation of EventProcessor to be used for processing analytics events.

        The default is Components.sendEvents() with no custom options. You may instead call Components.sendEvents() and then set custom options for event processing; or, disable events with Components.noEvents(); or, choose to use a custom implementation (for instance, a test fixture).

        Setting offline(boolean) to true 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:
        Components.sendEvents(), Components.noEvents()
      • http

        public LDConfig.Builder http​(ComponentConfigurer<HttpConfiguration> httpConfigurer)
        Sets the SDK's networking configuration, using a configuration builder. This builder is obtained from Components.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:
        Components.httpConfiguration()
      • serviceEndpoints

        public LDConfig.Builder serviceEndpoints​(ServiceEndpointsBuilder serviceEndpointsBuilder)
        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 by Components.serviceEndpoints()
        Returns:
        the builder
        Since:
        3.3.0
      • disableBackgroundUpdating

        public LDConfig.Builder disableBackgroundUpdating​(boolean 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

        public LDConfig.Builder offline​(boolean 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
      • inlineUsersInEvents

        @Deprecated
        public LDConfig.Builder inlineUsersInEvents​(boolean inlineUsersInEvents)
        Deprecated method for specifying whether events sent to the server will always include the full user object.

        The preferred way to set this option now is with EventProcessorBuilder. Any settings there will override this deprecated method.

        This defaults to false in order to reduce network bandwidth.

        Parameters:
        inlineUsersInEvents - true if all user properties should be included in events
        Returns:
        the builder
      • evaluationReasons

        public LDConfig.Builder evaluationReasons​(boolean 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

        public LDConfig.Builder diagnosticOptOut​(boolean 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
      • maxCachedUsers

        public LDConfig.Builder maxCachedUsers​(int maxCachedUsers)
        Sets the maximum number of users to cache the flag values for locally in the device's SharedPreferences.

        Note that the active user is not considered part of this limit, as it will always be served from the backing SharedPreferences.

        Parameters:
        maxCachedUsers - The maximum number of users to cache, negative values represent allowing an unlimited number of cached users.
        Returns:
        the builder
      • autoAliasingOptOut

        public LDConfig.Builder autoAliasingOptOut​(boolean autoAliasingOptOut)
        Enable this opt-out to disable sending an automatic alias event when LDClient.identify(LDUser) is called with a non-anonymous user when the current user is anonymous.
        Parameters:
        autoAliasingOptOut - Whether the automatic aliasing feature should be disabled
        Returns:
        the builder
      • logLevel

        public LDConfig.Builder logLevel​(LDLogLevel 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 is LDLogLevel.INFO, meaning that INFO, WARN, and ERROR levels are enabled, but DEBUG is disabled. To enable DEBUG 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:
        logAdapter(LDLogAdapter), loggerName(String)
      • loggerName

        public LDConfig.Builder loggerName​(java.lang.String 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:
        logAdapter(LDLogAdapter), logLevel(LDLogLevel)
      • build

        public LDConfig build()
        Returns the configured LDConfig object.
        Returns:
        the configuration