Class CassandraBlobStore

  • All Implemented Interfaces:
    BlobStore, KeyValueStore<byte[]>

    public class CassandraBlobStore
    extends AbstractKeyValueStore<byte[]>
    implements BlobStore
    A BlobStore that is backed by Cassandra.

    This implementation persists values that implement Serializable by using vanilla Java serialization.

    This implementation persists key values in a specific table that will be created in a keyspace dictated by the schema manager.

    This implementation does not initiate its own Cassandra session and must be provided with one via a session factory.

    • Method Detail

      • put

        public long put​(String key,
                        byte[] value,
                        String context,
                        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.

        Specified by:
        put in interface KeyValueStore<byte[]>
        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:
        the timestamp the value was persisted with
      • get

        public Optional<byte[]> get​(String key,
                                    String context)
        Specified by:
        get in interface KeyValueStore<byte[]>
        context - a context used to differentiate between keys with the same name (forms a compound key)
        Returns:
        an optional containing the value if present or empty if the key did not exist
      • putAsync

        public CompletableFuture<Long> putAsync​(String key,
                                                byte[] value,
                                                String context,
                                                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.

        Specified by:
        putAsync in interface KeyValueStore<byte[]>
        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 CompletableFuture<Optional<byte[]>> getAsync​(String key,
                                                            String context)
        Specified by:
        getAsync in interface KeyValueStore<byte[]>
        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
      • getIfStale

        public Optional<Optional<byte[]>> getIfStale​(String key,
                                                     String context,
                                                     long timestamp)
        Specified by:
        getIfStale in interface KeyValueStore<byte[]>
        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:
        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
      • getLastUpdated

        public OptionalLong getLastUpdated​(String key,
                                           String context)
        Specified by:
        getLastUpdated in interface KeyValueStore<byte[]>
        context - a context used to differentiate between keys with the same name (forms a compound key)
        Returns:
        an optional containing the timestamp the key's value was last updated or empty if the key did not exist
      • getIfStaleAsync

        public CompletableFuture<Optional<Optional<byte[]>>> getIfStaleAsync​(String key,
                                                                             String context,
                                                                             long timestamp)
        Specified by:
        getIfStaleAsync in interface KeyValueStore<byte[]>
        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 CompletableFuture<OptionalLong> getLastUpdatedAsync​(String key,
                                                                   String context)
        Specified by:
        getLastUpdatedAsync in interface KeyValueStore<byte[]>
        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
      • enumerateContext

        public Map<String,​byte[]> enumerateContext​(String context)
        Specified by:
        enumerateContext in interface KeyValueStore<byte[]>
        Parameters:
        context - a context used to differentiate between keys with the same name (forms a compound key)
        Returns:
        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
      • delete

        public void delete​(String key,
                           String context)
        Specified by:
        delete in interface KeyValueStore<byte[]>
        context - a context used to differentiate between keys with the same name (forms a compound key)
      • enumerateContextAsync

        public CompletableFuture<Map<String,​byte[]>> enumerateContextAsync​(String context)
        Specified by:
        enumerateContextAsync in interface KeyValueStore<byte[]>
        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 CompletableFuture<Void> deleteAsync​(String key,
                                                   String context)
        Specified by:
        deleteAsync in interface KeyValueStore<byte[]>
        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 CompletableFuture<Void> truncateContextAsync​(String context)
        Description copied from interface: KeyValueStore
        Remove all records for a given context.
        Specified by:
        truncateContextAsync in interface KeyValueStore<byte[]>
        Parameters:
        context - a context used to differentiate between keys with the same name (forms a compound key)
      • getName

        public String getName()
        Specified by:
        getName in interface KeyValueStore<byte[]>
        Returns:
        the name of the backing implementation