Package org.nuxeo.runtime.kv
Class MemKeyValueStore
- java.lang.Object
-
- org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
-
- org.nuxeo.runtime.kv.MemKeyValueStore
-
- All Implemented Interfaces:
KeyValueStore,KeyValueStoreProvider
public class MemKeyValueStore extends AbstractKeyValueStoreProvider
Memory-based implementation of a Key/Value store.- Since:
- 9.1
-
-
Field Summary
Fields Modifier and Type Field Description protected net.jodah.expiringmap.ExpiringMap<String,byte[]>mapprotected LockwriteLock-
Fields inherited from class org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
name, UTF_8_DECODERS
-
-
Constructor Summary
Constructors Constructor Description MemKeyValueStore()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the content of this Key/Value store provider.protected static byte[]clone(byte[] value)voidclose()Closes this Key/Value store provider.booleancompareAndSet(String key, byte[] expected, byte[] value, long ttl)Atomically sets the value associated to the key to the given value, with the given TTL, if the current value is the expected value.protected voiddoSetTTL(String key, long ttl)byte[]get(String key)Retrieves the value associated to the key.Stream<String>keyStream()Returns aStreamof the keys contained in this Key/Value store provider.Stream<String>keyStream(String prefix)Returns aStreamof the keys with the given prefix contained in this Key/Value store provider.voidput(String key, byte[] value, long ttl)Sets the value associated to the key, and a TTL.booleansetTTL(String key, long ttl)Sets the TTL for an existing key.-
Methods inherited from class org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
addAndGet, bytesToLong, bytesToString, compareAndSet, compareAndSet, compareAndSet, get, getLong, getLongs, getString, getStrings, initialize, longToBytes, put, put, put, put, put, stringToBytes, toString
-
-
-
-
Method Detail
-
keyStream
public Stream<String> keyStream()
Description copied from interface:KeyValueStoreProviderReturns aStreamof the keys contained in this Key/Value store provider.This operation may be slow and should only be used for management or debug purposes.
- Returns:
- the stream of keys
-
keyStream
public Stream<String> keyStream(String prefix)
Description copied from interface:KeyValueStoreProviderReturns aStreamof the keys with the given prefix contained in this Key/Value store provider.This operation may be slow and should only be used for management or debug purposes.
- Returns:
- the stream of keys
-
close
public void close()
Description copied from interface:KeyValueStoreProviderCloses this Key/Value store provider.
-
clear
public void clear()
Description copied from interface:KeyValueStoreProviderClears the content of this Key/Value store provider.
-
clone
protected static byte[] clone(byte[] value)
-
put
public void put(String key, byte[] value, long ttl)
Description copied from interface:KeyValueStoreSets the value associated to the key, and a TTL.- Parameters:
key- the keyvalue- the value, which may benullttl- the TTL, in seconds (0 for infinite)
-
get
public byte[] get(String key)
Description copied from interface:KeyValueStoreRetrieves the value associated to the key.- Parameters:
key- the key- Returns:
- the value, or
nullif there is no value
-
setTTL
public boolean setTTL(String key, long ttl)
Description copied from interface:KeyValueStoreSets the TTL for an existing key.- Parameters:
key- the keyttl- the TTL, in seconds (0 for infinite)- Returns:
trueif the TTL has been set, orfalseif the key does not exist
-
doSetTTL
protected void doSetTTL(String key, long ttl)
-
compareAndSet
public boolean compareAndSet(String key, byte[] expected, byte[] value, long ttl)
Description copied from interface:KeyValueStoreAtomically sets the value associated to the key to the given value, with the given TTL, if the current value is the expected value.Note value comparison is done by value and not by reference.
- Parameters:
key- the keyexpected- the expected value, which may benullvalue- the updated value, which may benullttl- the TTL, in seconds (0 for infinite)- Returns:
trueif the value was updated, orfalseif not (the expected value was not found)
-
-