public interface TransientStore<V> extends AutoCloseable
PersistentStore
in that the lifetime of
a (key, value) tuple is bound to the lifetime of the node originally creating it. In other words, entries are evicted
as soon as node/s originally stored them leaves the cluster. That should explain the reason for relocating this
abstraction under cluster coordination package.
Consumers of this interface can observe changes made to the store via attaching a listener
.Modifier and Type | Method and Description |
---|---|
void |
addListener(TransientStoreListener listener)
Adds a listener that observes store
events . |
Iterator<Map.Entry<String,V>> |
entries()
Returns an iterator of (key, value) tuples.
|
V |
get(String key)
Returns a value corresponding to the given look-up key if exists, null otherwise.
|
Iterator<String> |
keys()
Returns an iterator of keys.
|
V |
put(String key,
V value)
Stores the given (key, value) in this store overriding the existing value.
|
V |
putIfAbsent(String key,
V value)
Stores the given (key, value) tuple in this store only if it does not exists.
|
V |
remove(String key)
Removes the (key, value) tuple from this store if the key exists.
|
void |
removeListener(TransientStoreListener listener)
Removes the given listener from this store if exists, has no effect otherwise.
|
int |
size()
Returns number of entries.
|
Iterator<V> |
values()
Returns an iterator of values.
|
close
V get(String key)
key
- look-up keyV put(String key, V value)
key
- look-up keyvalue
- value to storeV putIfAbsent(String key, V value)
key
- look-up keyvalue
- value to storeV remove(String key)
key
- look-up keyint size()
void addListener(TransientStoreListener listener)
events
.
Note that
i) Calling this method with the same listener instance more than once has no effect.
ii) Listeners are not necessarily invoked from the calling thread. Consumer should consider thread safety issues.
iii) Subclasses might hold a strong reference to the listener. It is important that consumer
removes
its listener once it is done observing events.removeListener(TransientStoreListener)
void removeListener(TransientStoreListener listener)
Copyright © 1970 The Apache Software Foundation. All rights reserved.