Interface PersistentDataStore
-
public interface PersistentDataStore
Interface for a data store that holds feature flag data and other SDK properties in a simple string format.The SDK has a default implementation which uses the Android
SharedPreferences
API. A custom implementation of this interface could store data somewhere else, or use that API in a different way.Each data item is uniquely identified by the combination of a "namespace" and a "key", and has a string value. These are defined as follows:
- Both the namespace and the key are non-empty strings.
- Both the namespace and the key contain only alphanumeric characters, hyphens, and underscores.
- The value can be any non-null string, including an empty string.
The store implementation does not need to worry about adding a LaunchDarkly-specific prefix to namespaces to distinguish them from storage that is used for other purposes; the SDK will take care of that at a higher level. PersistentDataStore is just a low-level storage mechanism.
The SDK will also provide its own caching layer on top of the persistent data store; the data store implementation should not provide caching, but simply do every query or update that the SDK tells it to do.
Error handling is defined as follows: if any data store operation encounters an I/O error, or is otherwise unable to complete its task, it should throw an exception to make the SDK aware of this. The SDK will decide whether to log the exception.
- Since:
- 4.0.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clear(java.lang.String storeNamespace, boolean fullyDelete)
Removes any values that currently exist in the given namespace.java.util.Collection<java.lang.String>
getAllNamespaces()
Returns all namespaces that exist in the data store.java.util.Collection<java.lang.String>
getKeys(java.lang.String storeNamespace)
Returns all keys that exist in the namespace.java.lang.String
getValue(java.lang.String storeNamespace, java.lang.String key)
Attempts to retrieve a string value from the store.void
setValue(java.lang.String storeNamespace, java.lang.String key, java.lang.String value)
Attempts to update or remove a string value in the store.void
setValues(java.lang.String storeNamespace, java.util.Map<java.lang.String,java.lang.String> keysAndValues)
Attempts to update multiple values atomically.
-
-
-
Method Detail
-
getValue
java.lang.String getValue(java.lang.String storeNamespace, java.lang.String key)
Attempts to retrieve a string value from the store.- Parameters:
storeNamespace
- the namespace identifierkey
- the unique key within that namespace- Returns:
- the value, or null if not found
-
setValue
void setValue(java.lang.String storeNamespace, java.lang.String key, java.lang.String value)
Attempts to update or remove a string value in the store.- Parameters:
storeNamespace
- the namespace identifierkey
- the unique key within that namespacevalue
- the new value, or null to remove the key
-
setValues
void setValues(java.lang.String storeNamespace, java.util.Map<java.lang.String,java.lang.String> keysAndValues)
Attempts to update multiple values atomically.- Parameters:
storeNamespace
- the namespace identifierkeysAndValues
- the keys and values to update
-
getKeys
java.util.Collection<java.lang.String> getKeys(java.lang.String storeNamespace)
Returns all keys that exist in the namespace.- Parameters:
storeNamespace
- the namespace identifier- Returns:
- the keys
-
getAllNamespaces
java.util.Collection<java.lang.String> getAllNamespaces()
Returns all namespaces that exist in the data store.This may be an inefficient operation, but the SDK will not call this method on a regular basis. It is used only when migrating data from earlier SDK versions.
- Returns:
- the namespaces
-
clear
void clear(java.lang.String storeNamespace, boolean fullyDelete)
Removes any values that currently exist in the given namespace.- Parameters:
storeNamespace
- the namespace identifierfullyDelete
- true to purge all data structures related to the namespace, false to simply leave it empty
-
-