Interface TransientStore<V>
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
BaseTransientStore
,MapBackedStore
,ZkEphemeralStore
An abstraction for storing, retrieving and observing transient (key, value) pairs in a distributed environment.
This abstraction diverges from
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
.-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(TransientStoreListener listener) Adds a listener that observes storeevents
.entries()
Returns an iterator of (key, value) tuples.Returns a value corresponding to the given look-up key if exists, null otherwise.keys()
Returns an iterator of keys.Stores the given (key, value) in this store overriding the existing value.putIfAbsent
(String key, V value) Stores the given (key, value) tuple in this store only if it does not exists.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.values()
Returns an iterator of values.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
get
Returns a value corresponding to the given look-up key if exists, null otherwise.- Parameters:
key
- look-up key
-
put
Stores the given (key, value) in this store overriding the existing value.- Parameters:
key
- look-up keyvalue
- value to store- Returns:
- the old value if the key exists, null otherwise
-
putIfAbsent
Stores the given (key, value) tuple in this store only if it does not exists.- Parameters:
key
- look-up keyvalue
- value to store- Returns:
- the old value if the key exists, null otherwise
-
remove
Removes the (key, value) tuple from this store if the key exists.- Parameters:
key
- look-up key- Returns:
- the removed value if key exists, null otherwise
-
entries
Returns an iterator of (key, value) tuples. -
keys
Returns an iterator of keys. -
values
Returns an iterator of values. -
size
int size()Returns number of entries. -
addListener
Adds a listener that observes storeevents
. 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 consumerremoves
its listener once it is done observing events.- See Also:
-
removeListener
Removes the given listener from this store if exists, has no effect otherwise.
-