Package co.featbit.server.exterior
Interface DataStorage
- All Superinterfaces:
AutoCloseable,Closeable
Interface for a data storage that holds feature flags, user segments or any other related data received by the SDK.
Ordinarily, the only implementations of this interface are the default in-memory implementation, which holds references to actual SDK data model objects.
All implementations should permit concurrent access and updates.
-
Method Summary
Modifier and TypeMethodDescriptionget(DataStoreTypes.Category category, String key) Retrieves an item from the specified collection, if available.getAll(DataStoreTypes.Category category) Retrieves all items from the specified collection.longreturn the latest version of storagevoidinit(Map<DataStoreTypes.Category, Map<String, DataStoreTypes.Item>> allData, Long version) Overwrites the storage with a set of items for each collection, if the new version > the old onebooleanChecks whether this store has been initialized with any data yet.booleanupsert(DataStoreTypes.Category category, String key, DataStoreTypes.Item item, Long version) Updates or inserts an item in the specified collection.
-
Method Details
-
init
Overwrites the storage with a set of items for each collection, if the new version > the old one- Parameters:
allData- map ofDataStoreTypes.Categoryand their data setDataStoreTypes.Itemversion- the version of dataset, Ordinarily it's a timestamp.
-
get
Retrieves an item from the specified collection, if available.If the item has been achieved and the store contains an achieved placeholder, but it should return null
- Parameters:
category- specifies which collection to usekey- the unique key of the item in the collection- Returns:
- a versioned item that contains the stored data or null if item is deleted or unknown
-
getAll
Retrieves all items from the specified collection.If the store contains placeholders for deleted items, it should filter them in the results.
- Parameters:
category- specifies which collection to use- Returns:
- a map of ids and their versioned items
-
upsert
boolean upsert(DataStoreTypes.Category category, String key, DataStoreTypes.Item item, Long version) 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; for inserts, if the version > the existing one, it will replace the existing one.The SDK may pass an
DataStoreTypes.Itemthat contains an archived object, In that case, assuming the version is greater than any existing version of that item, the store should retain a placeholder rather than simply not storing anything.- Parameters:
category- specifies which collection to usekey- the unique key of the item in the collectionitem- the item to insert or updateversion- the version of item- Returns:
- true if success
-
isInitialized
boolean isInitialized()Checks whether this store has been initialized with any data yet.- Returns:
- true if the storage contains data
-
getVersion
long getVersion()return the latest version of storage- Returns:
- a long value
-