Class AbstractAsyncKeyValueStore<T>

  • All Implemented Interfaces:
    KeyValueStore<T>
    Direct Known Subclasses:
    AbstractPostgresKeyValueStore, InMemoryMapBlobStore, NoOpBlobStore, NoOpJsonStore

    public abstract class AbstractAsyncKeyValueStore<T>
    extends AbstractKeyValueStore<T>
    An implementation of 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.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.Void> deleteAsync​(java.lang.String key, java.lang.String context)  
      java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​T>> enumerateContextAsync​(java.lang.String context)  
      java.util.concurrent.CompletableFuture<java.util.Optional<T>> getAsync​(java.lang.String key, java.lang.String context)  
      java.util.concurrent.CompletableFuture<java.util.Optional<java.util.Optional<T>>> getIfStaleAsync​(java.lang.String key, java.lang.String context, long timestamp)  
      java.util.concurrent.CompletableFuture<java.util.OptionalLong> getLastUpdatedAsync​(java.lang.String key, java.lang.String context)  
      java.util.concurrent.CompletableFuture<java.lang.Long> putAsync​(java.lang.String key, T value, java.lang.String context, java.lang.Integer ttlInSeconds)
      Put a value with a suggested time-to-live after which the value should be expired and removed from the store.
      java.util.concurrent.CompletableFuture<java.lang.Void> truncateContextAsync​(java.lang.String context)
      Remove all records for a given context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractAsyncKeyValueStore

        protected AbstractAsyncKeyValueStore​(java.util.concurrent.Executor executor)
      • AbstractAsyncKeyValueStore

        protected AbstractAsyncKeyValueStore()
    • Method Detail

      • putAsync

        public final java.util.concurrent.CompletableFuture<java.lang.Long> putAsync​(java.lang.String key,
                                                                                     T value,
                                                                                     java.lang.String context,
                                                                                     java.lang.Integer ttlInSeconds)
        Description copied from interface: KeyValueStore
        Put a value with a suggested time-to-live after which the value should be expired and removed from the store.

        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 null
        Returns:
        a future containing the timestamp the value was persisted with
      • getAsync

        public final java.util.concurrent.CompletableFuture<java.util.Optional<T>> getAsync​(java.lang.String key,
                                                                                            java.lang.String context)
        context - a context used to differentiate between keys with the same name (forms a compound key)
        Returns:
        a future containing an optional of the value if present or empty if the key did not exist
      • getIfStaleAsync

        public final java.util.concurrent.CompletableFuture<java.util.Optional<java.util.Optional<T>>> getIfStaleAsync​(java.lang.String key,
                                                                                                                       java.lang.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 returned
        Returns:
        a future containing an optional that will be empty if the key was not found or will contain another optional that will be empty if not stale or contain the value if stale
      • getLastUpdatedAsync

        public final java.util.concurrent.CompletableFuture<java.util.OptionalLong> getLastUpdatedAsync​(java.lang.String key,
                                                                                                        java.lang.String context)
        context - a context used to differentiate between keys with the same name (forms a compound key)
        Returns:
        a future containing an optional of the the timestamp the key's value was last updated or empty if the key did not exist
      • enumerateContextAsync

        public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,​T>> enumerateContextAsync​(java.lang.String context)
        Parameters:
        context - a context used to differentiate between keys with the same name (forms a compound key)
        Returns:
        a future containing a map of all the records matching the given context where the map's key is the record's key and the map's value is the records value
      • deleteAsync

        public java.util.concurrent.CompletableFuture<java.lang.Void> deleteAsync​(java.lang.String key,
                                                                                  java.lang.String context)
        context - a context used to differentiate between keys with the same name (forms a compound key)
        Returns:
        a future that is completed when the delete has finished
      • truncateContextAsync

        public java.util.concurrent.CompletableFuture<java.lang.Void> truncateContextAsync​(java.lang.String context)
        Description copied from interface: KeyValueStore
        Remove all records for a given context.
        Parameters:
        context - a context used to differentiate between keys with the same name (forms a compound key)