Interface KeyValueStorage
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
public interface KeyValueStorage extends java.io.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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clear()
Deletes all keys and values from the storage.boolean
containsKey(byte[] key)
Whether the key-value storage contains the given key.java.util.Optional<byte[]>
get(byte[] key)
Retrieves the value associated with a given key.java.util.Set<byte[]>
getAllKeysThat(java.util.function.Predicate<byte[]> returnCondition)
Performs an evaluation against each key in the store, returning the set of entries that pass.long
removeAllKeysUnless(java.util.function.Predicate<byte[]> retainCondition)
Performs an evaluation against each key in the store, keeping the entries that pass, removing those that fail.KeyValueStorageTransaction
startTransaction()
Begins a fresh transaction, for sequencing operations for later atomic execution.
-
-
-
Method Detail
-
clear
void clear() throws StorageException
Deletes all keys and values from the storage.- Throws:
StorageException
- problem encountered when attempting to clear storage.
-
containsKey
boolean containsKey(byte[] key) throws StorageException
Whether the key-value storage contains the given key.- Parameters:
key
- a key that might be contained in the key-value storage.- Returns:
true
when the given key is present in keyset,false
otherwise.- Throws:
StorageException
- problem encountered when interacting with the key set.
-
get
java.util.Optional<byte[]> get(byte[] key) throws StorageException
Retrieves the value associated with a given key.- Parameters:
key
- whose associated value is being retrieved.- Returns:
- an
Optional
containing the value associated with the specified key, otherwise empty. - Throws:
StorageException
- problem encountered during the retrieval attempt.
-
removeAllKeysUnless
long removeAllKeysUnless(java.util.function.Predicate<byte[]> retainCondition) throws StorageException
Performs an evaluation against each key in the store, keeping the entries that pass, removing those that fail.- Parameters:
retainCondition
- predicate to evaluate each key against, unless the result isnull
, both the key and associated value must be removed.- Returns:
- the number of keys removed.
- Throws:
StorageException
- problem encountered when removing data.
-
getAllKeysThat
java.util.Set<byte[]> getAllKeysThat(java.util.function.Predicate<byte[]> returnCondition)
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.
-
startTransaction
KeyValueStorageTransaction startTransaction() throws StorageException
Begins a fresh transaction, for sequencing operations for later atomic execution.- Returns:
- transaciton to sequence key-value operations.
- Throws:
StorageException
- problem encountered when starting a new transaction.
-
-