public class RangeCache extends Object implements AutoCloseable, Iterable<KeyValue>
The cache must be started via the start() method before
it will populate and update itself with key/values from the
specified range.
Note that no range checking is done - the cache will not update itself with keys outside of the specified range, but it is possible to put, delete and getRemote keys outside of the range. This is not advised and may result in stale out-of-range key/values remaining in the cache.
| Modifier and Type | Class and Description |
|---|---|
static interface |
RangeCache.Listener
Interface for listening to update events from
the cache
|
static class |
RangeCache.PutResult
Stores result of put operations
|
| Modifier and Type | Field and Description |
|---|---|
protected Executor |
listenerExecutor |
protected List<RangeCache.Listener> |
listeners |
protected static org.slf4j.Logger |
logger |
static long |
TIMEOUT_MS |
| Constructor and Description |
|---|
RangeCache(EtcdClient client,
com.google.protobuf.ByteString prefix) |
RangeCache(EtcdClient client,
com.google.protobuf.ByteString prefix,
boolean sorted) |
RangeCache(EtcdClient client,
com.google.protobuf.ByteString prefix,
boolean sorted,
Executor listenerExecutor) |
RangeCache(EtcdClient client,
com.google.protobuf.ByteString fromKey,
com.google.protobuf.ByteString toKey,
boolean sorted) |
RangeCache(EtcdClient client,
com.google.protobuf.ByteString fromKey,
com.google.protobuf.ByteString toKey,
boolean sorted,
Executor listenerExecutor) |
RangeCache(EtcdClient client,
com.google.protobuf.ByteString prefix,
Executor listenerExecutor) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(RangeCache.Listener listener) |
void |
close() |
boolean |
delete(com.google.protobuf.ByteString key)
Unconditional delete
|
boolean |
delete(com.google.protobuf.ByteString key,
long modRev)
Conditional delete
|
void |
forEach(Consumer<? super KeyValue> action) |
protected com.google.common.util.concurrent.ListenableFuture<Boolean> |
fullRefreshCache() |
KeyValue |
get(com.google.protobuf.ByteString key) |
KeyValue |
getFirst() |
KeyValue |
getRemote(com.google.protobuf.ByteString key) |
protected KeyValue |
getRemote(com.google.protobuf.ByteString key,
boolean weak) |
KeyValue |
getRemoteWeak(com.google.protobuf.ByteString key) |
boolean |
isClosed() |
protected static boolean |
isDeleted(KeyValue kv) |
Iterator<KeyValue> |
iterator()
Iterator.remove() not supported on returned iterators |
boolean |
keyExists(com.google.protobuf.ByteString key) |
boolean |
keyExistsRemote(com.google.protobuf.ByteString key) |
Set<com.google.protobuf.ByteString> |
keySet() |
protected static KeyValue |
kvOrNullIfDeleted(KeyValue fromCache) |
protected static Compare.Builder |
modRevCompare(com.google.protobuf.ByteString key,
long modRev) |
protected void |
notifyListeners(RangeCache.Listener.EventType type,
KeyValue keyValue,
boolean inListenerExecutor) |
protected KeyValue |
offerDelete(com.google.protobuf.ByteString key,
long modRevision)
Assumed to not be called from watch/listener executor
|
protected KeyValue |
offerExpiry(com.google.protobuf.ByteString key)
Deprecated.
this method now has no effect
|
protected KeyValue |
offerUpdate(KeyValue keyValue,
boolean watchThread) |
long |
put(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value)
Unconditional put.
|
RangeCache.PutResult |
put(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long modRev) |
RangeCache.PutResult |
put(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long lease,
CompareOrBuilder... conditions)
Multi-purpose put or delete, returns updated or existing KeyValue
|
RangeCache.PutResult |
put(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long leaseId,
long modRev) |
long |
putNoGet(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long modRev) |
long |
putNoGet(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long lease,
CompareOrBuilder... conditions)
Multi-purpose put or delete.
|
long |
putNoGet(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long leaseId,
long modRev) |
protected TxnRequest |
putTxn(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
boolean getOnFail,
long lease,
CompareOrBuilder... conditions) |
boolean |
removeListener(RangeCache.Listener listener) |
protected void |
revisionUpdate(long upToRev) |
int |
size() |
com.google.common.util.concurrent.ListenableFuture<Boolean> |
start()
Start the cache.
|
Iterator<KeyValue> |
strongIterator()
Iterator whose contents is guaranteed to be sequentially consistent
with remote updates to the cached range.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitspliteratorprotected static final org.slf4j.Logger logger
public static final long TIMEOUT_MS
protected final List<RangeCache.Listener> listeners
protected final Executor listenerExecutor
public RangeCache(EtcdClient client, com.google.protobuf.ByteString prefix)
public RangeCache(EtcdClient client, com.google.protobuf.ByteString prefix, Executor listenerExecutor)
public RangeCache(EtcdClient client, com.google.protobuf.ByteString prefix, boolean sorted)
public RangeCache(EtcdClient client, com.google.protobuf.ByteString prefix, boolean sorted, Executor listenerExecutor)
public RangeCache(EtcdClient client, com.google.protobuf.ByteString fromKey, com.google.protobuf.ByteString toKey, boolean sorted)
public RangeCache(EtcdClient client, com.google.protobuf.ByteString fromKey, com.google.protobuf.ByteString toKey, boolean sorted, Executor listenerExecutor)
public com.google.common.util.concurrent.ListenableFuture<Boolean> start()
protected com.google.common.util.concurrent.ListenableFuture<Boolean> fullRefreshCache()
protected void revisionUpdate(long upToRev)
public void addListener(RangeCache.Listener listener)
public boolean removeListener(RangeCache.Listener listener)
protected void notifyListeners(RangeCache.Listener.EventType type, KeyValue keyValue, boolean inListenerExecutor)
protected KeyValue offerExpiry(com.google.protobuf.ByteString key)
protected KeyValue offerDelete(com.google.protobuf.ByteString key, long modRevision)
protected KeyValue offerUpdate(KeyValue keyValue, boolean watchThread)
keyValue - watchThread - if being called from background watch contextprotected static boolean isDeleted(KeyValue kv)
public KeyValue get(com.google.protobuf.ByteString key)
public KeyValue getFirst()
protected KeyValue getRemote(com.google.protobuf.ByteString key, boolean weak)
public KeyValue getRemote(com.google.protobuf.ByteString key)
public KeyValue getRemoteWeak(com.google.protobuf.ByteString key)
public int size()
public boolean keyExists(com.google.protobuf.ByteString key)
public boolean keyExistsRemote(com.google.protobuf.ByteString key)
public long put(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value)
delete(ByteString) for this.key - value - value to putpublic RangeCache.PutResult put(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value, long lease, CompareOrBuilder... conditions)
key - value - new value to put, or null to deletelease - leaseId to associate value with if successful, or 0L for no leaseconditions - conditions which must all match to proceed, null or empty for unconditionalpublic RangeCache.PutResult put(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value, long modRev)
key - value - new value to put, or null to deletemodRev - last-modified revision to match, or 0 for put-if-absentpublic RangeCache.PutResult put(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value, long leaseId, long modRev)
key - value - new value to put, or null to deleteleaseId - leaseId to associate value with if successful, or 0L for no leasemodRev - last-modified revision to match, or 0 for put-if-absentpublic long putNoGet(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long lease,
CompareOrBuilder... conditions)
key - value - new value to put, or null to deletelease - leaseId to associate value with if successful, or 0L for no leaseconditions - conditions which must all match to proceed, null or empty for unconditionalpublic long putNoGet(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long modRev)
key - value - new value to put, or null to deletemodRev - last-modified revision to match, or 0 for put-if-absentpublic long putNoGet(com.google.protobuf.ByteString key,
com.google.protobuf.ByteString value,
long leaseId,
long modRev)
key - value - new value to put, or null to deleteleaseId - leaseId to associate value with if successful, or 0L for no leasemodRev - last-modified rev to match, or 0 for put-if-absentprotected static Compare.Builder modRevCompare(com.google.protobuf.ByteString key, long modRev)
protected TxnRequest putTxn(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value, boolean getOnFail, long lease, CompareOrBuilder... conditions)
public boolean delete(com.google.protobuf.ByteString key)
key - public boolean delete(com.google.protobuf.ByteString key,
long modRev)
key - modRev - public Set<com.google.protobuf.ByteString> keySet()
public Iterator<KeyValue> iterator()
Iterator.remove() not supported on returned iteratorspublic Iterator<KeyValue> strongIterator()
public void close()
close in interface AutoCloseablepublic boolean isClosed()
Copyright © 2022. All rights reserved.