Interface DataSourceUpdateSink
-
public interface DataSourceUpdateSink
Interface that a data source implementation will use to push data into the SDK.The data source interacts with this object, rather than manipulating the data store directly, so that the SDK can perform any other necessary operations that must happen when data is updated.
- Since:
- 5.0.0
- See Also:
ClientContext.getDataSourceUpdateSink()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description DataStoreStatusProvider
getDataStoreStatusProvider()
Returns an object that provides status tracking for the data store, if applicable.boolean
init(DataStoreTypes.FullDataSet<DataStoreTypes.ItemDescriptor> allData)
Completely overwrites the current contents of the data store with a set of items for each collection.void
updateStatus(DataSourceStatusProvider.State newState, DataSourceStatusProvider.ErrorInfo newError)
Informs the SDK of a change in the data source's status.boolean
upsert(DataStoreTypes.DataKind kind, java.lang.String key, DataStoreTypes.ItemDescriptor item)
Updates or inserts an item in the specified collection.
-
-
-
Method Detail
-
init
boolean init(DataStoreTypes.FullDataSet<DataStoreTypes.ItemDescriptor> allData)
Completely overwrites the current contents of the data store with a set of items for each collection.If the underlying data store throws an error during this operation, the SDK will catch it, log it, and set the data source state to
DataSourceStatusProvider.State.INTERRUPTED
with an error ofDataSourceStatusProvider.ErrorKind.STORE_ERROR
. It will not rethrow the error to the data source, but will simply returnfalse
to indicate that the operation failed.- Parameters:
allData
- a list ofDataStoreTypes.DataKind
instances and their corresponding data sets- Returns:
- true if the update succeeded, false if it failed
-
upsert
boolean upsert(DataStoreTypes.DataKind kind, java.lang.String key, DataStoreTypes.ItemDescriptor item)
Updates or inserts an item in the specified collection. For updates, the object will only be updated if the existing version is less than the new version.To mark an item as deleted, pass an
DataStoreTypes.ItemDescriptor
that contains a null, with a version number (you may useDataStoreTypes.ItemDescriptor.deletedItem(int)
). Deletions must be versioned so that they do not overwrite a later update in case updates are received out of order.If the underlying data store throws an error during this operation, the SDK will catch it, log it, and set the data source state to
DataSourceStatusProvider.State.INTERRUPTED
with an error ofDataSourceStatusProvider.ErrorKind.STORE_ERROR
. It will not rethrow the error to the data source, but will simply returnfalse
to indicate that the operation failed.- Parameters:
kind
- specifies which collection to usekey
- the unique key for the item within that collectionitem
- the item to insert or update- Returns:
- true if the update succeeded, false if it failed
-
getDataStoreStatusProvider
DataStoreStatusProvider getDataStoreStatusProvider()
Returns an object that provides status tracking for the data store, if applicable.This may be useful if the data source needs to be aware of storage problems that might require it to take some special action: for instance, if a database outage may have caused some data to be lost and therefore the data should be re-requested from LaunchDarkly.
- Returns:
- a
DataStoreStatusProvider
-
updateStatus
void updateStatus(DataSourceStatusProvider.State newState, DataSourceStatusProvider.ErrorInfo newError)
Informs the SDK of a change in the data source's status.Data source implementations should use this method if they have any concept of being in a valid state, a temporarily disconnected state, or a permanently stopped state.
If
newState
is different from the previous state, and/ornewError
is non-null, the SDK will start returning the new status (adding a timestamp for the change) fromDataSourceStatusProvider.getStatus()
, and will trigger status change events to any registered listeners.A special case is that if
newState
isDataSourceStatusProvider.State.INTERRUPTED
, but the previous state wasDataSourceStatusProvider.State.INITIALIZING
, the state will remain atDataSourceStatusProvider.State.INITIALIZING
becauseDataSourceStatusProvider.State.INTERRUPTED
is only meaningful after a successful startup.- Parameters:
newState
- the data source statenewError
- information about a new error, if any- See Also:
DataSourceStatusProvider
-
-