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
Memory-based implementation of a Key/Value store.
- Since:
- 9.1
-
Field Summary
Modifier and TypeFieldDescriptionprotected final net.jodah.expiringmap.ExpiringMap<String,
byte[]> protected final Lock
Fields inherited from class org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
name, UTF_8_DECODERS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the content of this Key/Value store provider.protected static byte[]
clone
(byte[] value) void
close()
Closes this Key/Value store provider.boolean
compareAndSet
(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 void
byte[]
Retrieves the value associated to the key.Returns aStream
of the keys contained in this Key/Value store provider.Returns aStream
of the keys with the given prefix contained in this Key/Value store provider.void
Sets the value associated to the key, and a TTL.boolean
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
-
Field Details
-
map
-
writeLock
-
-
Constructor Details
-
MemKeyValueStore
public MemKeyValueStore()
-
-
Method Details
-
keyStream
Description copied from interface:KeyValueStoreProvider
Returns aStream
of 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
Description copied from interface:KeyValueStoreProvider
Returns aStream
of 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:KeyValueStoreProvider
Closes this Key/Value store provider. -
clear
public void clear()Description copied from interface:KeyValueStoreProvider
Clears the content of this Key/Value store provider. -
clone
protected static byte[] clone(byte[] value) -
put
Description copied from interface:KeyValueStore
Sets the value associated to the key, and a TTL.- Parameters:
key
- the keyvalue
- the value, which may benull
ttl
- the TTL, in seconds (0 for infinite)
-
get
Description copied from interface:KeyValueStore
Retrieves the value associated to the key.- Parameters:
key
- the key- Returns:
- the value, or
null
if there is no value
-
setTTL
Description copied from interface:KeyValueStore
Sets the TTL for an existing key.- Parameters:
key
- the keyttl
- the TTL, in seconds (0 for infinite)- Returns:
true
if the TTL has been set, orfalse
if the key does not exist
-
doSetTTL
-
compareAndSet
Description copied from interface:KeyValueStore
Atomically 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 benull
value
- the updated value, which may benull
ttl
- the TTL, in seconds (0 for infinite)- Returns:
true
if the value was updated, orfalse
if not (the expected value was not found)
-