Adds a MapListener for this map.
listener object
optional key to restrict events to associated entry
if set to true
, event message will contain
new value of the key
registration id of the listener
Adds a MapListener for this map. Listener will get notified for map add/remove/update/evict events filtered by the given predicate.
listener object
predicate
optional key to restrict events to associated entry
if set to true
, event message will contain
new value of the key
registration id of the listener
Adds an index to this map for the specified entries so that queries can run faster.
Let's say your map values are Employee objects.
class Employee implements Portable {
active: boolean = false;
age: number;
name: string = null;
// other fields
// portable implementation
}
If you are querying your values mostly based on age and active then you may consider indexing these fields.
const map = client.getMap('employees');
// Sorted index for range queries:
map.addIndex({
type: 'SORTED',
attributes: ['age']
});
// Hash index for equality predicates:
map.addIndex({
type: 'HASH',
attributes: ['active']
});
Index attribute should either have a getter method or be public. You should also make sure to add the indexes before adding entries to this map.
Time to Index
Indexing time is executed in parallel on each partition by operation threads. The Map is not blocked during this operation.
The time taken in proportional to the size of the Map and the number Members.
Searches while indexes are being built
Until the index finishes being created, any searches for the attribute will use a full Map scan, thus avoiding using a partially built index and returning incorrect results.
Index configuration.
Applies the aggregation logic on all map entries and returns the result.
Fast-Aggregations are the successor of the Map-Reduce Aggregators. They are equivalent to the Map-Reduce Aggregators in most of the use-cases, but instead of running on the Map-Reduce engine they run on the Query infrastructure. Their performance is tens to hundreds times better due to the fact that they run in parallel for each partition and are highly optimized for speed and low memory consumption.
type of the result
aggregator to aggregate the entries with
the result of the given type
Applies the aggregation logic on map entries filtered with the Predicated and returns the result.
Fast-Aggregations are the successor of the Map-Reduce Aggregators. They are equivalent to the Map-Reduce Aggregators in most of the use-cases, but instead of running on the Map-Reduce engine they run on the Query infrastructure. Their performance is tens to hundreds times better due to the fact that they run in parallel for each partition and are highly optimized for speed and low memory consumption.
type of the result
aggregator to aggregate the entries with
predicate to filter the entries with
the result of the given type
Removes all of the mappings.
Returns true
if this map has an item associated with key.
the key of the map entry
true
if the map contains the key, false
otherwise
Returns true
if this map has key(s) associated with given value.
the value of the map entry
true
if the map has key or keys associated with given value
Removes specified key from the map. Unlike remove this method does not return the deleted value. Therefore, it eliminates deserialization cost of the returned value.
the key of the map entry
Destroys this object cluster-wide. Clears all resources taken for this object.
Returns entries as an array of key-value pairs.
Queries the map based on the specified predicate and returns matching entries. Specified predicate runs on all members in parallel.
specified query criteria.
result entry set of the query.
Evicts the specified key from this map.
the key of the map entry
Evicts all keys from this map.
Applies the user defined EntryProcessor to the all entries in the map.
Returns the results mapped by each key in the map.
Note that entryProcessor
should be registered at server side too.
EntryProcessor object
if specified, entry processor is applied to the entries that satisfy this predicate
entries after EntryProcessor is applied
Applies the user defined EntryProcessor to the entry mapped by the key.
entry processor is applied only to the value that is mapped with this key
entry processor to be applied
result of entry process
Applies the user defined EntryProcessor to the entries mapped by the given keys.
keys to be processed
result of entry process
If this map has a MapStore, this method flushes all local dirty entries.
Releases the lock for the specified key regardless of the owner. This operation always unlocks the key.
the key of the map entry
Retrieves the value associated with given key.
the key of the map entry
value associated with key, null
if the key does not exist
Retrieves key value pairs of given keys.
the array of keys
Returns a key-value pair representing the association of given key.
the key of the map entry
Returns the unique name of this object.
Returns the key of the partition that this DistributedObject is assigned to.
For a partitioned data structure, the returned value will not be null
,
but otherwise undefined
.
Returns the service name for this object.
Returns whether this map is empty or not.
Checks whether given key is locked.
the key of the map entry
true
if key is locked, false
otherwise
Returns the keys of this map as an array.
Queries the map based on the specified predicate and returns the keys of matching entries.
predicate to filter map entries
Loads keys to the store.
loads only given keys if set
if set to true
existing keys will be
replaced by newly loaded keys.
Locks the given key for this map. Promise is resolved when lock is successfully acquired. This means it may never be resolved if some other process holds the lock and does not unlock it. A lock may be acquired on non-existent keys. In that case, other clients would block 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 client 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.
Locking is reentrant, meaning that the lock owner client can obtain the
lock multiple times. If the lock was acquired multiple times, then unlock()
method must be called the same amount of times, otherwise the lock will
remain unavailable.
the key of the map entry
lock is automatically unlocked after leaseTime
milliseconds; defaults to infinity
Associates the specified value with the specified key. If key was associated with another value, it replaces the old 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 Max Idle is 0
, then the entry lives
forever. If the Max Idle is negative, then the Max Idle from the map
configuration will be used (default: forever). The time precision is
limited by 1
second. The Max Idle that is less than 1
second can
lead to unexpected behaviour.
the key of the map entry
new value
optional time to live in milliseconds. 0
means infinite,
negative means map config default. Time resolution for TTL
is seconds. The given value is rounded to the next closest
second value.
optional maximum time in milliseconds for this entry to
stay idle in the map. 0
means infinite, negative means
map config default.
old value if there was any, null
otherwise
Puts all key value pairs from this array to the map as key -> value mappings.
The behaviour of this operation is undefined if the specified pairs are modified while this operation is in progress.
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, this call may be rejected with ReachedMaxSizeError
if the write-behind queue has reached its per-node maximum capacity.
entries to be put
Puts specified key value association if it was not present before.
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 Max Idle is 0
, then the entry lives
forever. If the Max Idle is negative, then the Max Idle from the map
configuration will be used (default: forever). The time precision is
limited by 1
second. The Max Idle that is less than 1
second can
lead to unexpected behaviour.
the key of the map entry
new value
optional time to live in milliseconds. 0
means infinite,
negative means map config default. Time resolution for TTL
is seconds. The given value is rounded to the next closest
second value.
optional maximum time in milliseconds for this entry to
stay idle in the map. 0
means infinite, negative means
map config default.
old value of the entry
Same as put except it does not call underlying MapStore.
the key of the map entry
new value
optional time to live in milliseconds. 0
means infinite,
negative means map config default. Time resolution for TTL
is seconds. The given value is rounded to the next closest
second value.
optional maximum time in milliseconds for this entry to
stay idle in the map. 0
means infinite, negative means
map config default.
Removes specified key from map. If optional value is specified, the key is removed only if currently mapped to given value. Note that serialized version of the value is used in comparison.
the key of the map entry
expected value
value associated with key, null
if the key did not exist
before. If optional value is specified, a boolean
representing
whether or not entry is removed is returned
Removes a MapListener from this map.
registration Id of the listener
true
if remove operation is successful, false
if
unsuccessful or this listener did not exist
Replaces value of given key with newValue
.
the key of the map entry
previous value
Replaces value of the key if only it was associated to oldValue
.
the key of the map entry
expected old value
new value
true
if the value was replaced
Similar to put except it does not return the old 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 Max Idle is 0
, then the entry lives
forever. If the Max Idle is negative, then the Max Idle from the map
configuration will be used (default: forever). The time precision is
limited by 1
second. The Max Idle that is less than 1
second can
lead to unexpected behaviour.
the key of the map entry
new value
optional time to live in milliseconds. 0
means infinite,
negative means map config default. Time resolution for TTL
is seconds. The given value is rounded to the next closest
second value.
optional maximum time in milliseconds for this entry to
stay idle in the map. 0
means infinite, negative means
map config default.
Puts all key value pairs from this array to the map as key -> value
mappings 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.
The behaviour of this operation is undefined if the specified pairs are modified while this operation is in progress.
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, this call may be rejected with ReachedMaxSizeError
if the write-behind queue has reached its per-node maximum capacity.
Works with Hazelcast versions 4.1 and above.
entries to be put
Updates the TTL (time to live) value of the entry specified by key
with a new TTL value. New TTL value is valid starting from the time
this operation is invoked, not since the time the entry was created.
If the entry does not exist or is already expired, this call has no
effect.
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).
If there is no entry with key key
or is already expired, this call
makes no changes to entries stored in this map.
the key of the map entry
time to live in milliseconds. 0
means infinite, negative
means map config default. Time resolution for TTL is seconds.
The given value is rounded to the next closest second value.
true
if the entry exists and its TTL value is changed,
false
otherwise
Retrieves the number of elements in the map.
number of elements in map
Tries to acquire the lock for the specified key.
If lock is not available, server immediately responds with false
.
Locking is reentrant, meaning that the lock owner client can obtain
the lock multiple times. If the lock was acquired multiple times, then
unlock()
method must be called the same amount of times, otherwise the
lock will remain unavailable.
the key of the map entry
server waits for timeout
milliseconds to acquire
the lock before giving up; defaults to 0
lock is automatically release after leaseTime
milliseconds; defaults to infinity
Tries to put specified key value pair into the map. If this method returns
false, it indicates that caller thread was not able to acquire the lock for
given key in timeout
milliseconds.
the key of the map entry
new value
maximum time to wait in milliseconds
Tries to remove specified key from the map. If this method returns
false, it indicates that caller thread was not able to acquire the lock
for given key in timeout
milliseconds.
the key of the map entry
maximum time to wait in milliseconds
Releases the lock for this key. If this client holds the lock, hold count is decremented. If hold count is zero, lock is released.
the key of the map entry
Returns a list of values contained in this map.
Queries the map based on the specified predicate and returns the values of matching entries. Specified predicate runs on all members in parallel.
a list of values that satisfies the given predicate
Generated using TypeDoc
Concurrent, distributed, observable and queryable map.
Methods that require serialization/deserialization may throw RangeError, e.g when there is no suitable serializer for a certain type.