|
||||||||||
| 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.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Nested classes/interfaces inherited from interface com.hazelcast.core.Instance |
|---|
Instance.InstanceType |
| Field Summary | |
|---|---|
static Object |
MAP_LOCK
|
| Method Summary | ||
|---|---|---|
void |
addEntryListener(EntryListener<K,V> listener,
boolean includeValue)
Adds an entry listener for this map. |
|
void |
addEntryListener(EntryListener<K,V> listener,
K key,
boolean includeValue)
Adds the specified entry listener for the specified key. |
|
void |
addIndex(Expression<?> expression,
boolean ordered)
Adds an index to this map based on the provided expression. |
|
void |
addIndex(String attribute,
boolean ordered)
Adds an index to this map for the specified entries so that queries can run faster. |
|
Set<Map.Entry<K,V>> |
entrySet(Predicate predicate)
Queries the map based on the specified predicate and returns the matching entries. |
|
boolean |
evict(Object key)
Evicts the specified key from this map. |
|
Future<V> |
getAsync(K key)
Asynchronously gets the given key. |
|
LocalMapStats |
getLocalMapStats()
Returns LocalMapStats for this map. |
|
MapEntry<K,V> |
getMapEntry(K key)
Returns the MapEntry for the specified key. |
|
String |
getName()
Returns the name of 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. |
|
boolean |
lockMap(long time,
TimeUnit timeunit)
Tries to acquire the lock for the entire map. |
|
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. |
|
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 Entry will expire and get evicted after the ttl. |
|
Future<V> |
removeAsync(K key)
Asynchronously removes the given key. |
|
void |
removeEntryListener(EntryListener<K,V> listener)
Removes the specified entry listener Returns silently if there is no such listener added before. |
|
void |
removeEntryListener(EntryListener<K,V> listener,
K key)
Removes the specified entry listener for the specified key. |
|
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. |
|
void |
unlock(K key)
Releases the lock for the specified key. |
|
void |
unlockMap()
Unlocks the map. |
|
|
values(Predicate predicate)
Queries the map based on the specified predicate and returns the values of matching entries. |
|
| Methods inherited from interface java.util.concurrent.ConcurrentMap |
|---|
putIfAbsent, remove, replace, replace |
| Methods inherited from interface java.util.Map |
|---|
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
| Methods inherited from interface com.hazelcast.core.Instance |
|---|
destroy, getId, getInstanceType |
| Field Detail |
|---|
static final Object MAP_LOCK
| Method Detail |
|---|
String getName()
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.
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.
key - the key of the map entryvalue - the new value of the map entry
FutureFuture<V> removeAsync(K key)
key - The key of the map entry to remove.
Future from which the value
removed from the map can be retrieved.
boolean tryPut(K key,
V value,
long timeout,
TimeUnit timeunit)
key - key of the entryvalue - value of the entrytimeout - maximum time to waittimeunit - time unit for the ttl
V put(K key,
V value,
long ttl,
TimeUnit timeunit)
key - key of the entryvalue - value of the entryttl - maximum time for this entry to stay in the maptimeunit - time unit for the ttl
V putIfAbsent(K key,
V value,
long ttl,
TimeUnit timeunit)
key - key of the entryvalue - value of the entryttl - maximum time for this entry to stay in the maptimeunit - time unit for the ttl
void 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.
key - key to lock.boolean tryLock(K key)
If the lock is not available then the current thread doesn't wait and returns false immediately.
key - key to lock.
boolean tryLock(K key,
long time,
TimeUnit timeunit)
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:
time - the maximum time to wait for the locktimeunit - the time unit of the time argument.
void unlock(K key)
key - key to lock.
boolean lockMap(long time,
TimeUnit timeunit)
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:
time - the maximum time to wait for the locktimeunit - the time unit of the time argument.
void unlockMap()
void addEntryListener(EntryListener<K,V> listener,
boolean includeValue)
listener - entry listenerincludeValue - true if EntryEvent should
contain the value.void removeEntryListener(EntryListener<K,V> listener)
listener - entry listener
void addEntryListener(EntryListener<K,V> listener,
K key,
boolean includeValue)
listener - entry listenerkey - the key to listenincludeValue - true if EntryEvent should
contain the value.
void removeEntryListener(EntryListener<K,V> listener,
K key)
listener - key - MapEntry<K,V> getMapEntry(K key)
key - key of the entry
MapEntryboolean evict(Object key)
key - key to evict
Set<K> keySet(Predicate predicate)
predicate - query criteria
Set<Map.Entry<K,V>> entrySet(Predicate predicate)
predicate - query criteria
<V> Collection<V> values(Predicate predicate)
predicate - query criteria
Set<K> localKeySet()
Set<K> localKeySet(Predicate predicate)
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 range
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.
attribute - attribute of valueordered - true if index should be ordered,
false otherwise.
void addIndex(Expression<?> expression,
boolean ordered)
expression - The expression for the index.ordered - true if index should be ordered,
false otherwise.LocalMapStats getLocalMapStats()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||