
com.hazelcast.map.IMap Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.map;
import com.hazelcast.aggregation.Aggregator;
import com.hazelcast.config.IndexConfig;
import com.hazelcast.config.IndexType;
import com.hazelcast.core.EntryView;
import com.hazelcast.map.listener.MapListener;
import com.hazelcast.map.listener.MapPartitionLostListener;
import com.hazelcast.projection.Projection;
import com.hazelcast.query.Predicate;
import com.hazelcast.query.impl.IndexUtils;
import com.hazelcast.spi.properties.ClusterProperty;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
/**
* Concurrent, distributed, observable and queryable map.
*
* This class is not a general-purpose {@code ConcurrentMap}
* implementation! While this class implements the {@code Map} interface,
* it intentionally violates {@code Map's} general contract, which mandates
* the use of the {@code equals} method when comparing objects. Instead of
* the {@code 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 {@code get}, {@code containsKey},
* {@code containsValue}, {@code evict}, {@code remove}, {@code put},
* {@code putIfAbsent}, {@code replace}, {@code lock}, {@code unlock}, do
* not use {@code hashCode} and {@code equals} implementations of keys.
* Instead, they use {@code hashCode} and {@code equals} of binary (serialized)
* forms of the objects.
* - The {@code 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 {@link IMap#get(Object)}.
* - Methods, including but not limited to {@code keySet}, {@code values},
* {@code 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
* {@link ConcurrentMap} and {@link 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 {@code 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.
*
* - {@link IMap#executeOnKey(Object, EntryProcessor)}
* - {@link IMap#submitToKey(Object, EntryProcessor)}
*
* However, there are following methods that run the {@code EntryProcessor}
* on more than one entry.
* These operations are not lock-aware.
* The {@code EntryProcessor} will process the entries no matter if they
* are locked or not.
*
* - {@link IMap#executeOnEntries(EntryProcessor)}
* - {@link IMap#executeOnEntries(EntryProcessor, Predicate)}
* - {@link IMap#executeOnKeys(Set, EntryProcessor)}
*
* This applies to both {@code EntryProcessor} and {@code BackupEntryProcessor}.
*
* 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 {@code 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
* {@link #put(Object, Object, long, TimeUnit) 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 {@code 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 server-side
* {@code max-size} setting
* and the eviction policy may be configured using the
* {@code 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 {@link 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 {@code 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: {@link #put(Object, Object) put},
* {@link #set(Object, Object) set}, {@link #putAsync(Object, Object) putAsync},
* {@link #setAsync(Object, Object) setAsync},
* {@link #tryPut(Object, Object, long, TimeUnit) tryPut},
* {@link #putAll(Map) putAll}, {@link #setAll(Map) setAll},
* {@link #putAllAsync(Map) putAllAsync}, {@link #setAllAsync(Map) setAllAsync},
* {@link #replace(Object, Object, Object)} and {@link #replace(Object, Object)}.
*
*
* Asynchronous methods
*
* Asynchronous methods return a {@link CompletionStage} that can be used to
* chain further computation stages. Alternatively, a {@link java.util.concurrent.CompletableFuture}
* can be obtained via {@link 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 {@link java.util.concurrent.Executor} argument are performed
* by the {@link java.util.concurrent.ForkJoinPool#commonPool()} (unless it does not
* support a parallelism level of at least 2, in which case a new {@code Thread} is
* created per task).
*
* @param key type
* @param value type
* @see java.util.concurrent.ConcurrentMap
*/
@SuppressWarnings("MethodCount")
public interface IMap extends ConcurrentMap, BaseMap , Iterable> {
/**
* {@inheritDoc}
*
* 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 {@code hashCode} and {@code equals} of the binary form of
* the {@code key}, not the actual implementations of {@code hashCode} and {@code equals}
* defined in the {@code key}'s class.
*
Note:
* Use {@link #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 {@code key} in memory,
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-through persistence mode is configured, before the value
* is stored in memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @throws NullPointerException if the specified key or value is null
*/
V put(@Nonnull K key, @Nonnull V value);
/**
* 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code 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 {@link #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 {@code key} in memory,
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-through persistence mode is configured, before the value
* is stored in memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key of the entry
* @param value value of the entry
* @param ttl maximum time for this entry to stay in the map (0 means infinite, negative
* means map config default)
* @param ttlUnit time unit for the TTL
* @return old value of the entry
* @throws NullPointerException if the specified key or value is {@code null}
* @throws UnsupportedOperationException if the underlying map storage doesn't
* support TTL-based expiration (all in-memory storages support it).
*/
V put(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit);
/**
* 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code 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 {@link #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 {@code key} in memory,
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-through persistence mode is configured, before the value
* is stored in memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key of the entry
* @param value value of the entry
* @param ttl maximum time for this entry to stay in the map (0 means infinite, negative
* means map config default)
* @param ttlUnit time unit for the TTL
* @param maxIdle maximum time for this entry to stay idle in the map.
* (0 means infinite, negative means map config default)
* @param maxIdleUnit time unit for the Max-Idle
* @return old value of the entry
* @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are {@code null}
* @throws UnsupportedOperationException if the underlying map storage doesn't
* support TTL-based expiration (all in-memory storages support it).
*/
V put(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit);
/**
* {@inheritDoc}
*
* Note:
*
* This method uses {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code 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 {@code key} in memory,
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-through persistence mode is configured, before the value
* is stored in memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @return a clone of the previous value
* @throws NullPointerException if the specified {@code key} or {@code value}
* is {@code null}
*/
V putIfAbsent(@Nonnull K key, @Nonnull V value);
/**
* 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code 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 {@code key} in memory,
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-through persistence mode is configured, before the value
* is stored in memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key of the entry
* @param value value of the entry
* @param ttl maximum time for this entry to stay in the map (0 means infinite, negative
* means map config default)
* @param ttlUnit time unit for the TTL
* @return old value of the entry
* @throws NullPointerException if the specified {@code key} or {@code value}
* is {@code null}
* @throws UnsupportedOperationException if the underlying map storage doesn't
* support TTL-based expiration (all in-memory storages support it).
*/
V putIfAbsent(@Nonnull K key, @Nonnull V value, long ttl, @Nonnull TimeUnit ttlUnit);
/**
* 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code 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 {@code key} in memory,
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-through persistence mode is configured, before the value
* is stored in memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key of the entry
* @param value value of the entry
* @param ttl maximum time for this entry to stay in the map (0 means infinite, negative
* means map config default)
* @param ttlUnit time unit for the TTL
* @param maxIdle maximum time for this entry to stay idle in the map.
* (0 means infinite, negative means map config default)
* @param maxIdleUnit time unit for the Max-Idle
* @return old value of the entry
* @throws NullPointerException if the specified {@code key}, {@code value}, {@code ttlUnit} or
* {@code maxIdleUnit} are {@code null}
* @throws UnsupportedOperationException if the underlying map storage doesn't
* support TTL-based expiration (all in-memory storages support it).
*/
V putIfAbsent(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit);
/**
* Same as {@link #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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
* Warning 2:
*
* Time resolution for TTL is seconds. The given TTL value is rounded to
* next closest second value.
*
* @param key key of the entry
* @param value value of the entry
* @param ttl maximum time for this entry to stay in the map (0 means infinite, negative
* means map config default)
* @param ttlUnit time unit for the TTL
* @throws NullPointerException if the specified key or value is {@code null}
* @throws UnsupportedOperationException if the underlying map storage doesn't
* support TTL-based expiration (all in-memory storages support it).
*/
void putTransient(@Nonnull K key, @Nonnull V value, long ttl, @Nonnull TimeUnit ttlUnit);
/**
* Same as {@link #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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
* Warning 2:
*
* Time resolution for TTL is seconds. The given TTL value is rounded to
* next closest second value.
*
* @param key key of the entry
* @param value value of the entry
* @param ttl maximum time for this entry to stay in the map (0 means infinite, negative
* means map config default)
* @param ttlUnit time unit for the TTL
* @param maxIdle maximum time for this entry to stay idle in the map.
* (0 means infinite, negative means map config default)
* @param maxIdleUnit time unit for the Max-Idle
* @throws NullPointerException if the specified {@code key}, {@code value}, {@code ttlUnit} or
* {@code maxIdleUnit} are {@code null}
* @throws UnsupportedOperationException if the underlying map storage doesn't
* support TTL-based expiration (all in-memory storages support it).
*/
void putTransient(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit);
/**
* 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
*
Interactions with the map store
*
* If no value is found with {@code key} in memory,
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-through persistence mode is configured, before the value
* is stored in memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key of the entry
* @param value value of the entry
* @param timeout maximum time to wait
* @param timeunit time unit for the timeout
* @return {@code true} if the put is successful, {@code false} otherwise
* @throws NullPointerException if the specified key or value is {@code null}
*/
boolean tryPut(@Nonnull K key, @Nonnull V value,
long timeout, @Nonnull TimeUnit timeunit);
/**
* {@inheritDoc}
*
* 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
* an attempt will be made to load the value from
* the map store backing the map, which may come at a significant
* performance cost. Exceptions thrown by the map 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-through persistence mode is configured,
* an attempt will be made for each element to store it
* before the element is added in memory, which may come at a
* significant performance cost. Exceptions thrown by the map 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*/
void putAll(@Nonnull Map extends K, ? extends V> m);
/**
* {@inheritDoc}
*
* 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
*
Interactions with the map store
*
* If value with {@code key} is not found in memory
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* @throws NullPointerException if the specified key is {@code null}
*/
V get(@Nonnull Object key);
/**
* 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code keys}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
*
Interactions with the map store
*
* If any keys are not found in memory, an attempt will be made
* to load the missing keys. Exceptions thrown by
* the map store fail the operation and are propagated to the caller.
*
* @param keys keys to get (keys inside the collection cannot be null)
* @return an immutable map of entries
* @throws NullPointerException if any of the specified
* keys are null or if any key or any value returned
* during the loading of missing keys is {@code null}.
*/
Map getAll(@Nullable Set keys);
/**
* 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 {@link #delete} and avoid the cost of serialization and network
* transfer.
*
* Warning 1:
*
* This method uses {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code 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 {@code key} in memory,
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-through persistence mode is configured, before the value
* is removed from the memory, an attempt will be made is
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @throws NullPointerException if the specified key is null
* @see #delete(Object)
*/
V remove(@Nonnull Object key);
/**
* {@inheritDoc}
*
* Warning:
*
* This method uses {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
*
Interactions with the map store
*
* If no value is found with {@code key} in memory,
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-through persistence mode is configured, before the value
* is removed from the memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @throws NullPointerException if the specified key or value is null
*/
boolean remove(@Nonnull Object key, @Nonnull Object value);
/**
* 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, an attempt will be made to
* remove the value from the map store. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-behind persistence mode is configured with write-coalescing
* turned off, {@link com.hazelcast.map.ReachedMaxSizeException} may be
* thrown if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param predicate matching entries with this predicate will be removed
* from this map
* @throws NullPointerException if the specified predicate is null
* @throws IllegalArgumentException if the predicate is a {@link com.hazelcast.query.PagingPredicate} or is a
* {@link com.hazelcast.query.PartitionPredicate} that includes a
* {@link com.hazelcast.query.PagingPredicate}
*/
void removeAll(@Nonnull Predicate predicate);
/**
* 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
*
Interactions with the map store
*
* If write-through persistence mode is configured, before the value
* is removed from the memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key of the entry
* @param timeout maximum time to wait for acquiring the lock for the key
* @param timeunit time unit for the timeout
* @return {@code true} if the remove is successful, {@code false} otherwise
* @throws NullPointerException if the specified key is {@code null}
*/
boolean tryRemove(@Nonnull K key, long timeout, @Nonnull TimeUnit timeunit);
/**
* Removes the mapping for the key from this map if it is present.
*
* Unlike {@link #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 memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key whose mapping is to be removed from the map
* @throws ClassCastException if the key is of an inappropriate type for this map (optional)
* @throws NullPointerException if the specified key is null
* @see #remove(Object)
*/
void delete(@Nonnull Object key);
/**
* {@inheritDoc}
*
* Warning 1:
*
* This method uses {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code 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 {@code key} is not found in memory,
* an attempt will be made 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, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @throws NullPointerException if the specified key or value is {@code null}
*/
V replace(@Nonnull K key, @Nonnull V value);
/**
* {@inheritDoc}
*
* Warning 1:
*
* This method uses {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
* Warning 2:
*
* This method may return {@code 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 {@code false}. Hazelcast doesn't guarantee exactly once invocation.
*
*
Interactions with the map store
*
* If value with {@code key} is not found in memory,
* an attempt will be made 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, an attempt will be made to
* write the value into the map store. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* If write-behind persistence mode is configured with write-coalescing
* turned off, {@link com.hazelcast.map.ReachedMaxSizeException} may be
* thrown if the write-behind queue has reached its per-node maximum capacity.
*
* @throws NullPointerException if any of the specified parameters are {@code null}
*/
boolean replace(@Nonnull K key, @Nonnull V oldValue, @Nonnull V newValue);
/**
* {@inheritDoc}
*
* Warning:
*
* This method uses {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
*
Interactions with the map store
*
* If {@code key} is not found in memory
* an attempt will be made to load the value from
* the map store backing the map. Exceptions thrown by the map store fail
* the operation and are propagated to the caller.
*
* @throws NullPointerException if the specified key is {@code null}
*/
boolean containsKey(@Nonnull Object key);
/**
* {@inheritDoc}
*
* @throws NullPointerException if the specified value is {@code null}
*/
boolean containsValue(@Nonnull Object value);
/**
* Clears the map and deletes the items from the backing map store.
*
* The MAP_CLEARED event is fired for any registered listeners.
* See {@link com.hazelcast.core.EntryListener#mapCleared(MapEvent)}.
*
* To clear the map without removing the items from the map store,
* use {@link #evictAll}.
*
*
Interactions with the map store
*
* On each partition deletes all the entries
* with the keys that the given partition stores. Exceptions thrown
* by the delete attempt are not propagated to the caller.
*
* @see #evictAll
*/
@Override
void clear();
/**
* Returns an immutable set clone of the keys contained in this map.
*
* Warning:
*
* The set is NOT backed by the map,
* so changes to the map are NOT reflected in the set.
*
* This method is always executed by a distributed query,
* so it may throw a {@link QueryResultSizeExceededException}
* if {@link ClusterProperty#QUERY_RESULT_SIZE_LIMIT} is configured.
*
* @return an immutable set clone of the keys contained in this map
* @throws QueryResultSizeExceededException if query result size limit is exceeded
* @see ClusterProperty#QUERY_RESULT_SIZE_LIMIT
*/
@Nonnull
Set keySet();
/**
* Queries the map based on the specified predicate and
* returns the keys of matching entries.
*
* @param predicate specified query criteria.
* @return result key set of the query.
* @throws NullPointerException if the specified predicate is null.
*/
Set keySet(Predicate predicate);
/**
* Queries the map based on the specified predicate and
* returns the values of matching entries.
*
* @param predicate specified query criteria.
* @return result value collection of the query.
* @throws NullPointerException if the predicate is null
*/
Collection values(Predicate predicate);
/**
* Returns an immutable collection clone of the values contained in this map.
*
* Warning:
*
* The collection is NOT backed by the map,
* so changes to the map are NOT reflected in the collection.
*
* This method is always executed by a distributed query,
* so it may throw a {@link QueryResultSizeExceededException}
* if {@link ClusterProperty#QUERY_RESULT_SIZE_LIMIT} is configured.
*
* @return an immutable collection clone of the values contained in this map
* @throws QueryResultSizeExceededException if query result size limit is exceeded
* @see ClusterProperty#QUERY_RESULT_SIZE_LIMIT
*/
@Nonnull
Collection values();
/**
* Returns an immutable {@link Set} clone of the mappings contained in this map.
*
* Warning:
*
* The set is NOT backed by the map,
* so changes to the map are NOT reflected in the set.
*
* This method is always executed by a distributed query,
* so it may throw a {@link QueryResultSizeExceededException}
* if {@link ClusterProperty#QUERY_RESULT_SIZE_LIMIT} is configured.
*
* @return an immutable set clone of the keys mappings in this map
* @throws QueryResultSizeExceededException if query result size limit is exceeded
* @see ClusterProperty#QUERY_RESULT_SIZE_LIMIT
*/
@Nonnull
Set> entrySet();
/**
* Queries the map based on the specified predicate and returns an immutable set of the matching entries.
*
* Specified predicate runs on all members in parallel.
*
* Warning:
*
* The set is NOT backed by the map,
* so changes to the map are NOT reflected in the set.
*
* This method is always executed by a distributed query,
* so it may throw a {@link QueryResultSizeExceededException}
* if {@link ClusterProperty#QUERY_RESULT_SIZE_LIMIT} is configured.
*
* @param predicate specified query criteria
* @return result entry set of the query
* @throws QueryResultSizeExceededException if query result size limit is exceeded
* @throws NullPointerException if the predicate is {@code null}
* @see ClusterProperty#QUERY_RESULT_SIZE_LIMIT
*/
Set> entrySet(@Nonnull Predicate predicate);
/**
* {@inheritDoc}
*
*
*
* If the supplied {@code function} is a lambda, anonymous class or an inner class,
* it would be executed locally. Same would happen if it is not serializable.
* This may result in multiple round-trips between hazelcast nodes, and possibly a livelock.
*
*
* Otherwise (i.e. if it is a top-level class or a member class, and it is serializable), the function may be sent
* to the server which owns the key. This results in a single remote call. Also, the function would have exclusive
* access to the map entry during its execution.
* Note that in this case, the function class must be deployed on all the servers (either physically
* or via user-code-deployment).
*
*
* When this method is invoked using a hazelcast-client instance, the {@code function} is always executed locally
*
*
* @since 4.1
*/
default void replaceAll(@Nonnull BiFunction super K, ? super V, ? extends V> function) {
ConcurrentMap.super.replaceAll(function);
}
/**
* Puts an entry into this map without returning the old value
* (which is more efficient than {@code 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code key}'s class.
*
*
Interactions with the map store
*
* If write-through persistence mode is configured, before the value
* is stored in memory, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key of the entry
* @param value value of the entry
* @throws NullPointerException if the specified key or value is {@code null}
*/
void set(@Nonnull K key, @Nonnull V value);
/**
* Puts an entry into this map with a given TTL (time to live) value,
* without returning the old value (which is more efficient than {@code 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code 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, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key of the entry
* @param value value of the entry
* @param ttl maximum time for this entry to stay in the map (0 means infinite, negative
* means map config default)
* @param ttlUnit time unit for the TTL
* @throws NullPointerException if the specified key or value is {@code null}
* @throws UnsupportedOperationException if the underlying map storage doesn't
* support TTL-based expiration (all in-memory storages support it).
*/
void set(@Nonnull K key, @Nonnull V value, long ttl, @Nonnull TimeUnit ttlUnit);
/**
* 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 {@code 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 {@code hashCode} and {@code equals} of the binary form
* of the {@code key}, not the actual implementations of {@code hashCode}
* and {@code equals} defined in the {@code 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, an attempt will be made
* 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param key key of the entry
* @param value value of the entry
* @param ttl maximum time for this entry to stay in the map (0 means infinite, negative
* means map config default)
* @param ttlUnit time unit for the TTL
* @param maxIdle maximum time for this entry to stay idle in the map.
* (0 means infinite, negative means map config default)
* @param maxIdleUnit time unit for the Max-Idle
* @throws NullPointerException if the specified key, value, ttlUnit or maxIdleUnit are {@code null}
* @throws UnsupportedOperationException if the underlying map storage doesn't
* support TTL-based expiration (all in-memory storages support it).
*/
void set(@Nonnull K key, @Nonnull V value,
long ttl, @Nonnull TimeUnit ttlUnit,
long maxIdle, @Nonnull TimeUnit maxIdleUnit);
/**
* 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 {@code 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,
* an attempt will be made for each element to store it
* before the element is added in memory, which may come at a
* significant performance cost. Exceptions thrown by the map 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,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @since 4.1
*/
void setAll(@Nonnull Map extends K, ? extends V> map);
/**
* Applies the user defined {@code EntryProcessor} to the entry mapped by the {@code key}.
* Returns the object which is the result of the {@link EntryProcessor#process(Map.Entry)} method.
*
* See {@link #submitToKey(Object, EntryProcessor)} for an async version of this method.
*
*
Interactions with the map store
*
* If value with {@code key} is not found in memory,
* an attempt will be made to load the value from
* the map store backing the map.
*
* If the entryProcessor updates the entry and write-through
* persistence mode is configured, before the value is stored
* in memory, an attempt will be made to
* write the value into the map store.
*
* If the entryProcessor updates the entry's value to null value and
* write-through persistence mode is configured, before the value is
* removed from the memory, an attempt will be made
* to delete the value from the map store.
*
* Any exceptions thrown by the map store fail the operation and are
* propagated to the caller.
*
* If write-behind persistence mode is configured with
* write-coalescing turned off,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* @param the entry processor return type
* @return result of {@link EntryProcessor#process(Map.Entry)}
* @throws NullPointerException if the specified key is {@code null}
*/
R executeOnKey(@Nonnull K key,
@Nonnull EntryProcessor entryProcessor);
/**
* Applies the user defined {@link EntryProcessor} to the entries mapped by the collection of keys.
*
* The operation is not lock-aware. The {@code EntryProcessor} will process the entries no matter if the keys are
* locked or not. For more details check Entry Processing section on {@link IMap} documentation.
*
*
Interactions with the map store
*
* For each entry not found in memory an attempt will be made
* to load the value from the map store backing the map.
*
* If write-through persistence mode is configured, for each entry
* updated by the entryProcessor, before the updated value is stored
* in memory, an attempt will be made to
* write the value into the map store.
*
* If write-through persistence mode is configured, for each entry
* updated to null value, before the value is removed from the
* memory, an attempt will be made to delete the
* value from the map store.
*
* Any exceptions thrown by the map store fail the operation and are
* propagated to the caller. If an exception happened, the operation might
* be already succeeded on some of the keys.
*
* If write-behind persistence mode is
* configured with write-coalescing turned off,
* {@link com.hazelcast.map.ReachedMaxSizeException} may be thrown
* if the write-behind queue has reached its per-node maximum
* capacity.
*
* Performance note
*
Keep the state of {@code entryProcessor}
* small, it will be serialized and one copy will be sent to each member.
* Additionally, the {@linkplain EntryProcessor#getBackupProcessor() backup
* processor} will also be serialized once for each affected partition and
* sent to each backup. For example, in this usage the entire {@code
* additions} map will be duplicated once for each member and once for each
* partition and backup:
*
{@code
* HashMap additions = ...;
* iMap.executeOnKeys(map.keySet(), entry -> {
* Integer updateBy = additions.get(entry.getKey());
* entry.setValue(entry.getValue() + updateBy);
* return null;
* });
* }
*
* @param keys The keys to execute the entry processor on. Can be empty, in
* that case it's a local no-op
* @param the entry processor return type
* @return results of {@link EntryProcessor#process(Map.Entry)}
* @throws NullPointerException if there's null element in {@code keys}
*/
Map executeOnKeys(@Nonnull Set keys,
@Nonnull EntryProcessor entryProcessor);
/**
* Async version of {@link #executeOnKeys}.
* @param keys the keys to execute the entry processor on. Can be empty, in
* that case it's a local no-op
* @param entryProcessor the processor to process the keys
* @param return type for entry processor
* @return CompletionStage on which client code can block waiting for the
* operation to complete or register callbacks to be invoked
* upon set operation completion
* @see CompletionStage
*/
CompletionStage