Interface AsyncConsistentMultimap<K,​V>

  • All Superinterfaces:
    AsyncIterable<java.util.Map.Entry<K,​V>>, DistributedPrimitive

    public interface AsyncConsistentMultimap<K,​V>
    extends DistributedPrimitive, AsyncIterable<java.util.Map.Entry<K,​V>>
    Interface for a distributed multimap. NOTE: Editing any returned collection will NOT effect the map itself and changes in the map will NOT be reflected in the returned collections. Certain operations may be too expensive when backed by a distributed data structure and have been labeled as such.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default java.util.concurrent.CompletableFuture<java.lang.Void> addListener​(MultimapEventListener<K,​V> listener)
      Registers the specified listener to be notified whenever the map is updated.
      java.util.concurrent.CompletableFuture<java.lang.Void> addListener​(MultimapEventListener<K,​V> listener, java.util.concurrent.Executor executor)
      Registers the specified listener to be notified whenever the map is updated.
      java.util.concurrent.CompletableFuture<java.util.Map<K,​java.util.Collection<V>>> asMap()
      Returns a map of keys to collections of values that reflect the set of key-value pairs contained in the multimap, where the key value pairs would be the key paired with each of the values in the collection.
      default ConsistentMultimap<K,​V> asMultimap()
      Returns a ConsistentMultimap instance that wraps this map.
      default ConsistentMultimap<K,​V> asMultimap​(long timeoutMillis)
      Returns a ConsistentMultimap instance that wraps this map.
      java.util.concurrent.CompletableFuture<java.lang.Void> clear()
      Removes all key-value pairs, after which it will be empty.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> containsEntry​(K key, V value)
      Returns true if this map contains at least one key-value pair with key and value specified.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> containsKey​(K key)
      Returns true if there is at lease one key-value pair with a key equal to key.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> containsValue​(V value)
      Returns true if this map contains at lease one key-value pair with a value equal to value.
      default java.util.concurrent.CompletableFuture<java.lang.Void> destroy()
      Purges state associated with this primitive.
      java.util.concurrent.CompletableFuture<java.util.Collection<java.util.Map.Entry<K,​V>>> entries()
      Returns a collection of each key-value pair in this map.
      java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> get​(K key)
      Returns a collection of values associated with the specified key, if the key is not in the map it will return an empty collection.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> isEmpty()
      Returns if this multimap contains no key-value pairs.
      java.util.concurrent.CompletableFuture<com.google.common.collect.Multiset<K>> keys()
      Returns a multiset of the keys present in this multimap with one or more associated values each.
      java.util.concurrent.CompletableFuture<java.util.Set<K>> keySet()
      Returns a set of the keys contained in this multimap with one or more associated values.
      default DistributedPrimitive.Type primitiveType()
      Returns the type of primitive.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> put​(K key, V value)
      If the key-value pair does not already exist adds either the key value pair or the value to the set of values associated with the key and returns true, if the key-value pair already exists then behavior is implementation specific with some implementations allowing duplicates and others ignoring put requests for existing entries.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> putAll​(K key, java.util.Collection<? extends V> values)
      Adds the set of key-value pairs of the specified key with each of the values in the iterable if each key-value pair does not already exist, if the pair does exist the behavior is implementation specific.
      java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> putAndGet​(K key, V value)
      If the key-value pair does not already exist adds either the key value pair or the value to the set of values associated with the key and returns the updated value, if the key-value pair already exists then behavior is implementation specific with some implementations allowing duplicates and others ignoring put requests for existing entries.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> remove​(K key, V value)
      Removes the key-value pair with the specified values if it exists.
      java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> removeAll​(K key)
      Removes all values associated with the specified key as well as the key itself.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> removeAll​(K key, java.util.Collection<? extends V> values)
      Removes the key-value pairs with the specified key and values if they exist.
      java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> removeAndGet​(K key, V value)
      Removes the key-value pair with the specified values if it exists.
      java.util.concurrent.CompletableFuture<java.lang.Void> removeListener​(MultimapEventListener<K,​V> listener)
      Unregisters the specified listener such that it will no longer receive map change notifications.
      java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> replaceValues​(K key, java.util.Collection<V> values)
      Stores all the values in values associated with the key specified, removes all preexisting values and returns a collection of the removed values which may be empty if the entry did not exist.
      java.util.concurrent.CompletableFuture<java.lang.Integer> size()
      Returns the number of key-value pairs in this multimap.
      java.util.concurrent.CompletableFuture<com.google.common.collect.Multiset<V>> values()
      Returns a collection of values in the set with duplicates permitted, the size of this collection will equal the size of the map at the time of creation.
    • Method Detail

      • destroy

        default java.util.concurrent.CompletableFuture<java.lang.Void> destroy()
        Description copied from interface: DistributedPrimitive
        Purges state associated with this primitive.

        Implementations can override and provide appropriate clean up logic for purging any state state associated with the primitive. Whether modifications made within the destroy method have local or global visibility is left unspecified.

        Specified by:
        destroy in interface DistributedPrimitive
        Returns:
        CompletableFuture that is completed when the operation completes
      • size

        java.util.concurrent.CompletableFuture<java.lang.Integer> size()
        Returns the number of key-value pairs in this multimap.
        Returns:
        the number of key-value pairs
      • isEmpty

        java.util.concurrent.CompletableFuture<java.lang.Boolean> isEmpty()
        Returns if this multimap contains no key-value pairs.
        Returns:
        completable future that will be true if no key-value pairs exist, false otherwise
      • containsKey

        java.util.concurrent.CompletableFuture<java.lang.Boolean> containsKey​(K key)
        Returns true if there is at lease one key-value pair with a key equal to key.
        Parameters:
        key - the key to query
        Returns:
        a future whose value will be true if the map contains a key-value pair with key false otherwise
      • containsValue

        java.util.concurrent.CompletableFuture<java.lang.Boolean> containsValue​(V value)
        Returns true if this map contains at lease one key-value pair with a value equal to value.
        Parameters:
        value - the value to query
        Returns:
        a future whose value will be true if there is a key-value pair with the specified value, false otherwise.
      • containsEntry

        java.util.concurrent.CompletableFuture<java.lang.Boolean> containsEntry​(K key,
                                                                                V value)
        Returns true if this map contains at least one key-value pair with key and value specified.
        Parameters:
        key - key
        value - value
        Returns:
        a future whose value will be true if there is a key-value pair with the specified key and value, false otherwise.
      • put

        java.util.concurrent.CompletableFuture<java.lang.Boolean> put​(K key,
                                                                      V value)
        If the key-value pair does not already exist adds either the key value pair or the value to the set of values associated with the key and returns true, if the key-value pair already exists then behavior is implementation specific with some implementations allowing duplicates and others ignoring put requests for existing entries.
        Parameters:
        key - the key to add
        value - the value to add
        Returns:
        a future whose value will be true if the map has changed because of this call, false otherwise
      • putAndGet

        java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> putAndGet​(K key,
                                                                                                       V value)
        If the key-value pair does not already exist adds either the key value pair or the value to the set of values associated with the key and returns the updated value, if the key-value pair already exists then behavior is implementation specific with some implementations allowing duplicates and others ignoring put requests for existing entries.
        Parameters:
        key - the key to add
        value - the value to add
        Returns:
        a future to be completed with the updated values
      • remove

        java.util.concurrent.CompletableFuture<java.lang.Boolean> remove​(K key,
                                                                         V value)
        Removes the key-value pair with the specified values if it exists. In implementations that allow duplicates which matching entry will be removed is undefined.
        Parameters:
        key - the key of the pair to be removed
        value - the value of the pair to be removed
        Returns:
        a future whose value will be true if the map changed because of this call, false otherwise.
      • removeAndGet

        java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> removeAndGet​(K key,
                                                                                                          V value)
        Removes the key-value pair with the specified values if it exists. In implementations that allow duplicates which matching entry will be removed is undefined.
        Parameters:
        key - the key of the pair to be removed
        value - the value of the pair to be removed
        Returns:
        a future to be completed with the updated values
      • removeAll

        java.util.concurrent.CompletableFuture<java.lang.Boolean> removeAll​(K key,
                                                                            java.util.Collection<? extends V> values)
        Removes the key-value pairs with the specified key and values if they exist. In implementations that allow duplicates each instance of a key will remove one matching entry, which one is not defined. Equivalent to repeated calls to remove() for each key value pair but more efficient.
        Parameters:
        key - the key of the pair to be removed
        values - the set of values to be removed
        Returns:
        a future whose value will be true if the map changes because of this call, false otherwise.
      • removeAll

        java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> removeAll​(K key)
        Removes all values associated with the specified key as well as the key itself.
        Parameters:
        key - the key whose key-value pairs will be removed
        Returns:
        a future whose value is the set of values that were removed, which may be empty, if the values did not exist the version will be less than one.
      • putAll

        java.util.concurrent.CompletableFuture<java.lang.Boolean> putAll​(K key,
                                                                         java.util.Collection<? extends V> values)
        Adds the set of key-value pairs of the specified key with each of the values in the iterable if each key-value pair does not already exist, if the pair does exist the behavior is implementation specific. (Same as repeated puts but with efficiency gains.)
        Parameters:
        key - the key to use for all pairs to be added
        values - the set of values to be added in pairs with the key
        Returns:
        a future whose value will be true if any change in the map results from this call, false otherwise
      • replaceValues

        java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> replaceValues​(K key,
                                                                                                           java.util.Collection<V> values)
        Stores all the values in values associated with the key specified, removes all preexisting values and returns a collection of the removed values which may be empty if the entry did not exist.
        Parameters:
        key - the key for all entries to be added
        values - the values to be associated with the key
        Returns:
        a future whose value will be the collection of removed values, which may be empty
      • clear

        java.util.concurrent.CompletableFuture<java.lang.Void> clear()
        Removes all key-value pairs, after which it will be empty.
        Returns:
        a future whose value is irrelevant, simply used to determine if the call has completed
      • get

        java.util.concurrent.CompletableFuture<Versioned<java.util.Collection<? extends V>>> get​(K key)
        Returns a collection of values associated with the specified key, if the key is not in the map it will return an empty collection.
        Parameters:
        key - the key whose associated values will be returned
        Returns:
        a future whose value will be the collection of the values associated with the specified key, the collection may be empty
      • keySet

        java.util.concurrent.CompletableFuture<java.util.Set<K>> keySet()
        Returns a set of the keys contained in this multimap with one or more associated values.
        Returns:
        a future whose value will be the collection of all keys with one or more associated values, this may be empty
      • keys

        java.util.concurrent.CompletableFuture<com.google.common.collect.Multiset<K>> keys()
        Returns a multiset of the keys present in this multimap with one or more associated values each. Keys will appear once for each key-value pair in which they participate.
        Returns:
        a future whose value will be a multiset of the keys, this may be empty
      • values

        java.util.concurrent.CompletableFuture<com.google.common.collect.Multiset<V>> values()
        Returns a collection of values in the set with duplicates permitted, the size of this collection will equal the size of the map at the time of creation.
        Returns:
        a future whose value will be a collection of values, this may be empty
      • entries

        java.util.concurrent.CompletableFuture<java.util.Collection<java.util.Map.Entry<K,​V>>> entries()
        Returns a collection of each key-value pair in this map.
        Returns:
        a future whose value will be a collection of all entries in the map, this may be empty
      • addListener

        default java.util.concurrent.CompletableFuture<java.lang.Void> addListener​(MultimapEventListener<K,​V> listener)
        Registers the specified listener to be notified whenever the map is updated.
        Parameters:
        listener - listener to notify about map events
        Returns:
        future that will be completed when the operation finishes
      • addListener

        java.util.concurrent.CompletableFuture<java.lang.Void> addListener​(MultimapEventListener<K,​V> listener,
                                                                           java.util.concurrent.Executor executor)
        Registers the specified listener to be notified whenever the map is updated.
        Parameters:
        listener - listener to notify about map events
        executor - executor to use for handling incoming map events
        Returns:
        future that will be completed when the operation finishes
      • removeListener

        java.util.concurrent.CompletableFuture<java.lang.Void> removeListener​(MultimapEventListener<K,​V> listener)
        Unregisters the specified listener such that it will no longer receive map change notifications.
        Parameters:
        listener - listener to unregister
        Returns:
        future that will be completed when the operation finishes
      • asMap

        java.util.concurrent.CompletableFuture<java.util.Map<K,​java.util.Collection<V>>> asMap()
        Returns a map of keys to collections of values that reflect the set of key-value pairs contained in the multimap, where the key value pairs would be the key paired with each of the values in the collection.
        Returns:
        a future whose value will be a map of keys to collections of values, the returned map may be empty.
      • asMultimap

        default ConsistentMultimap<K,​V> asMultimap()
        Returns a ConsistentMultimap instance that wraps this map. All calls will have the same behavior as this map but will be blocking instead of asynchronous. If a call does not complete within the default timeout an exception will be produced.
        Returns:
        a ConsistentMultimap which wraps this map, providing synchronous access to this map
      • asMultimap

        default ConsistentMultimap<K,​V> asMultimap​(long timeoutMillis)
        Returns a ConsistentMultimap instance that wraps this map. All calls will have the same behavior as this map but will be blocking instead of asynchronous. If a call does not complete within the specified timeout an exception will be produced.
        Parameters:
        timeoutMillis - the number of millis to block while waiting for a call to return
        Returns:
        a ConsistentMultimap which wraps this map, providing synchronous access to this map