Class PollingDataSourceBuilder

  • All Implemented Interfaces:
    DataSourceFactory

    public abstract class PollingDataSourceBuilder
    extends java.lang.Object
    implements DataSourceFactory
    Contains methods for configuring the polling data source.

    Polling 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, create a builder with Components.pollingDataSource(), change its properties with the methods of this class, and pass it to LDConfig.Builder.dataSource(DataSourceFactory):

    
         LDConfig config = new LDConfig.Builder()
             .dataSource(Components.pollingDataSource().pollInterval(Duration.ofSeconds(45)))
             .build();
     

    Note that this class is abstract; the actual implementation is created by calling Components.pollingDataSource().

    Since:
    4.12.0
    • Field Detail

      • DEFAULT_POLL_INTERVAL

        public static final java.time.Duration DEFAULT_POLL_INTERVAL
        The default and minimum value for pollInterval(Duration): 30 seconds.
      • baseURI

        protected java.net.URI baseURI
      • pollInterval

        protected java.time.Duration pollInterval
    • Constructor Detail

      • PollingDataSourceBuilder

        public PollingDataSourceBuilder()
    • Method Detail

      • baseURI

        public PollingDataSourceBuilder baseURI​(java.net.URI baseURI)
        Sets a custom base URI for the polling service.

        You will only need to change this value in the following cases:

        • You are using the Relay Proxy. Set streamUri to the base URI of the Relay Proxy instance.
        • You are connecting to a test server or anything else other than the standard LaunchDarkly service.
        Parameters:
        baseURI - the base URI of the polling service; null to use the default
        Returns:
        the builder
      • pollInterval

        public PollingDataSourceBuilder pollInterval​(java.time.Duration pollInterval)
        Sets the interval at which the SDK will poll for feature flag updates.

        The default and minimum value is DEFAULT_POLL_INTERVAL. Values less than this will be set to the default.

        Parameters:
        pollInterval - the polling interval; null to use the default
        Returns:
        the builder