Interface DataStorage

All Superinterfaces:
AutoCloseable, Closeable

public interface DataStorage extends 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 Details

    • init

      Overwrites the storage with a set of items for each collection, if the new version > the old one

      Parameters:
      allData - map of DataStoreTypes.Category and their data set DataStoreTypes.Item
      version - 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 use
      key - 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.Item that 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 use
      key - the unique key of the item in the collection
      item - the item to insert or update
      version - 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