Class DefaultKeyValueStore

java.lang.Object
io.fluxzero.sdk.common.AbstractNamespaced<KeyValueStore>
io.fluxzero.sdk.persisting.keyvalue.DefaultKeyValueStore
All Implemented Interfaces:
Namespaced<KeyValueStore>, KeyValueStore

public class DefaultKeyValueStore extends AbstractNamespaced<KeyValueStore> implements KeyValueStore
The default implementation of the KeyValueStore interface that provides operations for storing, retrieving, and deleting key-value pairs using a KeyValueClient and a Serializer. This class handles serialization and deserialization of values and ensures that operations conform to the guarantees provided by the client.
  • Constructor Details

    • DefaultKeyValueStore

      public DefaultKeyValueStore(Client client, Serializer serializer)
  • Method Details

    • createForNamespace

      protected KeyValueStore createForNamespace(String namespace)
      Specified by:
      createForNamespace in class AbstractNamespaced<KeyValueStore>
    • store

      public CompletableFuture<Void> store(String key, Object value, Guarantee guarantee)
      Description copied from interface: KeyValueStore
      Stores a value under the given key with the specified delivery guarantee.
      Specified by:
      store in interface KeyValueStore
      Parameters:
      key - the key to store the value under
      value - the value to store
      guarantee - the delivery guarantee (DEFAULT, NONE, SENT, or STORED)
      Returns:
      completion according to the selected guarantee
    • storeIfAbsent

      public CompletableFuture<Boolean> storeIfAbsent(String key, Object value)
      Description copied from interface: KeyValueStore
      Stores a value only if there is no existing value for the specified key. This always requests a stored result; the application delivery default does not weaken the conditional operation.
      Specified by:
      storeIfAbsent in interface KeyValueStore
      Parameters:
      key - the key to store the value under
      value - the value to store
      Returns:
      a future with true if the value was stored, false if the key already had a value
    • get

      public <R> R get(String key)
      Description copied from interface: KeyValueStore
      Retrieves the value associated with the given key.
      Specified by:
      get in interface KeyValueStore
      Type Parameters:
      R - the expected result type
      Parameters:
      key - the key to retrieve
      Returns:
      the stored value, or null if not found
    • delete

      public CompletableFuture<Void> delete(String key, Guarantee guarantee)
      Description copied from interface: KeyValueStore
      Removes a value asynchronously with the specified delivery guarantee.
      Specified by:
      delete in interface KeyValueStore
      Parameters:
      key - the key to delete
      guarantee - concrete guarantee or DEFAULT
      Returns:
      completion according to the selected guarantee
    • withDefaultGuarantee

      public DefaultKeyValueStore withDefaultGuarantee(Guarantee guarantee)
      Configures the concrete application delivery default before first use; namespace stores inherit it.