Class CassandraBlobStore
- java.lang.Object
-
- org.opennms.features.distributed.kvstore.api.AbstractKeyValueStore<byte[]>
-
- org.opennms.features.distributed.kvstore.blob.cassandra.CassandraBlobStore
-
- All Implemented Interfaces:
BlobStore
,KeyValueStore<byte[]>
public class CassandraBlobStore extends AbstractKeyValueStore<byte[]> implements BlobStore
ABlobStore
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 asession factory
.
-
-
Constructor Summary
Constructors Constructor Description CassandraBlobStore(CassandraSessionFactory sessionFactory, CassandraSchemaManagerFactory cassandraSchemaManagerFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
delete(java.lang.String key, java.lang.String context)
java.util.concurrent.CompletableFuture<java.lang.Void>
deleteAsync(java.lang.String key, java.lang.String context)
java.util.Map<java.lang.String,byte[]>
enumerateContext(java.lang.String context)
java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,byte[]>>
enumerateContextAsync(java.lang.String context)
java.util.Optional<byte[]>
get(java.lang.String key, java.lang.String context)
java.util.concurrent.CompletableFuture<java.util.Optional<byte[]>>
getAsync(java.lang.String key, java.lang.String context)
java.util.Optional<java.util.Optional<byte[]>>
getIfStale(java.lang.String key, java.lang.String context, long timestamp)
java.util.concurrent.CompletableFuture<java.util.Optional<java.util.Optional<byte[]>>>
getIfStaleAsync(java.lang.String key, java.lang.String context, long timestamp)
java.util.OptionalLong
getLastUpdated(java.lang.String key, java.lang.String context)
java.util.concurrent.CompletableFuture<java.util.OptionalLong>
getLastUpdatedAsync(java.lang.String key, java.lang.String context)
java.lang.String
getName()
long
put(java.lang.String key, byte[] 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.Long>
putAsync(java.lang.String key, byte[] 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 org.opennms.features.distributed.kvstore.api.AbstractKeyValueStore
put, putAsync, truncateContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.opennms.features.distributed.kvstore.api.KeyValueStore
put, putAsync, truncateContext
-
-
-
-
Constructor Detail
-
CassandraBlobStore
public CassandraBlobStore(CassandraSessionFactory sessionFactory, CassandraSchemaManagerFactory cassandraSchemaManagerFactory) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
put
public long put(java.lang.String key, byte[] 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.
- Specified by:
put
in interfaceKeyValueStore<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 java.util.Optional<byte[]> get(java.lang.String key, java.lang.String context)
- Specified by:
get
in interfaceKeyValueStore<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 java.util.concurrent.CompletableFuture<java.lang.Long> putAsync(java.lang.String key, byte[] 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.
- Specified by:
putAsync
in interfaceKeyValueStore<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 java.util.concurrent.CompletableFuture<java.util.Optional<byte[]>> getAsync(java.lang.String key, java.lang.String context)
- Specified by:
getAsync
in interfaceKeyValueStore<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 java.util.Optional<java.util.Optional<byte[]>> getIfStale(java.lang.String key, java.lang.String context, long timestamp)
- Specified by:
getIfStale
in interfaceKeyValueStore<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 java.util.OptionalLong getLastUpdated(java.lang.String key, java.lang.String context)
- Specified by:
getLastUpdated
in interfaceKeyValueStore<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 java.util.concurrent.CompletableFuture<java.util.Optional<java.util.Optional<byte[]>>> getIfStaleAsync(java.lang.String key, java.lang.String context, long timestamp)
- Specified by:
getIfStaleAsync
in interfaceKeyValueStore<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 java.util.concurrent.CompletableFuture<java.util.OptionalLong> getLastUpdatedAsync(java.lang.String key, java.lang.String context)
- Specified by:
getLastUpdatedAsync
in interfaceKeyValueStore<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 java.util.Map<java.lang.String,byte[]> enumerateContext(java.lang.String context)
- Specified by:
enumerateContext
in interfaceKeyValueStore<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(java.lang.String key, java.lang.String context)
- Specified by:
delete
in interfaceKeyValueStore<byte[]>
context
- a context used to differentiate between keys with the same name (forms a compound key)
-
enumerateContextAsync
public java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,byte[]>> enumerateContextAsync(java.lang.String context)
- Specified by:
enumerateContextAsync
in interfaceKeyValueStore<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 java.util.concurrent.CompletableFuture<java.lang.Void> deleteAsync(java.lang.String key, java.lang.String context)
- Specified by:
deleteAsync
in interfaceKeyValueStore<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 java.util.concurrent.CompletableFuture<java.lang.Void> truncateContextAsync(java.lang.String context)
Description copied from interface:KeyValueStore
Remove all records for a given context.- Specified by:
truncateContextAsync
in interfaceKeyValueStore<byte[]>
- Parameters:
context
- a context used to differentiate between keys with the same name (forms a compound key)
-
getName
public java.lang.String getName()
- Specified by:
getName
in interfaceKeyValueStore<byte[]>
- Returns:
- the name of the backing implementation
-
-