Class InMemoryKeyValueStore
java.lang.Object
io.fluxcapacitor.javaclient.persisting.keyvalue.client.InMemoryKeyValueStore
- All Implemented Interfaces:
KeyValueClient
,AutoCloseable
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
deleteValue
(String key, Guarantee guarantee) Deletes the value associated with the given key.Data
<byte[]> Returns theData
object associated with the given key.Adds or replaces the given value in the key value store.putValueIfAbsent
(String key, Data<byte[]> value) Adds the given value in the key value store if the key is not already mapped to a value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.persisting.keyvalue.client.KeyValueClient
deleteValue
-
Constructor Details
-
InMemoryKeyValueStore
public InMemoryKeyValueStore() -
InMemoryKeyValueStore
-
-
Method Details
-
putValue
Description copied from interface:KeyValueClient
Adds or replaces the given value in the key value store.- Specified by:
putValue
in interfaceKeyValueClient
- Parameters:
key
- The key associated with this valuevalue
- The value to storeguarantee
- The guarantee for storing- Returns:
- a handle that enables clients to wait until the value was sent or stored depending on the guarantee
-
putValueIfAbsent
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 interfaceKeyValueClient
- Parameters:
key
- The key associated with this valuevalue
- The value to store- Returns:
- a handle that enables clients to wait until the value was sent or stored depending on the guarantee
-
getValue
Description copied from interface:KeyValueClient
Returns theData
object associated with the given key. Returnsnull
if there is no associated value.- Specified by:
getValue
in interfaceKeyValueClient
- Parameters:
key
- The key associated with the value- Returns:
- the value for the given key or null
-
deleteValue
Description copied from interface:KeyValueClient
Deletes the value associated with the given key.- Specified by:
deleteValue
in interfaceKeyValueClient
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceKeyValueClient
-