Interface PersistentDataStore

All Superinterfaces:
java.lang.AutoCloseable, java.io.Closeable

public interface PersistentDataStore
extends java.io.Closeable
Interface for a data store that holds feature flags and related data in a serialized form.

This interface should be used for database integrations, or any other data store implementation that stores data in some external service. The SDK will take care of converting between its own internal data model and a serialized string form; the data store interacts only with the serialized form. 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.

Implementations must be thread-safe.

Conceptually, each item in the store is a DataStoreTypes.SerializedItemDescriptor which always has a version number, and can represent either a serialized object or a placeholder (tombstone) for a deleted item. There are two approaches a persistent store implementation can use for persisting this data:

1. Preferably, it should store the version number and the DataStoreTypes.SerializedItemDescriptor.isDeleted() state separately so that the object does not need to be fully deserialized to read them. In this case, deleted item placeholders can ignore the value of DataStoreTypes.SerializedItemDescriptor.getSerializedItem() on writes and can set it to null on reads. The store should never call DataStoreTypes.DataKind.deserialize(String) or DataStoreTypes.DataKind.serialize(DataStoreTypes.ItemDescriptor).

2. If that isn't possible, then the store should simply persist the exact string from DataStoreTypes.SerializedItemDescriptor.getSerializedItem() on writes, and return the persisted string on reads (returning zero for the version and false for DataStoreTypes.SerializedItemDescriptor.isDeleted()). The string is guaranteed to provide the SDK with enough information to infer the version and the deleted state. On updates, the store must call DataStoreTypes.DataKind.deserialize(String) in order to inspect the version number of the existing item if any.

Error handling is defined as follows: if any data store operation encounters a database error, or is otherwise unable to complete its task, it should throw a RuntimeException to make the SDK aware of this. The SDK will log the exception and will assume that the data store is now in a non-operational state; the SDK will then start polling isStoreAvailable() to determine when the store has started working again.

Since:
5.0.0