Interface DataSource
This component uses a push model. When it is created, the SDK will provide a reference to a
DataSourceUpdateSink
component (as part of ClientContext
, which is a write-only
abstraction of the SDK state. The SDK never requests feature flag data from the
DataSource
-- 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 with identify()
, or if the SDK goes
online after previously being offline, or if the foreground/background state changes.
-
Method Summary
Modifier and TypeMethodDescriptiondefault 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
Initializes the data source.void
Tells the data source to stop.
-
Method Details
-
start
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
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
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
-