Class InMemoryKeyValueStore

java.lang.Object
io.fluxcapacitor.javaclient.persisting.keyvalue.client.InMemoryKeyValueStore
All Implemented Interfaces:
KeyValueClient, AutoCloseable

public class InMemoryKeyValueStore extends Object implements KeyValueClient
An in-memory implementation of the KeyValueClient interface. This class provides methods for storing, retrieving, and deleting key-value pairs in a local memory store.

It is thread-safe by utilizing a ConcurrentHashMap as an underlying data structure.

  • Constructor Details

    • InMemoryKeyValueStore

      public InMemoryKeyValueStore()
    • InMemoryKeyValueStore

      protected InMemoryKeyValueStore(Map<String,Data<byte[]>> map)
  • Method Details

    • putValue

      public CompletableFuture<Void> putValue(String key, Data<byte[]> value, Guarantee guarantee)
      Description copied from interface: KeyValueClient
      Adds or replaces the given value in the key value store.
      Specified by:
      putValue in interface KeyValueClient
      Parameters:
      key - The key associated with this value
      value - The value to store
      guarantee - The guarantee for storing
      Returns:
      a handle that enables clients to wait until the value was sent or stored depending on the guarantee
    • putValueIfAbsent

      public CompletableFuture<Boolean> putValueIfAbsent(String key, Data<byte[]> value)
      Description copied from interface: KeyValueClient
      Adds the given value in the key value store if the key is not already mapped to a value.
      Specified by:
      putValueIfAbsent in interface KeyValueClient
      Parameters:
      key - The key associated with this value
      value - The value to store
      Returns:
      a handle that enables clients to wait until the value was sent or stored depending on the guarantee
    • getValue

      public Data<byte[]> getValue(String key)
      Description copied from interface: KeyValueClient
      Returns the Data object associated with the given key. Returns null if there is no associated value.
      Specified by:
      getValue in interface KeyValueClient
      Parameters:
      key - The key associated with the value
      Returns:
      the value for the given key or null
    • deleteValue

      public CompletableFuture<Void> deleteValue(String key, Guarantee guarantee)
      Description copied from interface: KeyValueClient
      Deletes the value associated with the given key.
      Specified by:
      deleteValue in interface KeyValueClient
      Parameters:
      key - The key associated with this value
      Returns:
      a handle that enables clients to wait until the command was safely sent to the store
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface KeyValueClient