public abstract class AbstractAsyncKeyValueStore<T> extends AbstractKeyValueStore<T>
KeyValueStore
to extend for implementations that do not otherwise have access to
async get/put operations.
This implementation wraps the synchronous get/put calls in a CompletableFuture
and executes them async.
This implementation attempts to process all requests async but may instead process synchronously depending on the executor implementation used. The default is to degrade to synchronous processing if the executor is full.
Modifier | Constructor and Description |
---|---|
protected |
AbstractAsyncKeyValueStore() |
protected |
AbstractAsyncKeyValueStore(Executor executor) |
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Void> |
deleteAsync(String key,
String context) |
CompletableFuture<Map<String,T>> |
enumerateContextAsync(String context) |
CompletableFuture<Optional<T>> |
getAsync(String key,
String context) |
CompletableFuture<Optional<Optional<T>>> |
getIfStaleAsync(String key,
String context,
long timestamp) |
CompletableFuture<OptionalLong> |
getLastUpdatedAsync(String key,
String context) |
CompletableFuture<Long> |
putAsync(String key,
T value,
String context,
Integer ttlInSeconds)
Put a value with a suggested time-to-live after which the value should be expired and removed from the store.
|
CompletableFuture<Void> |
truncateContextAsync(String context)
Remove all records for a given context.
|
put, putAsync, truncateContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
delete, enumerateContext, get, getIfStale, getLastUpdated, getName, put
protected AbstractAsyncKeyValueStore(Executor executor)
protected AbstractAsyncKeyValueStore()
public final CompletableFuture<Long> putAsync(String key, T value, String context, Integer ttlInSeconds)
KeyValueStore
Records are expired on a best effort basis and depending on the implementation it is possible to get an expired record.
context
- a context used to differentiate between keys with the same name (forms a compound key)ttlInSeconds
- the time to live in seconds for this key or no ttl if nullpublic final CompletableFuture<Optional<T>> getAsync(String key, String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)public final CompletableFuture<Optional<Optional<T>>> getIfStaleAsync(String key, String context, long timestamp)
context
- a context used to differentiate between keys with the same name (forms a compound key)timestamp
- the timestamp of the last known state such that if an record with a more recent timestamp is
found the provided timestamp will be considered stale and the new record will be returnedpublic final CompletableFuture<OptionalLong> getLastUpdatedAsync(String key, String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)public CompletableFuture<Map<String,T>> enumerateContextAsync(String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)public CompletableFuture<Void> deleteAsync(String key, String context)
context
- a context used to differentiate between keys with the same name (forms a compound key)public CompletableFuture<Void> truncateContextAsync(String context)
KeyValueStore
context
- a context used to differentiate between keys with the same name (forms a compound key)Copyright © 2020. All rights reserved.