public class KeyValueBlobTransientStore extends Object implements TransientStoreProvider
The key/value store used is the one with the same name as the transient store itself.
The blob provider used is the one with the same name as the transient store itself.
The storage format is the following:
__blobsize__: storage size; because entries may expire without us being notified due to their TTL, this may be higher than the actual storage size entryKey.completed: "true" if completed, "false" if not; presence of this key marks entry existence entryKey.paraminfo: ["foo", "bar"] entryKey.param.foo: value for param foo entryKey.param.foo__format: "java" for java serializable format, otherwise string entryKey.param.bar: value for param bar etc. entryKey.blobinfo: {"count": number of blobs, "size": storage size of the blobs} entryKey.blob.0: {"key": key in blob provider for first blob, "mimetype": MIME Type, "encoding": encoding, "filename": filename, "digest": digest} entryKey.blob.1: {...} same for second blob etc.
Modifier and Type | Field and Description |
---|---|
protected long |
absoluteMaxSize |
protected String |
blobProviderId |
static String |
CONFIG_BLOB_PROVIDER |
static String |
CONFIG_KEY_VALUE_STORE |
static String |
COUNT |
static String |
DIGEST |
static String |
DOT_BLOB_DOT |
static String |
DOT_BLOBINFO |
static String |
DOT_COMPLETED |
static String |
DOT_PARAM_DOT |
static String |
DOT_PARAMINFO |
static String |
ENCODING |
static String |
FILENAME |
static String |
FORMAT |
static String |
FORMAT_JAVA |
static String |
KEY |
protected String |
keyValueStoreName |
static String |
LENGTH |
protected static com.fasterxml.jackson.core.type.TypeReference<List<String>> |
LIST_STRING |
protected static com.fasterxml.jackson.core.type.TypeReference<Map<String,String>> |
MAP_STRING_STRING |
protected com.fasterxml.jackson.databind.ObjectMapper |
mapper |
static String |
MIMETYPE |
protected int |
releaseTTL
TTL used to keep objects around a bit longer if there's space for them, for caching.
|
static String |
SEP |
static String |
SIZE |
static String |
STORAGE_SIZE |
protected long |
targetMaxSize |
protected int |
ttl
Basic TTL for all entries.
|
Constructor and Description |
---|
KeyValueBlobTransientStore() |
Modifier and Type | Method and Description |
---|---|
protected void |
addStorageSize(long delta) |
void |
atomicUpdate(String key,
Function<String,String> updateFunction,
long ttl) |
protected void |
computeStorageSize()
Computes an exact value for the current storage size (sum of all blobs size).
|
void |
doGC()
Runs garbage collecting to delete the file system resources that are associated with entries that were removed.
|
boolean |
exists(String key)
Returns
true if an entry exists with the given key . |
protected BlobProvider |
getBlobProvider() |
List<Blob> |
getBlobs(String key)
Gets the blobs associated with the entry with the given
key . |
protected KeyValueStore |
getKeyValueStore() |
Serializable |
getParameter(String key,
String parameter)
Gets the value of
parameter in the entry with the given key . |
Map<String,Serializable> |
getParameters(String key)
Gets values of the parameters in the entry with the given
key . |
long |
getSize(String key)
Returns the size of the blobs associated with the entry with the given
key or -1 if entry does
not exist. |
long |
getStorageSize()
Returns the size (in bytes) of the disk storage used for blobs.
|
void |
init(TransientStoreConfig config)
Initializes the store from the given
config . |
boolean |
isCompleted(String key)
Returns
true if the entry with the given key is ready. |
protected List<String> |
jsonToList(String json) |
protected Map<String,String> |
jsonToMap(String json) |
Stream<String> |
keyStream()
Returns a
Stream of keys for all entries. |
protected void |
markEntryExists(String key) |
void |
putBlobs(String key,
List<Blob> blobs)
Associates the given
blobs with the entry with the given key . |
void |
putParameter(String key,
String parameter,
Serializable value)
Sets
parameter to value in the entry with the given key . |
void |
putParameters(String key,
Map<String,Serializable> parameters)
Puts
parameters in the entry with the given key . |
void |
release(String key)
Informs the store that the entry with the given
key can be released if TTL or GC parameters require to do
some cleanup. |
void |
remove(String key)
Removes entry with the given
key . |
void |
removeAll()
Removes all entries from the store.
|
protected void |
removeBlobs(String key) |
protected void |
removeCompleted(String key) |
protected void |
removeParameters(String key) |
void |
setCompleted(String key,
boolean completed)
Marks the entry with the given
key as ready. |
protected void |
setReleaseTTL(String key) |
void |
shutdown()
Shuts down the store.
|
protected String |
toJson(Object object) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getStorageSizeMB, keySet
public static final String SEP
public static final String STORAGE_SIZE
public static final String DOT_COMPLETED
public static final String DOT_PARAMINFO
public static final String DOT_PARAM_DOT
public static final String FORMAT
public static final String FORMAT_JAVA
public static final String DOT_BLOBINFO
public static final String COUNT
public static final String SIZE
public static final String DOT_BLOB_DOT
public static final String KEY
public static final String MIMETYPE
public static final String ENCODING
public static final String FILENAME
public static final String LENGTH
public static final String DIGEST
public static final String CONFIG_KEY_VALUE_STORE
public static final String CONFIG_BLOB_PROVIDER
protected String keyValueStoreName
protected String blobProviderId
protected int ttl
protected int releaseTTL
protected long targetMaxSize
protected long absoluteMaxSize
protected com.fasterxml.jackson.databind.ObjectMapper mapper
protected static final com.fasterxml.jackson.core.type.TypeReference<List<String>> LIST_STRING
protected static final com.fasterxml.jackson.core.type.TypeReference<Map<String,String>> MAP_STRING_STRING
public KeyValueBlobTransientStore()
public void init(TransientStoreConfig config)
TransientStoreProvider
config
.init
in interface TransientStoreProvider
protected KeyValueStore getKeyValueStore()
protected BlobProvider getBlobProvider()
public void shutdown()
TransientStoreProvider
shutdown
in interface TransientStoreProvider
public Stream<String> keyStream()
TransientStoreProvider
Stream
of keys for all entries.keyStream
in interface TransientStoreProvider
public long getStorageSize()
TransientStoreProvider
getStorageSize
in interface TransientStoreProvider
protected void addStorageSize(long delta)
protected void computeStorageSize()
Does not take into account blob de-duplication that may be done by the blob provider.
Does not take into account blobs that still exist in the blob provider but are not referenced anymore (due to TTL expiration or GC not having been done).
public void doGC()
TransientStoreProvider
doGC
in interface TransientStoreProvider
public void removeAll()
TransientStoreProvider
removeAll
in interface TransientStoreProvider
protected List<String> jsonToList(String json)
public void atomicUpdate(String key, Function<String,String> updateFunction, long ttl)
public boolean exists(String key)
TransientStore
true
if an entry exists with the given key
.exists
in interface TransientStore
protected void markEntryExists(String key)
public void putParameter(String key, String parameter, Serializable value)
TransientStore
parameter
to value
in the entry with the given key
.
If entry does not exist a new entry is created. If parameter
already exists in the entry it is
overwritten.
putParameter
in interface TransientStore
public Serializable getParameter(String key, String parameter)
TransientStore
parameter
in the entry with the given key
.
Returns null
if entry or parameter does not exist.
getParameter
in interface TransientStore
public void putParameters(String key, Map<String,Serializable> parameters)
TransientStore
parameters
in the entry with the given key
. Overwrites any existing parameter in the entry.
If entry does not exist a new entry is created.
putParameters
in interface TransientStore
public Map<String,Serializable> getParameters(String key)
TransientStore
key
.
Returns null
if entry does not exist.
getParameters
in interface TransientStore
protected void removeParameters(String key)
public void putBlobs(String key, List<Blob> blobs)
TransientStore
blobs
with the entry with the given key
.
If entry does not exist a new entry is created.
putBlobs
in interface TransientStore
protected void removeBlobs(String key)
public List<Blob> getBlobs(String key)
TransientStore
key
.
Returns null
if entry does not exist.
getBlobs
in interface TransientStore
public long getSize(String key)
TransientStore
key
or -1
if entry does
not exist.getSize
in interface TransientStore
public boolean isCompleted(String key)
TransientStore
true
if the entry with the given key
is ready.isCompleted
in interface TransientStore
public void setCompleted(String key, boolean completed)
TransientStore
key
as ready.
If entry does not exist a new entry is created.
setCompleted
in interface TransientStore
protected void removeCompleted(String key)
public void release(String key)
TransientStore
key
can be released if TTL or GC parameters require to do
some cleanup.
Has no effect if entry does not exist.
release
in interface TransientStore
protected void setReleaseTTL(String key)
public void remove(String key)
TransientStore
key
.
Has no effect if entry does not exist.
remove
in interface TransientStore
Copyright © 2018 Nuxeo. All rights reserved.