Interface TransientStore<V>

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
BaseTransientStore, MapBackedStore, ZkEphemeralStore

public interface TransientStore<V> extends AutoCloseable
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 Details

    • get

      V get(String key)
      Returns a value corresponding to the given look-up key if exists, null otherwise.
      Parameters:
      key - look-up key
    • put

      V put(String key, V value)
      Stores the given (key, value) in this store overriding the existing value.
      Parameters:
      key - look-up key
      value - value to store
      Returns:
      the old value if the key exists, null otherwise
    • putIfAbsent

      V putIfAbsent(String key, V value)
      Stores the given (key, value) tuple in this store only if it does not exists.
      Parameters:
      key - look-up key
      value - value to store
      Returns:
      the old value if the key exists, null otherwise
    • remove

      V remove(String key)
      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

      Iterator<Map.Entry<String,V>> entries()
      Returns an iterator of (key, value) tuples.
    • keys

      Iterator<String> keys()
      Returns an iterator of keys.
    • values

      Iterator<V> values()
      Returns an iterator of values.
    • size

      int size()
      Returns number of entries.
    • addListener

      void addListener(TransientStoreListener listener)
      Adds a listener that observes store 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.
      See Also:
    • removeListener

      void removeListener(TransientStoreListener listener)
      Removes the given listener from this store if exists, has no effect otherwise.