Interface DataSource
-
public interface DataSource
Interface for an object that receives updates to feature flags from LaunchDarkly.This component uses a push model. When it is created, the SDK will provide a reference to a
DataSourceUpdateSink
component (as part ofClientContext
, which is a write-only abstraction of the SDK state. The SDK never requests feature flag data from theDataSource
-- it only looks at the last known data that was pushed into the state.Each
LDClient
instance maintains exactly one active data source instance. It stops and discards the active data source whenever it needs to create a new one due to a significant state change, such as if the evaluation context is changed withidentify()
, or if the SDK goes online after previously being offline, or if the foreground/background state changes.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default boolean
needsRefresh(boolean newInBackground, LDContext newEvaluationContext)
The SDK calls this method to determine whether it needs to stop the current data source and start a new one after a state transition.void
start(Callback<java.lang.Boolean> resultCallback)
Initializes the data source.void
stop(Callback<java.lang.Void> completionCallback)
Tells the data source to stop.
-
-
-
Method Detail
-
start
void start(@NonNull Callback<java.lang.Boolean> resultCallback)
Initializes the data source. This is called only once per instance.- Parameters:
resultCallback
- called when the data source has successfully acquired the initial data, or if an error has occurred
-
stop
void stop(@NonNull Callback<java.lang.Void> completionCallback)
Tells the data source to stop.- Parameters:
completionCallback
- called once it has completely stopped (this is allowed to be asynchronous because it might involve network operations that can't be done on the main thread)
-
needsRefresh
default boolean needsRefresh(boolean newInBackground, LDContext newEvaluationContext)
The SDK calls this method to determine whether it needs to stop the current data source and start a new one after a state transition.State transitions include going from foreground to background or vice versa, or changing the evaluation context. The SDK will not call this method unless at least one of those types of transitions has happened.
If this method returns true, the SDK considers the current data source to be no longer valid, stops it, and asks the ComponentConfigurer to create a new one.
If this method returns false, the SDK retains the current data source.
- Parameters:
newInBackground
- true if the application is now in the backgroundnewEvaluationContext
- the new evaluation context- Returns:
- true if the data source should be recreated
- Since:
- 4.1.0
-
-