Interface DataStore

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

    public interface DataStore
    extends java.io.Closeable
    Interface for a data store that holds feature flags and 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, and the persistent data store implementation that delegates to a PersistentDataStore.

    All implementations must permit concurrent access and updates.

    Since:
    5.0.0
    • Method Detail

      • init

        void init​(DataStoreTypes.FullDataSet<DataStoreTypes.ItemDescriptor> allData)
        Overwrites the store's contents with a set of items for each collection.

        All previous data should be discarded, regardless of versioning.

        The update should be done atomically. If it cannot be done atomically, then the store must first add or update each item in the same order that they are given in the input data, and then delete any previously stored items that were not in the input data.

        Parameters:
        allData - a list of DataStoreTypes.DataKind instances and their corresponding data sets
      • get

        DataStoreTypes.ItemDescriptor get​(DataStoreTypes.DataKind kind,
                                          java.lang.String key)
        Retrieves an item from the specified collection, if available.

        If the item has been deleted and the store contains a placeholder, it should return that placeholder rather than null.

        Parameters:
        kind - specifies which collection to use
        key - the unique key of the item within that collection
        Returns:
        a versioned item that contains the stored data (or placeholder for deleted data); null if the key is unknown
      • getAll

        DataStoreTypes.KeyedItems<DataStoreTypes.ItemDescriptor> getAll​(DataStoreTypes.DataKind kind)
        Retrieves all items from the specified collection.

        If the store contains placeholders for deleted items, it should include them in the results, not filter them out.

        Parameters:
        kind - specifies which collection to use
        Returns:
        a collection of key-value pairs; the ordering is not significant
      • 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.

        The SDK may pass an DataStoreTypes.ItemDescriptor that contains a null, to represent a placeholder for a deleted item. In that case, assuming the version is greater than any existing version of that item, the store should retain that placeholder rather than simply not storing anything.

        Parameters:
        kind - specifies which collection to use
        key - the unique key for the item within that collection
        item - the item to insert or update
        Returns:
        true if the item was updated; false if it was not updated because the store contains an equal or greater version
      • isInitialized

        boolean isInitialized()
        Checks whether this store has been initialized with any data yet.
        Returns:
        true if the store contains data
      • isStatusMonitoringEnabled

        boolean isStatusMonitoringEnabled()
        Returns true if this data store implementation supports status monitoring.

        This is normally only true for persistent data stores created with Components.persistentDataStore(ComponentConfigurer), but it could also be true for any custom DataStore implementation that makes use of ClientContext.getDataStoreUpdateSink(). Returning true means that the store guarantees that if it ever enters an invalid state (that is, an operation has failed or it knows that operations cannot succeed at the moment), it will publish a status update, and will then publish another status update once it has returned to a valid state.

        The same value will be returned from DataStoreStatusProvider.isStatusMonitoringEnabled().

        Returns:
        true if status monitoring is enabled
      • getCacheStats

        DataStoreStatusProvider.CacheStats getCacheStats()
        Returns statistics about cache usage, if this data store implementation supports caching.
        Returns:
        a cache statistics object, or null if not applicable