public final class LeaseCheckDocumentStoreWrapper extends java.lang.Object implements DocumentStore
Constructor and Description |
---|
LeaseCheckDocumentStoreWrapper(DocumentStore delegate,
ClusterNodeInfo clusterNodeInfo) |
Modifier and Type | Method and Description |
---|---|
<T extends Document> |
create(Collection<T> collection,
java.util.List<UpdateOp> updateOps)
Try to create a list of documents.
|
<T extends Document> |
createOrUpdate(Collection<T> collection,
java.util.List<UpdateOp> updateOps)
Create or unconditionally update a number of documents.
|
<T extends Document> |
createOrUpdate(Collection<T> collection,
UpdateOp update)
Atomically checks if the document exists and updates it, otherwise the
document is created (aka "upsert"), unless the update operation requires
the document to be present (see
UpdateOp.isNew() ). |
long |
determineServerTimeDifferenceMillis() |
void |
dispose()
Dispose this instance.
|
<T extends Document> |
find(Collection<T> collection,
java.lang.String key)
Get the document with the given
key . |
<T extends Document> |
find(Collection<T> collection,
java.lang.String key,
int maxCacheAge)
Get the document with the
key . |
<T extends Document> |
findAndUpdate(Collection<T> collection,
UpdateOp update)
Performs a conditional update (e.g.
|
java.lang.Iterable<CacheStats> |
getCacheStats() |
<T extends Document> |
getIfCached(Collection<T> collection,
java.lang.String key)
Fetches the cached document.
|
java.util.Map<java.lang.String,java.lang.String> |
getMetadata() |
int |
getNodeNameLimit()
Return the size limit for node name based on the document store implementation
|
@NotNull java.util.Map<java.lang.String,java.lang.String> |
getStats()
Returns statistics about the underlying storage.
|
CacheInvalidationStats |
invalidateCache()
Invalidate the document cache.
|
<T extends Document> |
invalidateCache(Collection<T> collection,
java.lang.String key)
Invalidate the document cache for the given key.
|
CacheInvalidationStats |
invalidateCache(java.lang.Iterable<java.lang.String> keys)
Invalidate the document cache but only with entries that match one
of the keys provided.
|
<T extends Document> |
query(Collection<T> collection,
java.lang.String fromKey,
java.lang.String toKey,
int limit)
Get a list of documents where the key is greater than a start value and
less than an end value.
|
<T extends Document> |
query(Collection<T> collection,
java.lang.String fromKey,
java.lang.String toKey,
java.lang.String indexedProperty,
long startValue,
int limit)
Get a list of documents where the key is greater than a start value and
less than an end value and the given "indexed property" is greater
or equals the specified value.
|
<T extends Document> |
remove(Collection<T> collection,
java.util.List<java.lang.String> keys)
Batch remove documents with given keys.
|
<T extends Document> |
remove(Collection<T> collection,
java.util.Map<java.lang.String,java.lang.Long> toRemove)
Batch remove documents with given keys and corresponding equal conditions
on
NodeDocument.MODIFIED_IN_SECS values. |
<T extends Document> |
remove(Collection<T> collection,
java.lang.String key)
Remove a document.
|
<T extends Document> |
remove(Collection<T> collection,
java.lang.String indexedProperty,
long startValue,
long endValue)
Batch remove documents where the given "indexed property" is within the given
range (exclusive) -
(startValue, endValue) . |
void |
setReadWriteMode(java.lang.String readWriteMode)
Set the level of guarantee for read and write operations, if supported by this backend.
|
public LeaseCheckDocumentStoreWrapper(DocumentStore delegate, ClusterNodeInfo clusterNodeInfo)
public final <T extends Document> T find(Collection<T> collection, java.lang.String key)
DocumentStore
key
. This is a convenience method
and equivalent to DocumentStore.find(Collection, String, int)
with a
maxCacheAge
of Integer.MAX_VALUE
.
The returned document is immutable.
find
in interface DocumentStore
T
- the document typecollection
- the collectionkey
- the keypublic final <T extends Document> T find(Collection<T> collection, java.lang.String key, int maxCacheAge)
DocumentStore
key
. The implementation may serve the
document from a cache, but the cached document must not be older than
the given maxCacheAge
in milliseconds. An implementation must
invalidate a cached document when it detects it is outdated. That is, a
subsequent call to DocumentStore.find(Collection, String)
must return the
newer version of the document.
The returned document is immutable.
find
in interface DocumentStore
T
- the document typecollection
- the collectionkey
- the keymaxCacheAge
- the maximum age of the cached document (in ms)public final <T extends Document> java.util.List<T> query(Collection<T> collection, java.lang.String fromKey, java.lang.String toKey, int limit)
DocumentStore
The returned documents are sorted by key and are immutable.
query
in interface DocumentStore
T
- the document typecollection
- the collectionfromKey
- the start value (excluding)toKey
- the end value (excluding)limit
- the maximum number of entries to return (starting with the lowest key)public final <T extends Document> java.util.List<T> query(Collection<T> collection, java.lang.String fromKey, java.lang.String toKey, java.lang.String indexedProperty, long startValue, int limit)
DocumentStore
The indexed property can either be a Long
value, in which case numeric
comparison applies, or a Boolean
value, in which case "false" is mapped
to "0" and "true" is mapped to "1".
The returned documents are sorted by key and are immutable.
query
in interface DocumentStore
T
- the document typecollection
- the collectionfromKey
- the start value (excluding)toKey
- the end value (excluding)indexedProperty
- the name of the indexed property (optional)startValue
- the minimum value of the indexed propertylimit
- the maximum number of entries to returnpublic final <T extends Document> void remove(Collection<T> collection, java.lang.String key)
DocumentStore
In case of a DocumentStoreException
, the document with the given
key may or may not have been removed from the store. It is the
responsibility of the caller to check whether it still exists. The
implementation however ensures that the result of the operation is
properly reflected in the document cache. That is, an implementation
could simply evict the document with the given key.
remove
in interface DocumentStore
T
- the document typecollection
- the collectionkey
- the keypublic final <T extends Document> void remove(Collection<T> collection, java.util.List<java.lang.String> keys)
DocumentStore
keys
may have been
removed.
In case of a DocumentStoreException
, the documents with the given
keys may or may not have been removed from the store. It may also be
possible that only some have been removed from the store. It is the
responsibility of the caller to check which documents still exist. The
implementation however ensures that the result of the operation is
properly reflected in the document cache. That is, an implementation
could simply evict documents with the given keys from the cache.
remove
in interface DocumentStore
T
- the document typecollection
- the collectionkeys
- list of keyspublic final <T extends Document> int remove(Collection<T> collection, java.util.Map<java.lang.String,java.lang.Long> toRemove)
DocumentStore
NodeDocument.MODIFIED_IN_SECS
values. Keys for documents that
do not exist are simply ignored. A document is only removed if the
corresponding condition is met.
In case of a DocumentStoreException
, the documents with the given
keys may or may not have been removed from the store. It may also be
possible that only some have been removed from the store. It is the
responsibility of the caller to check which documents still exist. The
implementation however ensures that the result of the operation is
properly reflected in the document cache. That is, an implementation
could simply evict documents with the given keys from the cache.
remove
in interface DocumentStore
T
- the document typecollection
- the collection.toRemove
- the keys of the documents to remove with the corresponding
timestamps.public <T extends Document> int remove(Collection<T> collection, java.lang.String indexedProperty, long startValue, long endValue) throws DocumentStoreException
DocumentStore
(startValue, endValue)
.
The indexed property is a Long
value and numeric comparison applies.
In case of a DocumentStoreException
, the documents with the given
keys may or may not have been removed from the store. It may also be
possible that only some have been removed from the store. It is the
responsibility of the caller to check which documents still exist. The
implementation however ensures that the result of the operation is
properly reflected in the document cache. That is, an implementation
could simply evict documents with the given keys from the cache.
remove
in interface DocumentStore
T
- the document typecollection
- the collection.indexedProperty
- the name of the indexed propertystartValue
- the minimum value of the indexed property (exclusive)endValue
- the maximum value of the indexed property (exclusive)DocumentStoreException
- if the operation failed. E.g. because of
an I/O error.public final <T extends Document> boolean create(Collection<T> collection, java.util.List<UpdateOp> updateOps)
DocumentStore
true
iff
none of the documents existed before and the create was successful. This
method will return false
if one of the documents already exists
in the store. Some documents may still have been created in the store.
An implementation does not have to guarantee an atomic create of all the
documents described in the updateOps
. It is the responsibility of
the caller to check, which documents were created and take appropriate
action. The same is true when this method throws
DocumentStoreException
(e.g. when a communication error occurs).
In this case only some documents may have been created.create
in interface DocumentStore
T
- the document typecollection
- the collectionupdateOps
- the list of documents to add (where UpdateOp.Condition
s are not allowed)public final <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update)
DocumentStore
UpdateOp.isNew()
). The returned
document is immutable.
If this method fails with a DocumentStoreException
, then the
document may or may not have been created or updated. It is the
responsibility of the caller to check the result e.g. by calling
DocumentStore.find(Collection, String)
. The implementation however ensures
that the result of the operation is properly reflected in the document
cache. That is, an implementation could simply evict documents with the
given keys from the cache.
createOrUpdate
in interface DocumentStore
T
- the document typecollection
- the collectionupdate
- the update operation (where UpdateOp.Condition
s are not
allowed)null
if it either didn't exist
before, or the UpdateOp required the document to be
present but UpdateOp.isNew()
was false
.public <T extends Document> java.util.List<T> createOrUpdate(Collection<T> collection, java.util.List<UpdateOp> updateOps)
DocumentStore
In case of a DocumentStoreException
(e.g. when a communication
error occurs) only some changes may have been applied. In this case it is
the responsibility of the caller to check which UpdateOps
were applied and take appropriate action. The implementation however
ensures that the result of the operations are properly reflected in the
document cache. That is, an implementation could simply evict documents
related to the given update operations from the cache.
createOrUpdate
in interface DocumentStore
T
- the document typecollection
- the collectionupdateOps
- the update operation listnull
values if they didn't exist
before (see DocumentStore.createOrUpdate(Collection, UpdateOp)), where the order
reflects the order in the "updateOps" parameterpublic final <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update)
DocumentStore
UpdateOp.Condition.Type.EXISTS
and only updates the
document if the condition is true
. The returned document is
immutable.
In case of a DocumentStoreException
(e.g. when a communication
error occurs) the update may or may not have been applied. In this case
it is the responsibility of the caller to check whether the update was
applied and take appropriate action. The implementation however ensures
that the result of the operation is properly reflected in the document
cache. That is, an implementation could simply evict the document related
to the given update operation from the cache.
findAndUpdate
in interface DocumentStore
T
- the document typecollection
- the collectionupdate
- the update operation with the conditionnull
if the condition is not met or
if the document wasn't foundpublic final CacheInvalidationStats invalidateCache()
DocumentStore
DocumentStore.getIfCached(Collection, String)
returns a non-null value for a key.
An implementation is allowed to perform lazy invalidation and only check
whether a document is up-to-date when it is accessed after this method
is called. However, this also includes a call to DocumentStore.getIfCached(Collection, String)
,
which must only return the document if it was up-to-date at the time
this method was called. Similarly, a call to DocumentStore.find(Collection, String)
must guarantee the returned document reflects all the changes done up to
when invalidateCache()
was called.
In some implementations this method can be a NOP because documents can
only be modified through a single instance of a DocumentStore
.
invalidateCache
in interface DocumentStore
null
if none are
available.public final CacheInvalidationStats invalidateCache(java.lang.Iterable<java.lang.String> keys)
DocumentStore
DocumentStore.invalidateCache()
for the general contract of cache
invalidation.invalidateCache
in interface DocumentStore
keys
- the keys of the documents to invalidate.null
if none are
available.public final <T extends Document> void invalidateCache(Collection<T> collection, java.lang.String key)
DocumentStore
DocumentStore.invalidateCache()
for the general contract of cache
invalidation.invalidateCache
in interface DocumentStore
collection
- the collectionkey
- the keypublic final void dispose()
DocumentStore
dispose
in interface DocumentStore
public final <T extends Document> T getIfCached(Collection<T> collection, java.lang.String key)
DocumentStore
null
will be returned. This method is consistent with other find
methods that may return cached documents and will return null
even when the implementation has a negative cache for documents that
do not exist. This method will never return NodeDocument.NULL
.getIfCached
in interface DocumentStore
T
- the document typecollection
- the collectionkey
- the keynull
.public final void setReadWriteMode(java.lang.String readWriteMode)
DocumentStore
setReadWriteMode
in interface DocumentStore
readWriteMode
- the read/write modepublic final java.lang.Iterable<CacheStats> getCacheStats()
getCacheStats
in interface DocumentStore
public final java.util.Map<java.lang.String,java.lang.String> getMetadata()
getMetadata
in interface DocumentStore
@NotNull public @NotNull java.util.Map<java.lang.String,java.lang.String> getStats()
DocumentStore
getStats
in interface DocumentStore
public long determineServerTimeDifferenceMillis()
determineServerTimeDifferenceMillis
in interface DocumentStore
public int getNodeNameLimit()
getNodeNameLimit
in interface DocumentStore
Copyright © 2012–2022 The Apache Software Foundation. All rights reserved.