Class InMemoryKeyValueStore
java.lang.Object
io.fluxzero.sdk.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 TypeMethodDescriptionvoidclose()deleteValue(String key, Guarantee guarantee) Deletes the value associated with the given key.Data<byte[]> Returns theDataobject 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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface KeyValueClient
deleteValue
-
Constructor Details
-
InMemoryKeyValueStore
public InMemoryKeyValueStore() -
InMemoryKeyValueStore
-
-
Method Details
-
putValue
Description copied from interface:KeyValueClientAdds or replaces the given value in the key value store.- Specified by:
putValuein 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:KeyValueClientAdds the given value in the key value store if the key is not already mapped to a value.- Specified by:
putValueIfAbsentin 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:KeyValueClientReturns theDataobject associated with the given key. Returnsnullif there is no associated value.- Specified by:
getValuein interfaceKeyValueClient- Parameters:
key- The key associated with the value- Returns:
- the value for the given key or null
-
deleteValue
Description copied from interface:KeyValueClientDeletes the value associated with the given key.- Specified by:
deleteValuein 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceKeyValueClient
-