public abstract class AbstractKeyValueStoreProvider extends Object implements KeyValueStoreProvider
| Modifier and Type | Field and Description |
|---|---|
protected String |
name |
protected static ThreadLocal<CharsetDecoder> |
UTF_8_DECODERS |
| Constructor and Description |
|---|
AbstractKeyValueStoreProvider() |
| Modifier and Type | Method and Description |
|---|---|
long |
addAndGet(String key,
long delta)
Atomically adds the delta to the value associated to the key, interpreted as a long represented as a string.
|
protected static Long |
bytesToLong(byte[] bytes)
Converts UTF-8 bytes to a Long, or throws if malformed.
|
protected static String |
bytesToString(byte[] bytes)
Converts UTF-8 bytes to a String, or throws if malformed.
|
boolean |
compareAndSet(String key,
byte[] expected,
byte[] value)
Atomically sets the value associated to the key to the given value if the current value is the expected value.
|
boolean |
compareAndSet(String key,
String expected,
String value)
Atomically sets the value associated to the key to the given value if the current value is the expected value.
|
boolean |
compareAndSet(String key,
String expected,
String 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.
|
Map<String,byte[]> |
get(Collection<String> keys)
Retrieves the key/value map associated with the keys.
|
Long |
getLong(String key)
Retrieves the value associated to the key.
|
Map<String,Long> |
getLongs(Collection<String> keys)
Retrieves the key/value map associated with the keys.
|
String |
getString(String key)
Retrieves the value associated to the key.
|
Map<String,String> |
getStrings(Collection<String> keys)
Retrieves the key/value map associated with the keys.
|
void |
initialize(KeyValueStoreDescriptor descriptor)
Initializes this Key/Value store provider.
|
protected static byte[] |
longToBytes(Long value)
Converts a long to UTF-8 bytes.
|
void |
put(String key,
byte[] value)
Sets the value associated to the key.
|
void |
put(String key,
Long value)
Sets the value associated to the key.
|
void |
put(String key,
Long value,
long ttl)
Sets the value associated to the key.
|
void |
put(String key,
String value)
Sets the value associated to the key.
|
void |
put(String key,
String value,
long ttl)
Sets the value associated to the key, and a TTL.
|
protected static byte[] |
stringToBytes(String string)
Converts a String to UTF-8 bytes.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitclear, close, keyStream, keyStreamcompareAndSet, get, put, setTTLprotected static final ThreadLocal<CharsetDecoder> UTF_8_DECODERS
public AbstractKeyValueStoreProvider()
public void initialize(KeyValueStoreDescriptor descriptor)
KeyValueStoreProviderinitialize in interface KeyValueStoreProviderdescriptor - the store provider descriptorprotected static String bytesToString(byte[] bytes) throws CharacterCodingException
CharacterCodingExceptionprotected static byte[] stringToBytes(String string)
protected static Long bytesToLong(byte[] bytes) throws NumberFormatException
NumberFormatExceptionprotected static byte[] longToBytes(Long value)
public void put(String key, byte[] value)
KeyValueStoreput in interface KeyValueStorekey - the keyvalue - the value, which may be nullpublic void put(String key, String value)
KeyValueStoreput in interface KeyValueStorekey - the keyvalue - the value, which may be nullpublic void put(String key, String value, long ttl)
KeyValueStoreput in interface KeyValueStorekey - the keyvalue - the value, which may be nullttl - the TTL, in seconds (0 for infinite)public void put(String key, Long value)
KeyValueStoreput in interface KeyValueStorekey - the keyvalue - the value, which may be nullpublic void put(String key, Long value, long ttl)
KeyValueStoreput in interface KeyValueStorekey - the keyvalue - the value, which may be nullttl - the TTL, in seconds (0 for infinite)public String getString(String key)
KeyValueStoregetString in interface KeyValueStorekey - the keynull if there is no valuepublic Long getLong(String key) throws NumberFormatException
KeyValueStoregetLong in interface KeyValueStorekey - the keynull if there is no valueNumberFormatException - if the value cannot be returned as a Longpublic Map<String,byte[]> get(Collection<String> keys)
KeyValueStoreget in interface KeyValueStorekeys - the keyspublic Map<String,String> getStrings(Collection<String> keys)
KeyValueStoregetStrings in interface KeyValueStorekeys - the keyspublic Map<String,Long> getLongs(Collection<String> keys) throws NumberFormatException
KeyValueStoregetLongs in interface KeyValueStorekeys - the keysNumberFormatException - if one of the values cannot be returned as a Longpublic boolean compareAndSet(String key, byte[] expected, byte[] value)
KeyValueStoreNote value comparison is done by value and not by reference.
compareAndSet in interface KeyValueStorekey - the keyexpected - the expected value, which may be nullvalue - the updated value, which may be nulltrue if the value was updated, or false if not (the expected value was not found)public boolean compareAndSet(String key, String expected, String value)
KeyValueStoreNote value comparison is done by value and not by reference.
compareAndSet in interface KeyValueStorekey - the keyexpected - the expected value, which may be nullvalue - the updated value, which may be nulltrue if the value was updated, or false if not (the expected value was not found)public boolean compareAndSet(String key, String expected, String value, long ttl)
KeyValueStoreNote value comparison is done by value and not by reference.
compareAndSet in interface KeyValueStorekey - the keyexpected - the expected value, which may be nullvalue - the updated value, which may be nullttl - the TTL, in seconds (0 for infinite)true if the value was updated, or false if not (the expected value was not found)public long addAndGet(String key, long delta) throws NumberFormatException
KeyValueStore
If the value does not exist (if KeyValueStore.get(java.lang.String) would return null), it is interpreted as 0.
addAndGet in interface KeyValueStorekey - the keydelta - the delta to addNumberFormatException - if the existing value cannot be interpreted as a longCopyright © 2019 Nuxeo. All rights reserved.