Interface KeyValueStorage
- All Superinterfaces:
AutoCloseable, Closeable
Responsible for storing values against keys.
Behaviour expected with regard to key to value mapping is that of a map, one key maps to one value, when a new value is added with an existing key, that key now points at the new value.
All keys and values must be non-null.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Deletes all keys and values from the storage.booleancontainsKey(byte[] key) Whether the key-value storage contains the given key.Optional<byte[]> get(byte[] key) Retrieves the value associated with a given key.Set<byte[]> getAllKeysThat(Predicate<byte[]> returnCondition) Performs an evaluation against each key in the store, returning the set of entries that pass.Set<byte[]> getAllValuesFromKeysThat(Predicate<byte[]> returnCondition) Gets all values from keys that matches the predicate.booleanisClosed()Return Whether the underlying storage is closed.Begins a fresh transaction, for sequencing operations for later atomic execution.Stream<org.apache.commons.lang3.tuple.Pair<byte[], byte[]>> stream()Returns a stream of all keys and values.Stream<org.apache.commons.lang3.tuple.Pair<byte[], byte[]>> streamFromKey(byte[] startKey) Returns a stream of key-value pairs starting from the specified key.Stream<org.apache.commons.lang3.tuple.Pair<byte[], byte[]>> streamFromKey(byte[] startKey, byte[] endKey) Returns a stream of key-value pairs starting from the specified key, ending at the specified key.Stream<byte[]> Returns a stream of all keys.booleantryDelete(byte[] key) Delete the value corresponding to the given key if a write lock can be instantly acquired on the underlying storage.
-
Method Details
-
clear
Deletes all keys and values from the storage.- Throws:
StorageException- problem encountered when attempting to clear storage.
-
containsKey
Whether the key-value storage contains the given key.- Parameters:
key- a key that might be contained in the key-value storage.- Returns:
truewhen the given key is present in keyset,falseotherwise.- Throws:
StorageException- problem encountered when interacting with the key set.
-
get
Retrieves the value associated with a given key.- Parameters:
key- whose associated value is being retrieved.- Returns:
- an
Optionalcontaining the value associated with the specified key, otherwise empty. - Throws:
StorageException- problem encountered during the retrieval attempt.
-
stream
Returns a stream of all keys and values.- Returns:
- A stream of all keys and values in storage.
- Throws:
StorageException- problem encountered during the retrieval attempt.
-
streamFromKey
Returns a stream of key-value pairs starting from the specified key. This method is used to retrieve a stream of data from the storage, starting from the given key. If no data is available from the specified key onwards, an empty stream is returned.- Parameters:
startKey- The key from which the stream should start.- Returns:
- A stream of key-value pairs starting from the specified key.
- Throws:
StorageException- If an error occurs while accessing the storage.
-
streamFromKey
Stream<org.apache.commons.lang3.tuple.Pair<byte[],byte[]>> streamFromKey(byte[] startKey, byte[] endKey) Returns a stream of key-value pairs starting from the specified key, ending at the specified key. This method is used to retrieve a stream of data from the storage, starting from the given key. If no data is available from the specified key onwards, an empty stream is returned.- Parameters:
startKey- The key from which the stream should start.endKey- The key at which the stream should stop.- Returns:
- A stream of key-value pairs starting from the specified key.
-
streamKeys
Returns a stream of all keys.- Returns:
- A stream of all keys in storage.
- Throws:
StorageException- problem encountered during the retrieval attempt.
-
tryDelete
Delete the value corresponding to the given key if a write lock can be instantly acquired on the underlying storage. Do nothing otherwise.- Parameters:
key- The key to delete.- Returns:
- false if the lock on the underlying storage could not be instantly acquired, true otherwise
- Throws:
StorageException- any problem encountered during the deletion attempt.
-
getAllKeysThat
Performs an evaluation against each key in the store, returning the set of entries that pass.- Parameters:
returnCondition- predicate to evaluate each key against, unless the result isnull, the key is added to the returned list of keys.- Returns:
- the set of keys that pass the condition.
-
getAllValuesFromKeysThat
-
startTransaction
Begins a fresh transaction, for sequencing operations for later atomic execution.- Returns:
- transaction to sequence key-value operations.
- Throws:
StorageException- problem encountered when starting a new transaction.
-
isClosed
boolean isClosed()Return Whether the underlying storage is closed.- Returns:
- boolean indicating whether the storage is closed.
-