Interface IMap<K,​V>

  • Type Parameters:
    K - key type
    V - value type
    All Superinterfaces:
    BaseMap<K,​V>, java.util.concurrent.ConcurrentMap<K,​V>, DistributedObject, java.lang.Iterable<java.util.Map.Entry<K,​V>>, java.util.Map<K,​V>

    public interface IMap<K,​V>
    extends java.util.concurrent.ConcurrentMap<K,​V>, BaseMap<K,​V>, java.lang.Iterable<java.util.Map.Entry<K,​V>>
    Concurrent, distributed, observable and queryable map.

    This class is not a general-purpose ConcurrentMap implementation! While this class implements the Map interface, it intentionally violates Map's general contract, which mandates the use of the equals method when comparing objects. Instead of the equals method, this implementation compares the serialized byte version of the objects.

    Moreover, stored values are handled as having a value type semantics, while standard Java implementations treat them as having a reference type semantics.

    Gotchas:

    • Methods, including but not limited to get, containsKey, containsValue, evict, remove, put, putIfAbsent, replace, lock, unlock, do not use hashCode and equals implementations of keys. Instead, they use hashCode and equals of binary (serialized) forms of the objects.
    • The get method returns a clone of original values, so modifying the returned value does not change the actual value in the map. You should put the modified value back to make changes visible to all nodes. For additional info, see get(Object).
    • Methods, including but not limited to keySet, values, entrySet, return an immutable collection clone of the values. The collection is NOT backed by the map, so changes to the map are NOT reflected in the collection.
    • Be careful while using default interface method implementations from ConcurrentMap and Map. Under the hood they are typically implemented as a sequence of more primitive map operations, therefore the operations won't be executed atomically.

    This class does not allow null to be used as a key or value.

    Entry Processing

    The following operations are lock-aware, since they operate on a single key only. If the key is locked, the EntryProcessor will wait until it acquires the lock.

    However, there are following methods that run the EntryProcessor on more than one entry. These operations are not lock-aware. The EntryProcessor will process the entries no matter if they are locked or not. The user may however check if an entry is locked by casting the Map.Entry to LockAware and invoking the LockAware.isLocked() method. This applies to both EntryProcessor and BackupEntryProcessor.

    Split-brain

    Behaviour of IMap under split-brain scenarios should be taken into account when using this data structure. During a split, each partitioned cluster will either create a brand new IMap or it will continue to use the primary or back-up version.

    When the split heals, Hazelcast by default, performs a PutIfAbsentMergePolicy. Users can also decide to specify their own map merge policies, these policies when used in concert with CRDTs (Convergent and Commutative Replicated Data Types) can ensure against data loss during a split-brain.

    As a defensive mechanism against such inconsistency, consider using the in-built split-brain protection for IMap. Using this functionality it is possible to restrict operations in smaller partitioned clusters. It should be noted that there is still an inconsistency window between the time of the split and the actual detection. Therefore using this reduces the window of inconsistency but can never completely eliminate it.

    Interactions with the map store

    Maps can be configured to be backed by a map store to persist the entries. In this case many of the IMap methods call MapLoader or MapStore methods to load, store or remove data. Each method's javadoc describes the way of its interaction with the map store.

    Expiration and eviction

    Expiration puts a limit on the maximum lifetime of an entry stored inside the map. When the entry expires it can't be retrieved from the map any longer and at some point in time it will be cleaned out from the map to free up the memory. There are two expiration policies:

    • The time-to-live (TTL) expiration policy limits the lifetime of the entry relative to the time of the last write access performed on the entry. The default TTL value for the map may be configured using the time-to-live-seconds setting, which has an infinite by default. An individual entry may have its own TTL value assigned using one of the methods accepting a TTL value, for instance using the put method. If there is no TTL value provided for the individual entry, it inherits the value set in the map configuration.
    • The max-idle expiration policy limits the lifetime of the entry relative to the time of the last read or write access performed on the entry. The max-idle value for the map may be configured using the max-idle-seconds setting, which has an infinite value by default.

    Both expiration policies may be used simultaneously on the map entries. In such case, the entry is considered expired if at least one of the policies marks it as expired.

    Eviction puts a limit on the maximum size of the map. If the size of the map grows larger than the maximum allowed size, an eviction policy decides which item to evict from the map to reduce its size. The maximum allowed size may be configured using the max-size setting and the eviction policy may be configured using the eviction-policy setting as well. By default, maps have no restrictions on the size and may grow arbitrarily large.

    Eviction may be enabled along with the expiration policies. In such case, the expiration policies continue to work as usual cleaning out the expired entries regardless of the map size.

    Locked map entries are not the subjects for the expiration and eviction policies.

    Mutating methods without TTL

    Certain IMap methods perform the entry set mutation and don't accept TTL as a parameter. Entries created or updated by such methods are subjects for the following TTL calculation procedure:

    • If the entry is new, i.e. the entry was created, it receives the default TTL value configured for the map using the time-to-live-seconds configuration setting. If this setting is not provided for the map, the entry receives an infinite TTL value.
    • If the entry already exists, i.e. the entry was updated, its TTL value remains unchanged and its lifetime is prolonged by this TTL value.
    The methods to which this procedure applies: put, set, putAsync, setAsync, tryPut, putAll, setAll, putAllAsync, setAllAsync, replace(Object, Object, Object) and replace(Object, Object).

    Asynchronous methods

    Asynchronous methods return a CompletionStage that can be used to chain further computation stages. Alternatively, a CompletableFuture can be obtained via CompletionStage.toCompletableFuture() to wait for the operation to complete in a blocking way.

    Actions supplied for dependent completions of default non-async methods and async methods without an explicit Executor argument are performed by the ForkJoinPool.commonPool() (unless it does not support a parallelism level of at least 2, in which case a new Thread is created per task).

    See Also:
    ConcurrentMap
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      java.util.UUID addEntryListener​(MapListener listener, boolean includeValue)
      Adds a MapListener for this map.
      java.util.UUID addEntryListener​(MapListener listener, Predicate<K,​V> predicate, boolean includeValue)
      Adds a MapListener for this map.
      java.util.UUID addEntryListener​(MapListener listener, Predicate<K,​V> predicate, K key, boolean includeValue)
      Adds a MapListener for this map.
      java.util.UUID addEntryListener​(MapListener listener, K key, boolean includeValue)
      Adds a MapListener for this map.
      void addIndex​(IndexConfig indexConfig)
      Adds an index to this map for the specified entries so that queries can run faster.
      default void addIndex​(IndexType type, java.lang.String... attributes)
      Convenient method to add an index to this map with the given type and attributes.
      java.lang.String addInterceptor​(MapInterceptor interceptor)
      Adds an interceptor for this map.
      java.util.UUID addLocalEntryListener​(MapListener listener)
      Adds a MapListener for this map.
      java.util.UUID addLocalEntryListener​(MapListener listener, Predicate<K,​V> predicate, boolean includeValue)
      Adds a MapListener for this map.
      java.util.UUID addLocalEntryListener​(MapListener listener, Predicate<K,​V> predicate, K key, boolean includeValue)
      Adds a local entry listener for this map.
      java.util.UUID addPartitionLostListener​(MapPartitionLostListener listener)
      Adds a MapPartitionLostListener.
      <R> R aggregate​(Aggregator<? super java.util.Map.Entry<K,​V>,​R> aggregator)
      Applies the aggregation logic on all map entries and returns the result
      <R> R aggregate​(Aggregator<? super java.util.Map.Entry<K,​V>,​R> aggregator, Predicate<K,​V> predicate)
      Applies the aggregation logic on map entries filtered with the Predicated and returns the result
      void clear()
      Clears the map and deletes the items from the backing map store.
      V compute​(K key, java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction)
      V computeIfAbsent​(K key, java.util.function.Function<? super K,​? extends V> mappingFunction)
      V computeIfPresent​(K key, java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction)
      boolean containsKey​(java.lang.Object key)
      Returns true if this map contains an entry for the specified key.
      boolean containsValue​(java.lang.Object value)
      void delete​(java.lang.Object key)
      Removes the mapping for the key from this map if it is present.
      java.util.concurrent.CompletionStage<java.lang.Boolean> deleteAsync​(K key)
      Asynchronously removes the given key, returning an CompletionStage on which the caller can register further computation stages to be invoked upon delete operation completion or block waiting for the operation to complete using one of blocking ways to wait on CompletionStage.toCompletableFuture().
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
      Returns an immutable Set clone of the mappings contained in this map.
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet​(Predicate<K,​V> predicate)
      Queries the map based on the specified predicate and returns an immutable set of the matching entries.
      boolean evict​(K key)
      Evicts the specified key from this map.
      void evictAll()
      Evicts all keys from this map except the locked ones.
      <R> java.util.Map<K,​R> executeOnEntries​(EntryProcessor<K,​V,​R> entryProcessor)
      Applies the user defined EntryProcessor to the all entries in the map.
      <R> java.util.Map<K,​R> executeOnEntries​(EntryProcessor<K,​V,​R> entryProcessor, Predicate<K,​V> predicate)
      Applies the user defined EntryProcessor to the entries in the map which satisfy provided predicate.
      <R> R executeOnKey​(K key, EntryProcessor<K,​V,​R> entryProcessor)
      Applies the user defined EntryProcessor to the entry mapped by the key.
      <R> java.util.Map<K,​R> executeOnKeys​(java.util.Set<K> keys, EntryProcessor<K,​V,​R> entryProcessor)
      Applies the user defined EntryProcessor to the entries mapped by the collection of keys.
      void flush()
      If this map has a MapStore, this method flushes all the local dirty entries.
      void forceUnlock​(K key)
      Releases the lock for the specified key regardless of the lock owner.
      default void forEach​(java.util.function.BiConsumer<? super K,​? super V> action)
      V get​(java.lang.Object key)
      Returns the value for the specified key, or null if this map does not contain this key.
      java.util.Map<K,​V> getAll​(java.util.Set<K> keys)
      Returns an immutable map of entries for the given keys.
      java.util.concurrent.CompletionStage<V> getAsync​(K key)
      Asynchronously gets the given key.
      EntryView<K,​V> getEntryView​(K key)
      Returns the EntryView for the specified key.
      LocalMapStats getLocalMapStats()
      Returns LocalMapStats for this map.
      QueryCache<K,​V> getQueryCache​(java.lang.String name)
      Returns corresponding QueryCache instance for the supplied name or null.
      QueryCache<K,​V> getQueryCache​(java.lang.String name, MapListener listener, Predicate<K,​V> predicate, boolean includeValue)
      Creates an always up to date snapshot of this IMap according to the supplied parameters.
      QueryCache<K,​V> getQueryCache​(java.lang.String name, Predicate<K,​V> predicate, boolean includeValue)
      Creates an always up to date snapshot of this IMap according to the supplied parameters.
      boolean isLocked​(K key)
      Checks the lock for the specified key.
      java.util.Iterator<java.util.Map.Entry<K,​V>> iterator()
      Returns an iterator over the entries of the map.
      java.util.Iterator<java.util.Map.Entry<K,​V>> iterator​(int fetchSize)
      Returns an iterator over the entries of the map.
      java.util.Set<K> keySet()
      Returns an immutable set clone of the keys contained in this map.
      java.util.Set<K> keySet​(Predicate<K,​V> predicate)
      Queries the map based on the specified predicate and returns an immutable Set clone of the keys of matching entries.
      void loadAll​(boolean replaceExistingValues)
      Loads all keys into the store.
      void loadAll​(java.util.Set<K> keys, boolean replaceExistingValues)
      Loads the given keys.
      java.util.Set<K> localKeySet()
      Returns the locally owned immutable set of keys.
      java.util.Set<K> localKeySet​(Predicate<K,​V> predicate)
      Returns an immutable set of the keys of matching locally owned entries.
      java.util.Collection<V> localValues()
      Returns an immutable collection locally owned values contained in this map.
      java.util.Collection<V> localValues​(Predicate<K,​V> predicate)
      Queries the map of locally owned keys based on the specified predicate and returns an immutable collection of the values of matching entries.
      void lock​(K key)
      Acquires the lock for the specified key.
      void lock​(K key, long leaseTime, java.util.concurrent.TimeUnit timeUnit)
      Acquires the lock for the specified key for the specified lease time.
      V merge​(K key, V value, java.util.function.BiFunction<? super V,​? super V,​? extends V> remappingFunction)
      <R> java.util.Collection<R> project​(Projection<? super java.util.Map.Entry<K,​V>,​R> projection)
      Applies the projection logic on all map entries and returns the result
      <R> java.util.Collection<R> project​(Projection<? super java.util.Map.Entry<K,​V>,​R> projection, Predicate<K,​V> predicate)
      Applies the projection logic on map entries filtered with the Predicated and returns the result
      V put​(K key, V value)
      Associates the specified value with the specified key in this map.
      V put​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit)
      Puts an entry into this map with a given TTL (time to live) value.
      V put​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
      Puts an entry into this map with a given TTL (time to live) value and max idle time value.
      void putAll​(java.util.Map<? extends K,​? extends V> m)
      java.util.concurrent.CompletionStage<java.lang.Void> putAllAsync​(java.util.Map<? extends K,​? extends V> map)
      Asynchronously copies all of the mappings from the specified map to this map.
      java.util.concurrent.CompletionStage<V> putAsync​(K key, V value)
      Asynchronously puts the given key and value.
      java.util.concurrent.CompletionStage<V> putAsync​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit)
      Asynchronously puts the given key and value into this map with a given TTL (time to live) value.
      java.util.concurrent.CompletionStage<V> putAsync​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
      Asynchronously puts the given key and value into this map with a given TTL (time to live) value and max idle time value.
      V putIfAbsent​(K key, V value)
      If the specified key is not already associated with a value, associate it with the given value.
      V putIfAbsent​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit)
      Puts an entry into this map with a given TTL (time to live) value, if the specified key is not already associated with a value.
      V putIfAbsent​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
      Puts an entry into this map with a given TTL (time to live) value and max idle time value.
      void putTransient​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit)
      Same as put(Object, Object, long, TimeUnit) except that the map store, if defined, will not be called to load/store/persist the entry.
      void putTransient​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
      Same as put(Object, Object, long, TimeUnit) except that the map store, if defined, will not be called to load/store/persist the entry.
      V remove​(java.lang.Object key)
      Removes the mapping for a key from this map if it is present.
      boolean remove​(java.lang.Object key, java.lang.Object value)
      Removes the entry for a key only if currently mapped to a given value.
      void removeAll​(Predicate<K,​V> predicate)
      Removes all entries which match with the supplied predicate.
      java.util.concurrent.CompletionStage<V> removeAsync​(K key)
      Asynchronously removes the given key, returning an CompletionStage on which the caller can register further computation stages to be invoked upon remove operation completion or block waiting for the operation to complete using one of blocking ways to wait on CompletionStage.toCompletableFuture().
      boolean removeEntryListener​(java.util.UUID id)
      Removes the specified entry listener.
      boolean removeInterceptor​(java.lang.String id)
      Removes the given interceptor for this map, so it will not intercept operations anymore.
      boolean removePartitionLostListener​(java.util.UUID id)
      Removes the specified map partition lost listener.
      V replace​(K key, V value)
      Replaces the entry for a key only if it is currently mapped to some value.
      boolean replace​(K key, V oldValue, V newValue)
      Replaces the entry for a key only if currently mapped to a given value.
      default void replaceAll​(java.util.function.BiFunction<? super K,​? super V,​? extends V> function)
      void set​(K key, V value)
      Puts an entry into this map without returning the old value (which is more efficient than put()).
      void set​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit)
      Puts an entry into this map with a given TTL (time to live) value, without returning the old value (which is more efficient than put()).
      void set​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
      Puts an entry into this map with a given TTL (time to live) value and max idle time value without returning the old value (which is more efficient than put()).
      void setAll​(java.util.Map<? extends K,​? extends V> map)
      Copies all of the mappings from the specified map to this map without loading non-existing elements from map store (which is more efficient than putAll()).
      java.util.concurrent.CompletionStage<java.lang.Void> setAllAsync​(java.util.Map<? extends K,​? extends V> map)
      Asynchronously copies all of the mappings from the specified map to this map without loading non-existing elements from map store.
      java.util.concurrent.CompletionStage<java.lang.Void> setAsync​(K key, V value)
      Asynchronously puts the given key and value.
      java.util.concurrent.CompletionStage<java.lang.Void> setAsync​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit)
      Asynchronously puts an entry into this map with a given TTL (time to live) value, without returning the old value (which is more efficient than put()).
      java.util.concurrent.CompletionStage<java.lang.Void> setAsync​(K key, V value, long ttl, java.util.concurrent.TimeUnit ttlUnit, long maxIdle, java.util.concurrent.TimeUnit maxIdleUnit)
      Asynchronously puts an entry into this map with a given TTL (time to live) value and max idle time value without returning the old value (which is more efficient than put()).
      boolean setTtl​(K key, long ttl, java.util.concurrent.TimeUnit timeunit)
      Updates the TTL (time to live) value of the entry specified by key with a new TTL value.
      <R> java.util.concurrent.CompletionStage<R> submitToKey​(K key, EntryProcessor<K,​V,​R> entryProcessor)
      Applies the user defined EntryProcessor to the entry mapped by the key.
      <R> java.util.concurrent.CompletionStage<java.util.Map<K,​R>> submitToKeys​(java.util.Set<K> keys, EntryProcessor<K,​V,​R> entryProcessor)
      boolean tryLock​(K key)
      Tries to acquire the lock for the specified key.
      boolean tryLock​(K key, long time, java.util.concurrent.TimeUnit timeunit)
      Tries to acquire the lock for the specified key.
      boolean tryLock​(K key, long time, java.util.concurrent.TimeUnit timeunit, long leaseTime, java.util.concurrent.TimeUnit leaseTimeunit)
      Tries to acquire the lock for the specified key for the specified lease time.
      boolean tryPut​(K key, V value, long timeout, java.util.concurrent.TimeUnit timeunit)
      Tries to put the given key and value into this map within a specified timeout value.
      boolean tryRemove​(K key, long timeout, java.util.concurrent.TimeUnit timeunit)
      Tries to remove the entry with the given key from this map within the specified timeout value.
      void unlock​(K key)
      Releases the lock for the specified key.
      java.util.Collection<V> values()
      Returns an immutable collection clone of the values contained in this map.
      java.util.Collection<V> values​(Predicate<K,​V> predicate)
      Queries the map based on the specified predicate and returns an immutable collection of the values of matching entries.
      • Methods inherited from interface java.util.concurrent.ConcurrentMap

        getOrDefault
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface java.util.Map

        equals, hashCode, isEmpty, size
    • Method Detail

      • putAll

        void putAll​(@Nonnull
                    java.util.Map<? extends K,​? extends V> m)

        No atomicity guarantees are given. It could be that in case of failure some of the key/value-pairs get written, while others are not.

        Interactions with the map store

        For each element not found in memory MapLoader.load(Object) is invoked to load the value from the map store backing the map, which may come at a significant performance cost. Exceptions thrown by load fail the operation and are propagated to the caller. The elements which were added before the exception was thrown will remain in the map, the rest will not be added.

        If write-through persistence mode is configured, MapStore.store(Object, Object) is invoked for each element before the element is added in memory, which may come at a significant performance cost. Exceptions thrown by store fail the operation and are propagated to the caller. The elements which were added before the exception was thrown will remain in the map, the rest will not be added.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        putAll in interface java.util.Map<K,​V>
      • containsKey

        boolean containsKey​(@Nonnull
                            java.lang.Object key)
        Returns true if this map contains an entry for the specified key.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If key is not found in memory MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        Specified by:
        containsKey in interface BaseMap<K,​V>
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Parameters:
        key - The specified key.
        Returns:
        true if this map contains an entry for the specified key.
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • containsValue

        boolean containsValue​(@Nonnull
                              java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
        Throws:
        java.lang.NullPointerException - if the specified value is null
      • get

        V get​(@Nonnull
              java.lang.Object key)
        Returns the value for the specified key, or null if this map does not contain this key.

        Warning 1:

        This method returns a clone of the original value, so modifying the returned value does not change the actual value in the map. You should put the modified value back to make changes visible to all nodes.

              V value = map.get(key);
              value.updateSomeProperty();
              map.put(key, value);
         

        Warning 2:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If value with key is not found in memory MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        Specified by:
        get in interface BaseMap<K,​V>
        Specified by:
        get in interface java.util.Map<K,​V>
        Parameters:
        key - The specified key.
        Returns:
        The value for the specified key.
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • put

        V put​(@Nonnull
              K key,
              @Nonnull
              V value)
        Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced by the specified value.

        Warning 1:

        This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.

        Warning 2:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Note: Use set(Object, Object) if you don't need the return value, it's slightly more efficient.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        put in interface BaseMap<K,​V>
        Specified by:
        put in interface java.util.Map<K,​V>
        Parameters:
        key - The specified key.
        value - The value to associate with the key.
        Returns:
        Previous value associated with key or null if there was no mapping for key.
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • remove

        V remove​(@Nonnull
                 java.lang.Object key)
        Removes the mapping for a key from this map if it is present.

        If you don't need the previously mapped value for the removed key, prefer to use delete(java.lang.Object) and avoid the cost of serialization and network transfer.

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is removed from the memory, MapStore.delete(Object) is called to remove the value from the map store. Exceptions thrown by delete fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        remove in interface BaseMap<K,​V>
        Specified by:
        remove in interface java.util.Map<K,​V>
        Parameters:
        key - Remove the mapping for this key.
        Returns:
        The previous value associated with key, or null if there was no mapping for key.
        Throws:
        java.lang.NullPointerException - if the specified key is null
        See Also:
        delete(Object)
      • remove

        boolean remove​(@Nonnull
                       java.lang.Object key,
                       @Nonnull
                       java.lang.Object value)
        Removes the entry for a key only if currently mapped to a given value. This is equivalent to
           if (map.containsKey(key) && map.get(key).equals(value)) {
               map.remove(key);
               return true;
           } else return false;
        except that the action is performed atomically.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is removed from the memory, MapStore.delete(Object) is called to remove the value from the map store. Exceptions thrown by delete fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        remove in interface BaseMap<K,​V>
        Specified by:
        remove in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        remove in interface java.util.Map<K,​V>
        Parameters:
        key - The specified key.
        value - Remove the key if it has this value.
        Returns:
        true if the value was removed.
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • removeAll

        void removeAll​(@Nonnull
                       Predicate<K,​V> predicate)
        Removes all entries which match with the supplied predicate.

        If this map has index, matching entries will be found via index search, otherwise they will be found by full-scan.

        Note that calling this method also removes all entries from caller's Near Cache.

        Interactions with the map store

        If write-through persistence mode is configured, before a value is removed from the memory, MapStore.delete(Object) is called to remove the value from the map store. Exceptions thrown by delete fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        predicate - matching entries with this predicate will be removed from this map
        Throws:
        java.lang.NullPointerException - if the specified predicate is null
        java.lang.IllegalArgumentException - if the predicate is a PagingPredicate or is a PartitionPredicate that includes a PagingPredicate
      • delete

        void delete​(@Nonnull
                    java.lang.Object key)
        Removes the mapping for the key from this map if it is present.

        Unlike remove(Object), this operation does not return the removed value, which avoids the serialization and network transfer cost of the returned value. If the removed value will not be used, this operation is preferred over the remove operation for better performance.

        The map will not contain a mapping for the specified key once the call returns.

        Warning:

        This method breaks the contract of EntryListener. When an entry is removed by delete(), it fires an EntryEvent with a null oldValue.

        Also, a listener with predicates will have null values, so only keys can be queried via predicates.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is removed from the the memory, MapStore.delete(Object) is called to remove the value from the map store. Exceptions thrown by delete fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        delete in interface BaseMap<K,​V>
        Parameters:
        key - key whose mapping is to be removed from the map
        Throws:
        java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional)
        java.lang.NullPointerException - if the specified key is null
        See Also:
        remove(Object)
      • flush

        void flush()
        If this map has a MapStore, this method flushes all the local dirty entries.

        Interactions with the map store

        Calls MapStore.storeAll(Map) and/or MapStore.deleteAll(Collection) with elements marked dirty.

        Please note that this method has effect only if write-behind persistence mode is configured. If the persistence mode is write-through calling this method has no practical effect, but an operation is executed on all partitions wasting resources.

      • getAll

        java.util.Map<K,​V> getAll​(@Nullable
                                        java.util.Set<K> keys)
        Returns an immutable map of entries for the given keys.

        Warning 1:

        The returned map is NOT backed by the original map, so changes to the original map are NOT reflected in the returned map.

        Warning 2:

        This method uses hashCode and equals of the binary form of the keys, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If any keys are not found in memory, MapLoader.loadAll(java.util.Collection<K>) is called with the missing keys. Exceptions thrown by loadAll fail the operation and are propagated to the caller.

        Parameters:
        keys - keys to get (keys inside the collection cannot be null)
        Returns:
        an immutable map of entries
        Throws:
        java.lang.NullPointerException - if any of the specified keys are null or if any key or any value returned from MapLoader.loadAll(java.util.Collection<K>) is null.
      • loadAll

        void loadAll​(boolean replaceExistingValues)
        Loads all keys into the store. This is a batch load operation so that an implementation can optimize multiple loads.

        Interactions with the map store

        Calls MapLoader.loadAllKeys() and with the loaded keys calls MapLoader.loadAll(java.util.Collection) on each partition. Exceptions thrown by loadAllKeys() or loadAll() are not propagated to the caller.

        Parameters:
        replaceExistingValues - when true, existing values in the Map will be replaced by those loaded from the MapLoader
        Since:
        3.3
      • loadAll

        void loadAll​(@Nonnull
                     java.util.Set<K> keys,
                     boolean replaceExistingValues)
        Loads the given keys. This is a batch load operation so that an implementation can optimize multiple loads.

        Interactions with the map store

        Calls MapLoader.loadAll(java.util.Collection) on the partitions storing the values with the keys. Exceptions thrown by loadAll() are not propagated to the caller.

        Parameters:
        keys - keys of the values entries to load (keys inside the collection cannot be null)
        replaceExistingValues - when true, existing values in the Map will be replaced by those loaded from the MapLoader
        Since:
        3.3
      • clear

        void clear()
        Clears the map and deletes the items from the backing map store.

        The MAP_CLEARED event is fired for any registered listeners. See MapClearedListener.mapCleared(MapEvent).

        To clear the map without removing the items from the map store, use evictAll().

        Interactions with the map store

        Calls MapStore.deleteAll(Collection) on each partition with the keys that the given partition stores. Exceptions thrown by deleteAll() are not propagated to the caller.

        Specified by:
        clear in interface java.util.Map<K,​V>
        See Also:
        evictAll()
      • getAsync

        java.util.concurrent.CompletionStage<V> getAsync​(@Nonnull
                                                         K key)
        Asynchronously gets the given key. CompletionStage can be converted to a CompletableFuture to obtain the value in a blocking way:
           CompletionStage future = map.getAsync(key);
           // do some other stuff, when ready get the result.
           Object value = future.toCompletableFuture().get();
         
        Additionally, the client can register further computation stages to be invoked upon completion of the CompletionStage via any of CompletionStage methods:
        
           // assuming an IMap<String, String>
           CompletionStage<String> future = map.getAsync("a");
           future.thenAcceptAsync(response -> System.out.println(response));
         

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If value with key is not found in memory MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        Parameters:
        key - the key of the map entry
        Returns:
        CompletionStage from which the value of the key can be retrieved
        Throws:
        java.lang.NullPointerException - if the specified key is null
        See Also:
        CompletionStage
      • putAsync

        java.util.concurrent.CompletionStage<V> putAsync​(@Nonnull
                                                         K key,
                                                         @Nonnull
                                                         V value)
        Asynchronously puts the given key and value. CompletionStage can be converted to a CompletableFuture to obtain the value in a blocking way:
        
           CompletionStage<Object> future = map.putAsync(key, value);
           // do some other stuff, when ready get the result.
           Object oldValue = future.toCompletableFuture().get();
         
        Additionally, the client can register further computation stages to be invoked upon completion of the CompletionStage via any of CompletionStage methods:
        
           // assuming an IMap<String, String>
           CompletionStage<String> future = map.putAsync("a", "b");
           future.whenCompleteAsync((v, throwable) -> {
             if (throwable == null) {
               // do something with the old value returned by put operation
             } else {
               // handle failure
             }
           });
         

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Note: Use setAsync(Object, Object) if you don't need the return value, it's slightly more efficient.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - the key of the map entry
        value - the new value of the map entry
        Returns:
        CompletionStage from which the old value of the key can be retrieved
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
        See Also:
        CompletionStage, setAsync(Object, Object)
      • putAsync

        java.util.concurrent.CompletionStage<V> putAsync​(@Nonnull
                                                         K key,
                                                         @Nonnull
                                                         V value,
                                                         long ttl,
                                                         @Nonnull
                                                         java.util.concurrent.TimeUnit ttlUnit)
        Asynchronously puts the given key and value into this map with a given TTL (time to live) value.

        The entry will expire and get evicted after the TTL. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

           CompletionStage future = map.putAsync(key, value, ttl, timeunit);
           // do some other stuff, when ready get the result
           Object oldValue = future.toCompletableFuture().get();
         
        CompletionStage.toCompletableFuture().get() will block until the actual map.put() completes. If your application requires a timely response, then you can use Future.get(timeout, timeunit).
           try {
             CompletionStage future = map.putAsync(key, newValue, ttl, timeunit);
             Object oldValue = future.toCompletableFuture().get(40, TimeUnit.MILLISECOND);
           } catch (TimeoutException t) {
             // time wasn't enough
           }
         
        The client can register further computation stages to be invoked upon completion of the CompletionStage via any of CompletionStage methods:
        
           // assuming an IMap<String, String>
           CompletionStage<String> future = map.putAsync("a", "b", 5, TimeUnit.MINUTES);
           future.thenAccept(oldVal -> System.out.println(oldVal));
         

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Note: Use setAsync(Object, Object, long, TimeUnit) if you don't need the return value, it's slightly more efficient.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - the key of the map entry
        value - the new value of the map entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        Returns:
        CompletionStage from which the old value of the key can be retrieved
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
        See Also:
        CompletionStage, setAsync(Object, Object, long, TimeUnit)
      • putAsync

        java.util.concurrent.CompletionStage<V> putAsync​(@Nonnull
                                                         K key,
                                                         @Nonnull
                                                         V value,
                                                         long ttl,
                                                         @Nonnull
                                                         java.util.concurrent.TimeUnit ttlUnit,
                                                         long maxIdle,
                                                         @Nonnull
                                                         java.util.concurrent.TimeUnit maxIdleUnit)
        Asynchronously puts the given key and value into this map with a given TTL (time to live) value and max idle time value.

        The entry will expire and get evicted after the TTL. It limits the lifetime of the entries relative to the time of the last write access performed on them. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        The entry will expire and get evicted after the Max Idle time. It limits the lifetime of the entries relative to the time of the last read or write access performed on them. If the MaxIdle is 0, then the entry lives forever. If the MaxIdle is negative, then the MaxIdle from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that is less than 1 second can lead to unexpected behaviour.

           CompletionStage future = map.putAsync(key, value, ttl, timeunit);
           // do some other stuff, when ready get the result
           Object oldValue = future.toCompletableFuture().get();
         
        CompletionStage.toCompletableFuture().get() will block until the actual map.put() completes. If your application requires a timely response, then you can use Future.get(timeout, timeunit).
           try {
             CompletionStage future = map.putAsync(key, newValue, ttl, timeunit);
             Object oldValue = future.toCompletableFuture().get(40, TimeUnit.MILLISECOND);
           } catch (TimeoutException t) {
             // time wasn't enough
           }
         
        The client can register further computation stages to be invoked upon completion of the CompletionStage via any of CompletionStage methods:
        
           // assuming an IMap<String, String>
           CompletionStage<String> future = map.putAsync("a", "b", 5, TimeUnit.MINUTES);
           future.thenAcceptAsync(oldValue -> System.out.println(oldValue));
         

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Note: Use setAsync(Object, Object, long, TimeUnit) if you don't need the return value, it's slightly more efficient.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - the key of the map entry
        value - the new value of the map entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        maxIdle - maximum time for this entry to stay idle in the map. (0 means infinite, negative means map config default)
        maxIdleUnit - time unit for the Max-Idle
        Returns:
        CompletionStage from which the old value of the key can be retrieved
        Throws:
        java.lang.NullPointerException - if the specified key, value, ttlUnit or maxIdleUnit are null
        See Also:
        CompletionStage, setAsync(Object, Object, long, TimeUnit)
      • putAllAsync

        java.util.concurrent.CompletionStage<java.lang.Void> putAllAsync​(@Nonnull
                                                                         java.util.Map<? extends K,​? extends V> map)
        Asynchronously copies all of the mappings from the specified map to this map. This version doesn't support batching.
        
             CompletionStage<Void> future = map.putAllAsync(map);
             // do some other stuff, when ready wait for completion
             future.toCompletableFuture.get();
         
        CompletionStage.toCompletableFuture.get() will block until the actual map.putAll(map) operation completes You can also register further computation stages to be invoked upon completion of the CompletionStage via any of CompletionStage methods:
        
              CompletionStage<Void> future = map.putAllAsync(map);
              future.thenRunAsync(() -> System.out.println("All the entries are added"));
         

        No atomicity guarantees are given. It could be that in case of failure some of the key/value-pairs get written, while others are not.

        Interactions with the map store

        For each element not found in memory MapLoader.load(Object) is invoked to load the value from the map store backing the map, which may come at a significant performance cost. Exceptions thrown by load fail the operation and are propagated to the caller. The elements which were added before the exception was thrown will remain in the map, the rest will not be added.

        If write-through persistence mode is configured, MapStore.store(Object, Object) is invoked for each element before the element is added in memory, which may come at a significant performance cost. Exceptions thrown by store fail the operation and are propagated to the caller. The elements which were added before the exception was thrown will remain in the map, the rest will not be added.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        map - mappings to be stored in this map
        Returns:
        CompletionStage on which client code can block waiting for the operation to complete or register callbacks to be invoked upon putAll operation completion
        Since:
        4.1
        See Also:
        CompletionStage
      • setAsync

        java.util.concurrent.CompletionStage<java.lang.Void> setAsync​(@Nonnull
                                                                      K key,
                                                                      @Nonnull
                                                                      V value)
        Asynchronously puts the given key and value. The entry lives forever. Similar to the put operation except that set doesn't return the old value, which is more efficient.
        
           CompletionStage<Void> future = map.setAsync(key, value);
           // do some other stuff, when ready wait for completion
           future.toCompletableFuture().get();
         
        CompletionStage.toCompletableFuture().get() will block until the actual map.set() operation completes. You can also register further computation stages to be invoked upon completion of the CompletionStage via any of CompletionStage methods:
        
           CompletionStage<Void> future = map.setAsync("a", "b");
           future.thenRunAsync(() -> System.out.println("Value is now set to b."));
         

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - the key of the map entry
        value - the new value of the map entry
        Returns:
        CompletionStage on which client code can block waiting for the operation to complete or register callbacks to be invoked upon set operation completion
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
        See Also:
        CompletionStage
      • setAsync

        java.util.concurrent.CompletionStage<java.lang.Void> setAsync​(@Nonnull
                                                                      K key,
                                                                      @Nonnull
                                                                      V value,
                                                                      long ttl,
                                                                      @Nonnull
                                                                      java.util.concurrent.TimeUnit ttlUnit)
        Asynchronously puts an entry into this map with a given TTL (time to live) value, without returning the old value (which is more efficient than put()).

        The entry will expire and get evicted after the TTL. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

           CompletionStage<Void> future = map.setAsync(key, value, ttl, timeunit);
           // do some other stuff, when you want to make sure set operation is complete:
           future.toCompletableFuture().get();
         
        CompletionStage.toCompletableFuture().get() will block until the actual map set operation completes. If your application requires a timely response, then you can use CompletionStage.toCompletableFuture().get(long, TimeUnit).
           try {
             CompletionStage<Void> future = map.setAsync(key, newValue, ttl, timeunit);
             future.toCompletableFuture().get(40, TimeUnit.MILLISECOND);
           } catch (TimeoutException t) {
             // time wasn't enough
           }
         
        You can also register further computation stages to be invoked upon completion of the CompletionStage via any of CompletionStage methods:
           CompletionStage<Void> future = map.setAsync("a", "b", 5, TimeUnit.MINUTES);
           future.thenRunAsync(() -> System.out.println("done"));
         

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - the key of the map entry
        value - the new value of the map entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        Returns:
        CompletionStage on which client code can block waiting for the operation to complete or register callbacks to be invoked upon set operation completion
        Throws:
        java.lang.NullPointerException - if the specified key, value, ttlUnit
        See Also:
        CompletionStage
      • setAsync

        java.util.concurrent.CompletionStage<java.lang.Void> setAsync​(@Nonnull
                                                                      K key,
                                                                      @Nonnull
                                                                      V value,
                                                                      long ttl,
                                                                      @Nonnull
                                                                      java.util.concurrent.TimeUnit ttlUnit,
                                                                      long maxIdle,
                                                                      @Nonnull
                                                                      java.util.concurrent.TimeUnit maxIdleUnit)
        Asynchronously puts an entry into this map with a given TTL (time to live) value and max idle time value without returning the old value (which is more efficient than put()).

        The entry will expire and get evicted after the TTL. It limits the lifetime of the entries relative to the time of the last write access performed on them. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        The entry will expire and get evicted after the Max Idle time. It limits the lifetime of the entries relative to the time of the last read or write access performed on them. If the MaxIdle is 0, then the entry lives forever. If the MaxIdle is negative, then the MaxIdle from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that less than 1 second can lead to unexpected behaviour.

           CompletionStage<Void> future = map.setAsync(key, value, ttl, timeunit);
           // do some other stuff, when you want to make sure set operation is complete:
           future.toCompletableFuture().get();
         
        CompletionStage.toCompletableFuture().get() will block until the actual map set operation completes. If your application requires a timely response, then you can use CompletionStage.toCompletableFuture().get(long, TimeUnit).
           try {
             CompletionStage<Void> future = map.setAsync(key, newValue, ttl, timeunit);
             future.toCompletableFuture().get(40, TimeUnit.MILLISECOND);
           } catch (TimeoutException t) {
             // time wasn't enough
           }
         
        You can also register further computation stages to be invoked upon completion of the CompletionStage via any of CompletionStage methods:
           CompletionStage<Void> future = map.setAsync("a", "b", 5, TimeUnit.MINUTES);
           future.thenRunAsync(() -> System.out.println("Done"));
         

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - the key of the map entry
        value - the new value of the map entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        maxIdle - maximum time for this entry to stay idle in the map. (0 means infinite, negative means map config default)
        maxIdleUnit - time unit for the Max-Idle
        Returns:
        CompletionStage on which client code can block waiting for the operation to complete or register callbacks to be invoked upon set operation completion
        Throws:
        java.lang.NullPointerException - if the specified key, value, ttlUnit or maxIdleUnit are null
        See Also:
        CompletionStage
      • removeAsync

        java.util.concurrent.CompletionStage<V> removeAsync​(@Nonnull
                                                            K key)
        Asynchronously removes the given key, returning an CompletionStage on which the caller can register further computation stages to be invoked upon remove operation completion or block waiting for the operation to complete using one of blocking ways to wait on CompletionStage.toCompletableFuture().

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is removed from the the memory, MapStore.delete(Object) is called to remove the value from the map store. Exceptions thrown by delete fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - The key of the map entry to remove
        Returns:
        CompletionStage from which the value removed from the map can be retrieved
        Throws:
        java.lang.NullPointerException - if the specified key is null
        See Also:
        CompletionStage
      • deleteAsync

        java.util.concurrent.CompletionStage<java.lang.Boolean> deleteAsync​(@Nonnull
                                                                            K key)
        Asynchronously removes the given key, returning an CompletionStage on which the caller can register further computation stages to be invoked upon delete operation completion or block waiting for the operation to complete using one of blocking ways to wait on CompletionStage.toCompletableFuture().

        Unlike removeAsync(Object), this operation does not return the removed value, which avoids the serialization and network transfer cost of the returned value. If the removed value will not be used, this operation is preferred over the removeAsync operation for better performance.

        The returned CompletionStage completes with a boolean value: true if the key is in memory and deletion is successful, false otherwise.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is removed from the memory, MapStore.delete(Object) is called to remove the value from the map store. Exceptions thrown by delete fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - The key of the map entry to remove
        Returns:
        CompletionStage which completes with a boolean value, indicating the result of the deletion
        Throws:
        java.lang.NullPointerException - if the specified key is null
        See Also:
        CompletionStage
      • tryRemove

        boolean tryRemove​(@Nonnull
                          K key,
                          long timeout,
                          @Nonnull
                          java.util.concurrent.TimeUnit timeunit)
        Tries to remove the entry with the given key from this map within the specified timeout value. If the key is already locked by another thread and/or member, then this operation will wait the timeout amount for acquiring the lock.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is removed from the the memory, MapStore.delete(Object) is called to remove the value from the map store. Exceptions thrown by delete fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - key of the entry
        timeout - maximum time to wait for acquiring the lock for the key
        timeunit - time unit for the timeout
        Returns:
        true if the remove is successful, false otherwise
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • tryPut

        boolean tryPut​(@Nonnull
                       K key,
                       @Nonnull
                       V value,
                       long timeout,
                       @Nonnull
                       java.util.concurrent.TimeUnit timeunit)
        Tries to put the given key and value into this map within a specified timeout value. If this method returns false, it means that the caller thread could not acquire the lock for the key within the timeout duration, thus the put operation is not successful.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - key of the entry
        value - value of the entry
        timeout - maximum time to wait
        timeunit - time unit for the timeout
        Returns:
        true if the put is successful, false otherwise
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • put

        V put​(@Nonnull
              K key,
              @Nonnull
              V value,
              long ttl,
              @Nonnull
              java.util.concurrent.TimeUnit ttlUnit)
        Puts an entry into this map with a given TTL (time to live) value.

        The entry will expire and get evicted after the TTL. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.

        Warning 3:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Note: Use set(Object, Object, long, TimeUnit) if you don't need the return value, it's slightly more efficient.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        put in interface BaseMap<K,​V>
        Parameters:
        key - key of the entry
        value - value of the entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        Returns:
        old value of the entry
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • put

        V put​(@Nonnull
              K key,
              @Nonnull
              V value,
              long ttl,
              @Nonnull
              java.util.concurrent.TimeUnit ttlUnit,
              long maxIdle,
              @Nonnull
              java.util.concurrent.TimeUnit maxIdleUnit)
        Puts an entry into this map with a given TTL (time to live) value and max idle time value.

        The entry will expire and get evicted after the TTL. It limits the lifetime of the entries relative to the time of the last write access performed on them. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        The entry will expire and get evicted after the Max Idle time. It limits the lifetime of the entries relative to the time of the last read or write access performed on them. If the MaxIdle is 0, then the entry lives forever. If the MaxIdle is negative, then the MaxIdle from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that less than 1 second can lead to unexpected behaviour.

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.

        Warning 3:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Note: Use set(Object, Object, long, TimeUnit) if you don't need the return value, it's slightly more efficient.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - key of the entry
        value - value of the entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        maxIdle - maximum time for this entry to stay idle in the map. (0 means infinite, negative means map config default)
        maxIdleUnit - time unit for the Max-Idle
        Returns:
        old value of the entry
        Throws:
        java.lang.NullPointerException - if the specified key, value, ttlUnit or maxIdleUnit are null
      • putTransient

        void putTransient​(@Nonnull
                          K key,
                          @Nonnull
                          V value,
                          long ttl,
                          @Nonnull
                          java.util.concurrent.TimeUnit ttlUnit)
        Same as put(Object, Object, long, TimeUnit) except that the map store, if defined, will not be called to load/store/persist the entry.

        The entry will expire and get evicted after the TTL. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        Time resolution for TTL is seconds. The given TTL value is rounded to next closest second value.

        Parameters:
        key - key of the entry
        value - value of the entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • putTransient

        void putTransient​(@Nonnull
                          K key,
                          @Nonnull
                          V value,
                          long ttl,
                          @Nonnull
                          java.util.concurrent.TimeUnit ttlUnit,
                          long maxIdle,
                          @Nonnull
                          java.util.concurrent.TimeUnit maxIdleUnit)
        Same as put(Object, Object, long, TimeUnit) except that the map store, if defined, will not be called to load/store/persist the entry.

        The entry will expire and get evicted after the TTL. It limits the lifetime of the entries relative to the time of the last write access performed on them. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        The entry will expire and get evicted after the Max Idle time. It limits the lifetime of the entries relative to the time of the last read or write access performed on them. If the MaxIdle is 0, then the entry lives forever. If the MaxIdle is negative, then the MaxIdle from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that less than 1 second can lead to unexpected behaviour.

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        Time resolution for TTL is seconds. The given TTL value is rounded to next closest second value.

        Parameters:
        key - key of the entry
        value - value of the entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        maxIdle - maximum time for this entry to stay idle in the map. (0 means infinite, negative means map config default)
        maxIdleUnit - time unit for the Max-Idle
        Throws:
        java.lang.NullPointerException - if the specified key, value, ttlUnit or maxIdleUnit are null
      • putIfAbsent

        V putIfAbsent​(@Nonnull
                      K key,
                      @Nonnull
                      V value)
        If the specified key is not already associated with a value, associate it with the given value. This is equivalent to
           if (!map.containsKey(key))
               return map.put(key, value);
           else
               return map.get(key);
        except that the action is performed atomically.

        Note:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Also, this method returns a clone of the previous value, not the original (identically equal) value previously put into the map.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        putIfAbsent in interface BaseMap<K,​V>
        Specified by:
        putIfAbsent in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        putIfAbsent in interface java.util.Map<K,​V>
        Parameters:
        key - The specified key.
        value - The value to associate with the key when there is no previous value.
        Returns:
        a clone of the previous value
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • putIfAbsent

        V putIfAbsent​(@Nonnull
                      K key,
                      @Nonnull
                      V value,
                      long ttl,
                      @Nonnull
                      java.util.concurrent.TimeUnit ttlUnit)
        Puts an entry into this map with a given TTL (time to live) value, if the specified key is not already associated with a value.

        The entry will expire and get evicted after the TTL. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.

        Warning 3:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - key of the entry
        value - value of the entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        Returns:
        old value of the entry
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • putIfAbsent

        V putIfAbsent​(@Nonnull
                      K key,
                      @Nonnull
                      V value,
                      long ttl,
                      @Nonnull
                      java.util.concurrent.TimeUnit ttlUnit,
                      long maxIdle,
                      @Nonnull
                      java.util.concurrent.TimeUnit maxIdleUnit)
        Puts an entry into this map with a given TTL (time to live) value and max idle time value. if the specified key is not already associated with a value.

        The entry will expire and get evicted after the TTL. It limits the lifetime of the entries relative to the time of the last write access performed on them. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        The entry will expire and get evicted after the Max Idle time. It limits the lifetime of the entries relative to the time of the last read or write access performed on them. If the MaxIdle is 0, then the entry lives forever. If the MaxIdle is negative, then the MaxIdle from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that less than 1 second can lead to unexpected behaviour.

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.

        Warning 3:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Interactions with the map store

        If no value is found with key in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - key of the entry
        value - value of the entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        maxIdle - maximum time for this entry to stay idle in the map. (0 means infinite, negative means map config default)
        maxIdleUnit - time unit for the Max-Idle
        Returns:
        old value of the entry
        Throws:
        java.lang.NullPointerException - if the specified key, value, ttlUnit or maxIdleUnit are null
      • replace

        boolean replace​(@Nonnull
                        K key,
                        @Nonnull
                        V oldValue,
                        @Nonnull
                        V newValue)
        Replaces the entry for a key only if currently mapped to a given value. This is equivalent to
           if (map.containsKey(key) && map.get(key).equals(oldValue)) {
               map.put(key, newValue);
               return true;
           } else return false;
        except that the action is performed atomically.

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        This method may return false even if the operation succeeds.
        Background: If the partition owner for given key goes down after successful value replace, but before the executing node retrieved the invocation result response, then the operation is retried. The invocation retry fails because the value is already updated and the result of such replace call returns false. Hazelcast doesn't guarantee exactly once invocation.

        Interactions with the map store

        If value with key is not found in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        replace in interface BaseMap<K,​V>
        Specified by:
        replace in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        replace in interface java.util.Map<K,​V>
        Parameters:
        key - The specified key.
        oldValue - Replace the key value if it is the old value.
        newValue - The new value to replace the old value.
        Returns:
        true if the value was replaced.
        Throws:
        java.lang.NullPointerException - if any of the specified parameters are null
      • replace

        V replace​(@Nonnull
                  K key,
                  @Nonnull
                  V value)
        Replaces the entry for a key only if it is currently mapped to some value. This is equivalent to
           if (map.containsKey(key)) {
               return map.put(key, value);
           } else return null;
        except that the action is performed atomically.

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.

        Interactions with the map store

        If value with key is not found in memory, MapLoader.load(Object) is invoked to load the value from the map store backing the map.

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        replace in interface BaseMap<K,​V>
        Specified by:
        replace in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        replace in interface java.util.Map<K,​V>
        Parameters:
        key - The specified key.
        value - The value to replace the previous value.
        Returns:
        The previous value associated with key, or null if there was no mapping for key.
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • set

        void set​(@Nonnull
                 K key,
                 @Nonnull
                 V value)
        Puts an entry into this map without returning the old value (which is more efficient than put()).

        Warning 1:

        This method breaks the contract of EntryListener. When an entry is updated by set(), it fires an EntryEvent with a null oldValue.

        Warning 2:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Specified by:
        set in interface BaseMap<K,​V>
        Parameters:
        key - key of the entry
        value - value of the entry
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • set

        void set​(@Nonnull
                 K key,
                 @Nonnull
                 V value,
                 long ttl,
                 @Nonnull
                 java.util.concurrent.TimeUnit ttlUnit)
        Puts an entry into this map with a given TTL (time to live) value, without returning the old value (which is more efficient than put()).

        The entry will expire and get evicted after the TTL. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - key of the entry
        value - value of the entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        Throws:
        java.lang.NullPointerException - if the specified key or value is null
      • set

        void set​(@Nonnull
                 K key,
                 @Nonnull
                 V value,
                 long ttl,
                 @Nonnull
                 java.util.concurrent.TimeUnit ttlUnit,
                 long maxIdle,
                 @Nonnull
                 java.util.concurrent.TimeUnit maxIdleUnit)
        Puts an entry into this map with a given TTL (time to live) value and max idle time value without returning the old value (which is more efficient than put()).

        The entry will expire and get evicted after the TTL. It limits the lifetime of the entries relative to the time of the last write access performed on them. If the TTL is 0, then the entry lives forever. If the TTL is negative, then the TTL from the map configuration will be used (default: forever).

        The entry will expire and get evicted after the Max Idle time. It limits the lifetime of the entries relative to the time of the last read or write access performed on them. If the MaxIdle is 0, then the entry lives forever. If the MaxIdle is negative, then the MaxIdle from the map configuration will be used (default: forever). The time precision is limited by 1 second. The MaxIdle that less than 1 second can lead to unexpected behaviour.

        Warning 1:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Warning 2:

        Time resolution for TTL is seconds. The given TTL value is rounded to the next closest second value.

        Interactions with the map store

        If write-through persistence mode is configured, before the value is stored in memory, MapStore.store(Object, Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        key - key of the entry
        value - value of the entry
        ttl - maximum time for this entry to stay in the map (0 means infinite, negative means map config default)
        ttlUnit - time unit for the TTL
        maxIdle - maximum time for this entry to stay idle in the map. (0 means infinite, negative means map config default)
        maxIdleUnit - time unit for the Max-Idle
        Throws:
        java.lang.NullPointerException - if the specified key, value, ttlUnit or maxIdleUnit are null
      • setAll

        void setAll​(@Nonnull
                    java.util.Map<? extends K,​? extends V> map)
        Copies all of the mappings from the specified map to this map without loading non-existing elements from map store (which is more efficient than putAll()).

        This method breaks the contract of EntryListener. EntryEvent of all the updated entries will have null oldValue even if they exist previously.

        No atomicity guarantees are given. It could be that in case of failure some of the key/value-pairs get written, while others are not.

        Interactions with the map store

        If write-through persistence mode is configured, MapStore.store(Object, Object) is invoked for each element before the element is added in memory, which may come at a significant performance cost. Exceptions thrown by store fail the operation and are propagated to the caller. The elements which were added before the exception was thrown will remain in the map, the rest will not be added.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Since:
        4.1
      • setAllAsync

        java.util.concurrent.CompletionStage<java.lang.Void> setAllAsync​(@Nonnull
                                                                         java.util.Map<? extends K,​? extends V> map)
        Asynchronously copies all of the mappings from the specified map to this map without loading non-existing elements from map store. This version doesn't support batching.
        
             CompletionStage<Void> future = map.setAllAsync(map);
             // do some other stuff, when ready wait for completion
             future.toCompletableFuture.get();
         
        CompletionStage.toCompletableFuture.get() will block until the actual map.setAll(map) operation completes You can also register further computation stages to be invoked upon completion of the CompletionStage via any of CompletionStage methods:
        
              CompletionStage<Void> future = map.setAllAsync(map);
              future.thenRunAsync(() -> System.out.println("All the entries are set"));
         

        This method breaks the contract of EntryListener. EntryEvent of all the updated entries will have null oldValue even if they exist previously.

        No atomicity guarantees are given. It could be that in case of failure some of the key/value-pairs get written, while others are not.

        Interactions with the map store

        If write-through persistence mode is configured, MapStore.store(Object, Object) is invoked for each element before the element is added in memory, which may come at a significant performance cost. Exceptions thrown by store fail the operation and are propagated to the caller. The elements which were added before the exception was thrown will remain in the map, the rest will not be added.

        If write-behind persistence mode is configured with write-coalescing turned off, ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.

        Parameters:
        map - mappings to be stored in this map
        Returns:
        CompletionStage on which client code can block waiting for the operation to complete or register callbacks to be invoked upon setAll operation completion
        Since:
        4.1
        See Also:
        CompletionStage
      • lock

        void lock​(@Nonnull
                  K key)
        Acquires the lock for the specified key.

        If the lock is not available, then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.

        You get a lock whether the value is present in the map or not. Other threads (possibly on other systems) would block on their invoke of lock() until the non-existent key is unlocked. If the lock holder introduces the key to the map, the put() operation is not blocked. If a thread not holding a lock on the non-existent key tries to introduce the key while a lock exists on the non-existent key, the put() operation blocks until it is unlocked.

        Scope of the lock is this map only. Acquired lock is only for the key in this map.

        Locks are re-entrant so if the key is locked N times then it should be unlocked N times before another thread can acquire it.

        There is no lock timeout on this method. Locks will be held infinitely.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Parameters:
        key - key to lock
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • lock

        void lock​(@Nonnull
                  K key,
                  long leaseTime,
                  @Nullable
                  java.util.concurrent.TimeUnit timeUnit)
        Acquires the lock for the specified key for the specified lease time.

        After lease time, the lock will be released.

        If the lock is not available, then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.

        Scope of the lock is this map only. Acquired lock is only for the key in this map.

        Locks are re-entrant, so if the key is locked N times then it should be unlocked N times before another thread can acquire it.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Parameters:
        key - the key to lock
        leaseTime - time to wait before releasing the lock
        timeUnit - unit of time to specify lease time
        Throws:
        java.lang.NullPointerException - if the specified key is null
        java.lang.IllegalArgumentException - if the leaseTime is not positive
      • isLocked

        boolean isLocked​(@Nonnull
                         K key)
        Checks the lock for the specified key.

        If the lock is acquired then returns true, else returns false.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Parameters:
        key - the key that is checked for lock
        Returns:
        true if lock is acquired, false otherwise
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • tryLock

        boolean tryLock​(@Nonnull
                        K key)
        Tries to acquire the lock for the specified key.

        If the lock is not available then the current thread doesn't wait and returns false immediately.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Parameters:
        key - the key to lock
        Returns:
        true if lock is acquired, false otherwise
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • tryLock

        boolean tryLock​(@Nonnull
                        K key,
                        long time,
                        @Nullable
                        java.util.concurrent.TimeUnit timeunit)
                 throws java.lang.InterruptedException
        Tries to acquire the lock for the specified key.

        If the lock is not available, then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

        • the lock is acquired by the current thread, or
        • the specified waiting time elapses.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Parameters:
        key - key to lock in this map
        time - maximum time to wait for the lock
        timeunit - time unit of the time argument
        Returns:
        true if the lock was acquired, false if the waiting time elapsed before the lock was acquired
        Throws:
        java.lang.NullPointerException - if the specified key is null
        java.lang.InterruptedException - if interrupted while trying to acquire the lock
      • tryLock

        boolean tryLock​(@Nonnull
                        K key,
                        long time,
                        @Nullable
                        java.util.concurrent.TimeUnit timeunit,
                        long leaseTime,
                        @Nullable
                        java.util.concurrent.TimeUnit leaseTimeunit)
                 throws java.lang.InterruptedException
        Tries to acquire the lock for the specified key for the specified lease time.

        After lease time, the lock will be released.

        If the lock is not available, then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

        • the lock is acquired by the current thread, or
        • the specified waiting time elapses.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Parameters:
        key - key to lock in this map
        time - maximum time to wait for the lock
        timeunit - time unit of the time argument
        leaseTime - time to wait before releasing the lock
        leaseTimeunit - unit of time to specify lease time
        Returns:
        true if the lock was acquired, false if the waiting time elapsed before the lock was acquired
        Throws:
        java.lang.NullPointerException - if the specified key is null
        java.lang.InterruptedException - if interrupted while trying to acquire the lock
      • unlock

        void unlock​(@Nonnull
                    K key)
        Releases the lock for the specified key. It never blocks and returns immediately.

        If the current thread is the holder of this lock, then the hold count is decremented. If the hold count is zero, then the lock is released. If the current thread is not the holder of this lock, then IllegalMonitorStateException is thrown.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Parameters:
        key - the key to unlock
        Throws:
        java.lang.NullPointerException - if the specified key is null
        java.lang.IllegalMonitorStateException - if the current thread does not hold this lock
      • forceUnlock

        void forceUnlock​(@Nonnull
                         K key)
        Releases the lock for the specified key regardless of the lock owner. It always successfully unlocks the key, never blocks, and returns immediately.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Parameters:
        key - the key to unlock
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • addLocalEntryListener

        java.util.UUID addLocalEntryListener​(@Nonnull
                                             MapListener listener)
        Adds a MapListener for this map. To receive an event, you should implement a corresponding MapListener sub-interface for that event.

        Note that entries in distributed map are partitioned across the cluster members; each member owns and manages the some portion of the entries. Owned entries are called local entries. This listener will be listening for the events of local entries. Let's say your cluster has member1 and member2. On member2 you added a local listener and from member1, you call map.put(key2, value2). If the key2 is owned by member2 then the local listener will be notified for the add/update event. Also note that entries can migrate to other nodes for load balancing and/or membership change.

        Parameters:
        listener - MapListener for this map
        Returns:
        a UUID.randomUUID().toString() which is used as a key to remove the listener
        Throws:
        java.lang.UnsupportedOperationException - if this operation is not supported, for example on a Hazelcast client
        java.lang.NullPointerException - if the listener is null
        See Also:
        localKeySet(), MapListener
      • addLocalEntryListener

        java.util.UUID addLocalEntryListener​(@Nonnull
                                             MapListener listener,
                                             @Nonnull
                                             Predicate<K,​V> predicate,
                                             boolean includeValue)
        Adds a MapListener for this map.

        To receive an event, you should implement a corresponding MapListener sub-interface for that event. The listener will get notified for map events filtered by the given predicate.

        Parameters:
        listener - MapListener for this map
        predicate - predicate for filtering entries
        includeValue - true if EntryEvent should contain the value
        Returns:
        a UUID.randomUUID().toString() which is used as a key to remove the listener
        Throws:
        java.lang.UnsupportedOperationException - if this operation isn't supported, for example on a Hazelcast client
        java.lang.NullPointerException - if the listener or predicate is null
        java.lang.IllegalArgumentException - if the predicate is a PagingPredicate or is a PartitionPredicate that includes a PagingPredicate
        See Also:
        MapListener
      • addLocalEntryListener

        java.util.UUID addLocalEntryListener​(@Nonnull
                                             MapListener listener,
                                             @Nonnull
                                             Predicate<K,​V> predicate,
                                             @Nullable
                                             K key,
                                             boolean includeValue)
        Adds a local entry listener for this map.

        The added listener will only be listening for the events (add/remove/update/evict) of the locally owned entries. The listener will get notified for map add/remove/update/evict events filtered by the given predicate.

        Parameters:
        listener - MapListener for this map
        predicate - predicate for filtering entries
        key - key to listen for
        includeValue - true if EntryEvent should contain the value
        Returns:
        a UUID.randomUUID().toString() which is used as a key to remove the listener
        Throws:
        java.lang.NullPointerException - if the listener is null
        java.lang.NullPointerException - if the predicate is null
        java.lang.UnsupportedOperationException - if this operation isn't supported, for example on a Hazelcast client
        java.lang.IllegalArgumentException - if the predicate is a PagingPredicate or is a PartitionPredicate that includes a PagingPredicate
        See Also:
        MapListener
      • addInterceptor

        java.lang.String addInterceptor​(@Nonnull
                                        MapInterceptor interceptor)
        Adds an interceptor for this map.

        Added interceptor will intercept operations and execute user defined methods. They will cancel operations if the user defined method throws an exception.

        Parameters:
        interceptor - map interceptor
        Returns:
        ID of registered interceptor
      • removeInterceptor

        boolean removeInterceptor​(@Nonnull
                                  java.lang.String id)
        Removes the given interceptor for this map, so it will not intercept operations anymore.
        Parameters:
        id - registration ID of the map interceptor
        Returns:
        true if registration is removed, false otherwise
      • addEntryListener

        java.util.UUID addEntryListener​(@Nonnull
                                        MapListener listener,
                                        boolean includeValue)
        Adds a MapListener for this map.

        To receive an event, you should implement a corresponding MapListener sub-interface for that event.

        Parameters:
        listener - MapListener for this map
        includeValue - true if EntryEvent should contain the value
        Returns:
        a UUID.randomUUID().toString() which is used as a key to remove the listener
        Throws:
        java.lang.NullPointerException - if the specified listener is null
        See Also:
        MapListener
      • removeEntryListener

        boolean removeEntryListener​(@Nonnull
                                    java.util.UUID id)
        Removes the specified entry listener.

        Returns silently if there is no such listener added before.

        Parameters:
        id - ID of registered listener
        Returns:
        true if registration is removed, false otherwise
      • addPartitionLostListener

        java.util.UUID addPartitionLostListener​(@Nonnull
                                                MapPartitionLostListener listener)
        Adds a MapPartitionLostListener.

        The method returns a register ID. This ID is needed to remove the MapPartitionLostListener using the removePartitionLostListener(UUID) method.

        There is no check for duplicate registrations, so if you register the listener twice, you will receive events twice.

        Warning 1:

        Please see PartitionLostListener for weaknesses.

        Warning 2:

        Listeners registered from HazelcastClient may miss some of the map partition lost events due to design limitations.

        Parameters:
        listener - the added MapPartitionLostListener
        Returns:
        returns the registration ID for the MapPartitionLostListener
        Throws:
        java.lang.NullPointerException - if listener is null
        See Also:
        removePartitionLostListener(UUID), PartitionLostListener
      • removePartitionLostListener

        boolean removePartitionLostListener​(@Nonnull
                                            java.util.UUID id)
        Removes the specified map partition lost listener.

        Returns silently if there is no such listener was added before.

        Parameters:
        id - ID of registered listener
        Returns:
        true if registration is removed, false otherwise
        Throws:
        java.lang.NullPointerException - if id is null
      • addEntryListener

        java.util.UUID addEntryListener​(@Nonnull
                                        MapListener listener,
                                        @Nonnull
                                        K key,
                                        boolean includeValue)
        Adds a MapListener for this map. To receive an event, you should implement a corresponding MapListener sub-interface for that event.

        Warning:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

        Parameters:
        listener - MapListener for this map
        key - key to listen for
        includeValue - true if EntryEvent should contain the value
        Returns:
        a UUID.randomUUID().toString() which is used as a key to remove the listener
        Throws:
        java.lang.NullPointerException - if the specified listener is null
        java.lang.NullPointerException - if the specified key is null
        See Also:
        MapListener
      • addEntryListener

        java.util.UUID addEntryListener​(@Nonnull
                                        MapListener listener,
                                        @Nonnull
                                        Predicate<K,​V> predicate,
                                        boolean includeValue)
        Adds a MapListener for this map.

        To receive an event, you should implement a corresponding MapListener sub-interface for that event.

        Parameters:
        listener - the added continuous MapListener for this map
        predicate - predicate for filtering entries
        includeValue - true if EntryEvent should contain the value
        Returns:
        a UUID.randomUUID().toString() which is used as a key to remove the listener
        Throws:
        java.lang.NullPointerException - if the specified listener or predicate is null
        java.lang.IllegalArgumentException - if the predicate is a PagingPredicate or is a PartitionPredicate that includes a PagingPredicate
        See Also:
        MapListener
      • addEntryListener

        java.util.UUID addEntryListener​(@Nonnull
                                        MapListener listener,
                                        @Nonnull
                                        Predicate<K,​V> predicate,
                                        @Nullable
                                        K key,
                                        boolean includeValue)
        Adds a MapListener for this map.

        To receive an event, you should implement a corresponding MapListener sub-interface for that event.

        Parameters:
        listener - the continuous MapListener for this map
        predicate - predicate for filtering entries
        key - key to listen for
        includeValue - true if EntryEvent should contain the value
        Returns:
        a UUID.randomUUID().toString() which is used as a key to remove the listener
        Throws:
        java.lang.NullPointerException - if the specified listener or predicate is null
        java.lang.IllegalArgumentException - if the predicate is a PagingPredicate or is a PartitionPredicate that includes a PagingPredicate
        See Also:
        MapListener
      • getEntryView

        EntryView<K,​V> getEntryView​(@Nonnull
                                          K key)
        Returns the EntryView for the specified key.

        Not to misuse this method, please know these points:

      • This method cannot be used as a replacement for get(java.lang.Object).
      • This method only looks up entries already in memory and does not load missing ones from MapStore.
      • Calling this method does not update entry or map level statistics.
      • Calling this method is not counted as an access, so it doesn't have any effect on eviction and expiration.
      • Warning 1:

        This method returns a clone of original mapping, modifying the returned value does not change the actual value in the map. One should put modified value back to make changes visible to all nodes.

        Warning 2:

        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals defined in the key's class.

Parameters:
key - the key of the entry
Returns:
EntryView of the specified key
Throws:
java.lang.NullPointerException - if the specified key is null
See Also:
EntryView