Class DataSystemBuilder
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
The data system is organized around connection modes. Each
mode has a data pipeline consisting of initializers (one-shot data loads)
and synchronizers (ongoing data updates). The SDK automatically transitions
between modes based on platform state (foreground/background, network availability).
Quick start — use defaults:
LDConfig config = new LDConfig.Builder(AutoEnvAttributes.Enabled)
.mobileKey("my-key")
.dataSystem(Components.dataSystem())
.build();
Custom mode pipelines — background polling 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();
Change the foreground mode to polling:
Components.dataSystem()
.foregroundConnectionMode(ConnectionMode.POLLING)
Disable automatic mode switching:
Components.dataSystem()
.automaticModeSwitching(AutomaticModeSwitchingConfig.disabled())
.foregroundConnectionMode(ConnectionMode.STREAMING)
When automatic mode switching is disabled, the SDK stays in the
foreground connection mode and does not react to
platform state changes (foreground/background, network availability). This can be
useful when you want full control over which mode the SDK uses.
Granular automatic mode switching — disable switching on lifecycle change, keep switching on network availability change:
Components.dataSystem()
.automaticModeSwitching(
DataSystemComponents.automaticModeSwitching()
.lifecycle(false)
.network(true)
.build())
Obtain an instance from Components.dataSystem().
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConfigures automatic mode switching based on platform state.Sets the connection mode used when the application is in the background.buildModeTable(boolean disableBackgroundUpdating) Builds the full mode table by starting with defaults and applying any user overrides and LDConfig-level settings.customizeConnectionMode(ConnectionMode mode, ConnectionModeBuilder builder) Overrides the data pipeline for a specific connection mode.Sets the connection mode used when the application is in the foreground.Returns the automatic mode switching configuration.Returns the configured background connection mode.Returns any user-specified mode overrides.Returns the configured foreground connection mode.
-
Constructor Details
-
DataSystemBuilder
public DataSystemBuilder()
-
-
Method Details
-
foregroundConnectionMode
Sets the connection mode used when the application is in the foreground.This determines which entry in the mode table is used when the SDK resolves the foreground platform state. For instance, setting this to
ConnectionMode.POLLINGmeans the SDK will use the polling mode pipeline when the app is in the foreground.The default is
ConnectionMode.STREAMING.- Parameters:
mode- the foreground connection mode- Returns:
- this builder
-
backgroundConnectionMode
Sets the connection mode used when the application is in the background.The default is
ConnectionMode.BACKGROUND.- Parameters:
mode- the background connection mode- Returns:
- this builder
-
automaticModeSwitching
Configures automatic mode switching based on platform state.Automatic mode switching controls whether the SDK reacts to application lifecycle events (foreground/background) and network availability changes by transitioning between connection modes. Lifecycle and network switching can be controlled independently via
DataSystemComponents.automaticModeSwitching().The default is
AutomaticModeSwitchingConfig.enabled(), meaning the SDK reacts to both lifecycle and network events.Use
AutomaticModeSwitchingConfig.disabled()to disable all automatic switching. When disabled, the SDK stays in theforeground connection modefor its entire lifecycle.Example — disable lifecycle switching but keep network switching:
Components.dataSystem() .automaticModeSwitching( DataSystemComponents.automaticModeSwitching() .lifecycle(false) .network(true) .build())- Parameters:
config- the automatic mode switching configuration- Returns:
- this builder
- See Also:
-
customizeConnectionMode
public DataSystemBuilder customizeConnectionMode(@NonNull ConnectionMode mode, @NonNull ConnectionModeBuilder builder) Overrides the data pipeline for a specific connection mode.This only affects the specified mode. All other connection modes that are not customized continue to use their default pipelines. For example, customizing
ConnectionMode.BACKGROUNDdoes not change the behavior ofConnectionMode.STREAMINGor any other mode.Example — set background polling to once every 6 hours:
Components.dataSystem() .customizeConnectionMode(ConnectionMode.BACKGROUND, DataSystemComponents.customMode() .initializers(DataSystemComponents.pollingInitializer()) .synchronizers( DataSystemComponents.pollingSynchronizer() .pollIntervalMillis(21_600_000)))- Parameters:
mode- the connection mode to customizebuilder- the pipeline configuration for this mode- Returns:
- this builder
-
getForegroundConnectionMode
Returns the configured foreground connection mode.- Returns:
- the foreground connection mode
-
getBackgroundConnectionMode
Returns the configured background connection mode.- Returns:
- the background connection mode
-
getAutomaticModeSwitchingConfig
Returns the automatic mode switching configuration.- Returns:
- the automatic mode switching config
-
getConnectionModeOverrides
Returns any user-specified mode overrides.- Returns:
- an unmodifiable map of overridden connection modes
-
buildModeTable
@NonNull public Map<ConnectionMode,ModeDefinition> buildModeTable(boolean disableBackgroundUpdating) Builds the full mode table by starting with defaults and applying any user overrides and LDConfig-level settings.If
disableBackgroundUpdatingis true, the background mode entry is replaced with an empty pipeline (no initializers or synchronizers).- Parameters:
disableBackgroundUpdating- whether background updates are disabled- Returns:
- the complete mode table
-