|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
K
- keyV
- valuepublic interface IMap<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.
Gotchas:
get(Object)
.
ConcurrentMap
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Method Summary | |
---|---|
String |
addEntryListener(EntryListener<K,V> listener,
boolean includeValue)
Adds an entry listener for this map. |
String |
addEntryListener(EntryListener<K,V> listener,
K key,
boolean includeValue)
Adds the specified entry listener for the specified key. |
String |
addEntryListener(EntryListener<K,V> listener,
Predicate<K,V> predicate,
K key,
boolean includeValue)
Adds an continuous entry listener for this map. |
void |
addIndex(String attribute,
boolean ordered)
Adds an index to this map for the specified entries so that queries can run faster. |
String |
addInterceptor(com.hazelcast.map.MapInterceptor interceptor)
Adds an interceptor for this map. |
String |
addLocalEntryListener(EntryListener<K,V> listener)
Adds a local entry listener for this map. |
boolean |
containsKey(Object key)
Returns true if this map contains an entry for the specified
key. |
boolean |
containsValue(Object value)
|
void |
delete(Object key)
Removes the mapping for a key from this map if it is present (optional operation). |
Set<Map.Entry<K,V>> |
entrySet()
Returns a Set clone of the mappings contained in this map. |
Set<Map.Entry<K,V>> |
entrySet(Predicate predicate)
Queries the map based on the specified predicate and returns the matching entries. |
boolean |
evict(K key)
Evicts the specified key from this map. |
Map<K,Object> |
executeOnEntries(com.hazelcast.map.EntryProcessor entryProcessor)
Applies the user defined EntryProcessor to the all entries in the map. |
Object |
executeOnKey(K key,
com.hazelcast.map.EntryProcessor entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key. |
void |
flush()
If this map has a MapStore this method flushes all the local dirty entries by calling MapStore.storeAll() and/or MapStore.deleteAll() |
void |
forceUnlock(K key)
Releases the lock for the specified key regardless of the lock owner. |
V |
get(Object key)
Returns the value for the specified key, or null if this map does not contain this key. |
Map<K,V> |
getAll(Set<K> keys)
Returns the entries for the given keys. |
Future<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. |
boolean |
isLocked(K key)
Checks the lock for the specified key. |
Set<K> |
keySet()
Returns a set clone of the keys contained in this map. |
Set<K> |
keySet(Predicate predicate)
Queries the map based on the specified predicate and returns the keys of matching entries. |
Set<K> |
localKeySet()
Returns the locally owned set of keys. |
Set<K> |
localKeySet(Predicate predicate)
Returns the keys of matching locally owned entries. |
void |
lock(K key)
Acquires the lock for the specified key. |
void |
lock(K key,
long leaseTime,
TimeUnit timeUnit)
Acquires the lock for the specified key for the specified lease time. |
V |
put(K key,
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. |
V |
put(K key,
V value,
long ttl,
TimeUnit timeunit)
Puts an entry into this map with a given ttl (time to live) value. |
Future<V> |
putAsync(K key,
V value)
Asynchronously puts the given key and value. |
Future<V> |
putAsync(K key,
V value,
long ttl,
TimeUnit timeunit)
Asynchronously puts the given key and value into this map with a given ttl (time to live) 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,
TimeUnit timeunit)
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. |
void |
putTransient(K key,
V value,
long ttl,
TimeUnit timeunit)
Same as #put(K, V, long, TimeUnit) but MapStore, if defined,
will not be called to store/persist the entry. |
V |
remove(Object key)
Removes the mapping for a key from this map if it is present. |
boolean |
remove(Object key,
Object value)
Removes the entry for a key only if currently mapped to a given value. |
Future<V> |
removeAsync(K key)
Asynchronously removes the given key. |
boolean |
removeEntryListener(String id)
Removes the specified entry listener Returns silently if there is no such listener added before. |
void |
removeInterceptor(String id)
Removes the given interceptor for this map. |
V |
replace(K key,
V value)
Replaces the entry for a key only if 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. |
void |
set(K key,
V value)
Puts an entry into this map with a given ttl (time to live) value. |
void |
set(K key,
V value,
long ttl,
TimeUnit timeunit)
Puts an entry into this map with a given ttl (time to live) value. |
boolean |
tryLock(K key)
Tries to acquire the lock for the specified key. |
boolean |
tryLock(K key,
long time,
TimeUnit timeunit)
Tries to acquire the lock for the specified key. |
boolean |
tryPut(K key,
V value,
long timeout,
TimeUnit timeunit)
Tries to put the given key, value into this map within specified timeout value. |
boolean |
tryRemove(K key,
long timeout,
TimeUnit timeunit)
Tries to remove the entry with the given key from this map within specified timeout value. |
void |
unlock(K key)
Releases the lock for the specified key. |
Collection<V> |
values()
Returns a collection clone of the values contained in this map. |
Collection<V> |
values(Predicate predicate)
Queries the map based on the specified predicate and returns the values of matching entries. |
Methods inherited from interface java.util.Map |
---|
clear, equals, hashCode, isEmpty, putAll, size |
Methods inherited from interface com.hazelcast.core.BaseMap |
---|
isEmpty, size |
Methods inherited from interface com.hazelcast.core.DistributedObject |
---|
destroy, getId, getName, getServiceName |
Method Detail |
---|
boolean containsKey(Object key)
true
if this map contains an entry for the specified
key.
Warning:
ˆ This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
containsKey
in interface BaseMap<K,V>
containsKey
in interface Map<K,V>
key
- key
true
if this map contains an entry for the specified keyboolean containsValue(Object value)
containsValue
in interface Map<K,V>
V get(Object key)
null
if this map does not contain this key.
Warning:
This method returns a clone of original value, 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.
V value = map.get(key); value.updateSomeProperty(); map.put(key, value);
Warning-2:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
get
in interface BaseMap<K,V>
get
in interface Map<K,V>
key
- key
V put(K key, V value)
Warning:
This method returns a clone of previous value, not the original (identically equal) value previously put into map.
Warning-2:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
put
in interface BaseMap<K,V>
put
in interface Map<K,V>
key
- keyvalue
- value
key
or null
if there was no mapping for key
.V remove(Object key)
The map will not contain a mapping for the specified key once the call returns.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
Warning-2:
This method returns a clone of previous value, not the original (identically equal) value previously put into map.
remove
in interface BaseMap<K,V>
remove
in interface Map<K,V>
key
- key
key
or null
if there was no mapping for key
.boolean remove(Object key, Object value)
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 binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
remove
in interface BaseMap<K,V>
remove
in interface ConcurrentMap<K,V>
key
- keyvalue
- value
true
if the value was removedvoid delete(Object key)
Differently from remove(Object)
; this operation does not return
removed value to avoid serialization cost of returned value.
If the removed value will not be used, delete operation
should be preferred over remove operation for a better performance.
The map will not contain a mapping for the specified key once the call returns.
delete
in interface BaseMap<K,V>
key
- key whose mapping is to be removed from the map
ClassCastException
- if the key is of an inappropriate type for
this map (optional)
NullPointerException
- if the specified key is null and this
map does not permit null keys (optional)void flush()
Map<K,V> getAll(Set<K> keys)
Warning:
The returned map is NOT backed by the original map, so changes to the original map are NOT reflected in the returned map, and vice-versa.Warning-2:
This method uses hashCode and equals of binary form of the keys, not the actual implementations of hashCode and equals defined in key's class.
keys
- keys to get
Future<V> getAsync(K key)
Future future = map.getAsync(key);
// do some other stuff, when ready get the result
Object value = future.get();
Future.get() will block until the actual map.get() completes.
If the application requires timely response,
then Future.get(timeout, timeunit) can be used.
try{
Future future = map.getAsync(key);
Object value = future.get(40, TimeUnit.MILLISECOND);
}catch (TimeoutException t) {
// time wasn't enough
}
ExecutionException is never thrown.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- the key of the map entry
Future
Future<V> putAsync(K key, V value)
Future future = map.putAsync(key, value);
// do some other stuff, when ready get the result
Object oldValue = future.get();
Future.get() will block until the actual map.get() completes.
If the application requires timely response,
then Future.get(timeout, timeunit) can be used.
try{
Future future = map.putAsync(key, newValue);
Object oldValue = future.get(40, TimeUnit.MILLISECOND);
}catch (TimeoutException t) {
// time wasn't enough
}
ExecutionException is never thrown.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- the key of the map entryvalue
- the new value of the map entry
Future
Future<V> putAsync(K key, V value, long ttl, TimeUnit timeunit)
Future future = map.putAsync(key, value, ttl, timeunit);
// do some other stuff, when ready get the result
Object oldValue = future.get();
Future.get() will block until the actual map.get() completes.
If the application requires timely response,
then Future.get(timeout, timeunit) can be used.
try{
Future future = map.putAsync(key, newValue, ttl, timeunit);
Object oldValue = future.get(40, TimeUnit.MILLISECOND);
}catch (TimeoutException t) {
// time wasn't enough
}
ExecutionException is never thrown.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- the key of the map entryvalue
- the new value of the map entryttl
- maximum time for this entry to stay in the map
0 means infinite.timeunit
- time unit for the ttl
Future
Future<V> removeAsync(K key)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- The key of the map entry to remove.
Future
from which the value
removed from the map can be retrieved.boolean tryRemove(K key, long timeout, TimeUnit timeunit)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.Warning-2:
This method returns a clone of previous value, not the original (identically equal) value previously put into map.
key
- key of the entrytimeout
- maximum time to wait for acquiring the lock
for the keytimeunit
- time unit for the timeout
boolean tryPut(K key, V value, long timeout, TimeUnit timeunit)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key of the entryvalue
- value of the entrytimeout
- maximum time to waittimeunit
- time unit for the timeout
V put(K key, V value, long ttl, TimeUnit timeunit)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.Warning-2:
This method returns a clone of previous value, not the original (identically equal) value previously put into map.
key
- key of the entryvalue
- value of the entryttl
- maximum time for this entry to stay in the map
0 means infinite.timeunit
- time unit for the ttl
void putTransient(K key, V value, long ttl, TimeUnit timeunit)
#put(K, V, long, TimeUnit)
but MapStore, if defined,
will not be called to store/persist the entry. If ttl is 0, then
the entry lives forever.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key of the entryvalue
- value of the entryttl
- maximum time for this entry to stay in the map.
0 means infinite.timeunit
- time unit for the ttlV putIfAbsent(K key, V value)
if (!map.containsKey(key)) return map.put(key, value); else return map.get(key);except that the action is performed atomically.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.Warning-2:
This method returns a clone of previous value, not the original (identically equal) value previously put into map.
putIfAbsent
in interface BaseMap<K,V>
putIfAbsent
in interface ConcurrentMap<K,V>
key
- keyvalue
- value
key
or null
if there was no mapping for key
.V putIfAbsent(K key, V value, long ttl, TimeUnit timeunit)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.Warning-2:
This method returns a clone of previous value, not the original (identically equal) value previously put into map.
key
- key of the entryvalue
- value of the entryttl
- maximum time for this entry to stay in the maptimeunit
- time unit for the ttl
boolean replace(K key, V oldValue, V newValue)
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:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
replace
in interface BaseMap<K,V>
replace
in interface ConcurrentMap<K,V>
key
- keyoldValue
- old valuenewValue
- new value
true
if the value was replacedV replace(K key, V value)
if (map.containsKey(key)) { return map.put(key, value); } else return null;except that the action is performed atomically.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.Warning-2:
This method returns a clone of previous value, not the original (identically equal) value previously put into map.
replace
in interface BaseMap<K,V>
replace
in interface ConcurrentMap<K,V>
key
- keyvalue
- value
key
or null
if there was no mapping for key
.void set(K key, V value)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
set
in interface BaseMap<K,V>
key
- key of the entryvalue
- value of the entryvoid set(K key, V value, long ttl, TimeUnit timeunit)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key of the entryvalue
- value of the entryttl
- maximum time for this entry to stay in the map
0 means infinite.timeunit
- time unit for the ttlvoid lock(K 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.
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 binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key to lock.void lock(K key, long leaseTime, TimeUnit timeUnit)
After lease time, 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 binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key to lock.leaseTime
- time to wait before releasing the lock.timeUnit
- unit of time to specify lease time.boolean isLocked(K key)
If the lock is acquired then returns true, else false.
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key to lock to be checked.
boolean tryLock(K 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 binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key to lock.
boolean tryLock(K key, long time, TimeUnit timeunit) throws InterruptedException
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:
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key to lock in this maptime
- maximum time to wait for the locktimeunit
- time unit of the time argument.
InterruptedException
void unlock(K key)
If the current thread is the holder of this lock then the hold
count is decremented. If the hold count is now 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 binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key to lock.
IllegalMonitorStateException
- if the current thread does not hold this lockvoid forceUnlock(K key)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key to lock.String addLocalEntryListener(EntryListener<K,V> listener)
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.
listener
- entry listenerlocalKeySet()
String addInterceptor(com.hazelcast.map.MapInterceptor interceptor)
interceptor
- map interceptor
void removeInterceptor(String id)
id
- registration id of map interceptorString addEntryListener(EntryListener<K,V> listener, boolean includeValue)
listener
- entry listenerincludeValue
- true if EntryEvent should
contain the value.boolean removeEntryListener(String id)
id
- id of registered listener
String addEntryListener(EntryListener<K,V> listener, K key, boolean includeValue)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
listener
- entry listenerkey
- key to listenincludeValue
- true if EntryEvent should
contain the value.String addEntryListener(EntryListener<K,V> listener, Predicate<K,V> predicate, K key, boolean includeValue)
listener
- entry listenerpredicate
- predicate for filtering entriesEntryView<K,V> getEntryView(K key)
Warning:
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 binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key of the entry
EntryView
boolean evict(K key)
Warning:
This method uses hashCode and equals of binary form of the key, not the actual implementations of hashCode and equals defined in key's class.
key
- key to evict
Set<K> keySet()
keySet
in interface Map<K,V>
Collection<V> values()
values
in interface Map<K,V>
Set<Map.Entry<K,V>> entrySet()
Set
clone of the mappings contained in this map.
The set is NOT backed by the map,
so changes to the map are NOT reflected in the set, and vice-versa.
entrySet
in interface Map<K,V>
Set<K> keySet(Predicate predicate)
Warning:
The set is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.
predicate
- query criteria
Set<Map.Entry<K,V>> entrySet(Predicate predicate)
Warning:
The set is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.
predicate
- query criteria
Collection<V> values(Predicate predicate)
Warning:
The collection is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.
predicate
- query criteria
Set<K> localKeySet()
Warning:
The set is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.
Set<K> localKeySet(Predicate predicate)
Warning:
The set is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.
predicate
- query criteria
void addIndex(String attribute, boolean ordered)
public class Employee implements Serializable { private boolean active = false; private int age; private String name = null; // other fields. // getters setter }If you are querying your values mostly based on age and active then you should consider indexing these fields.
IMap imap = Hazelcast.getMap("employees"); imap.addIndex("age", true); // ordered, since we have ranged queries for this field imap.addIndex("active", false); // not ordered, because boolean field cannot have rangeIndex 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.
attribute
- attribute of valueordered
- true if index should be ordered,
false otherwise.LocalMapStats getLocalMapStats()
Object executeOnKey(K key, com.hazelcast.map.EntryProcessor entryProcessor)
Map<K,Object> executeOnEntries(com.hazelcast.map.EntryProcessor entryProcessor)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |