Hazelcast C++ Client
|
Concurrent, distributed, observable and queryable map client. More...
#include <IMap.h>
Public Member Functions | |
bool | containsKey (const K &key) |
check if this map contains key. More... | |
bool | containsValue (const V &value) |
check if this map contains value. More... | |
boost::shared_ptr< V > | get (const K &key) |
get the value. More... | |
boost::shared_ptr< V > | put (const K &key, const V &value) |
put new entry into map. More... | |
boost::shared_ptr< V > | put (const K &key, const V &value, long ttlInMillis) |
Puts an entry into this map with a given ttl (time to live) value. More... | |
boost::shared_ptr< V > | remove (const K &key) |
remove entry form map More... | |
void | removeAll (const query::Predicate &predicate) |
Removes all entries which match with the supplied predicate. More... | |
bool | remove (const K &key, const V &value) |
removes entry from map if there is an entry with same key and value. More... | |
void | deleteEntry (const K &key) |
removes entry from map. More... | |
void | flush () |
If this map has a MapStore this method flushes all the local dirty entries by calling MapStore.storeAll() and/or MapStore.deleteAll() | |
bool | tryRemove (const K &key, long timeoutInMillis) |
Tries to remove the entry with the given key from this map within specified timeout value. More... | |
bool | tryPut (const K &key, const V &value, long timeoutInMillis) |
Tries to put the given key, value into this map within specified timeout value. More... | |
void | putTransient (const K &key, const V &value, long ttlInMillis) |
Same as put(K, V, long, TimeUnit) but MapStore, if defined, will not be called to store/persist the entry. More... | |
boost::shared_ptr< V > | putIfAbsent (const K &key, const V &value) |
Puts an entry into this map, if the specified key is not already associated with a value. More... | |
boost::shared_ptr< V > | putIfAbsent (const K &key, const V &value, long ttlInMillis) |
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. More... | |
bool | replace (const K &key, const V &oldValue, const V &newValue) |
Replaces the entry for a key only if currently mapped to a given value. More... | |
boost::shared_ptr< V > | replace (const K &key, const V &value) |
Replaces the entry for a key only if currently mapped to some value. More... | |
void | lock (const K &key) |
Acquires the lock for the specified key. More... | |
void | lock (const K &key, long leaseTime) |
Acquires the lock for the specified key for the specified lease time. More... | |
bool | isLocked (const K &key) |
Checks the lock for the specified key. More... | |
bool | tryLock (const K &key) |
Tries to acquire the lock for the specified key. More... | |
bool | tryLock (const K &key, long timeInMillis) |
Tries to acquire the lock for the specified key. More... | |
void | unlock (const K &key) |
Releases the lock for the specified key. More... | |
void | forceUnlock (const K &key) |
Releases the lock for the specified key regardless of the lock owner. More... | |
template<typename MapInterceptor > | |
std::string | addInterceptor (MapInterceptor &interceptor) |
Adds an interceptor for this map. More... | |
void | removeInterceptor (const std::string &id) |
Removes the given interceptor for this map. More... | |
std::string | addEntryListener (EntryListener< K, V > &listener, bool includeValue) |
Adds an entry listener for this map. More... | |
std::string | addEntryListener (EntryListener< K, V > &listener, const query::Predicate &predicate, bool includeValue) |
Adds an entry listener for this map. More... | |
bool | removeEntryListener (const std::string ®istrationId) |
Removes the specified entry listener Returns silently if there is no such listener added before. More... | |
std::string | addEntryListener (EntryListener< K, V > &listener, const K &key, bool includeValue) |
Adds the specified entry listener for the specified key. More... | |
EntryView< K, V > | getEntryView (const K &key) |
Returns the EntryView for the specified key. More... | |
bool | evict (const K &key) |
Evicts the specified key from this map. More... | |
void | evictAll () |
Evicts all keys from this map except locked ones. More... | |
std::map< K, V > | getAll (const std::set< K > &keys) |
Returns the entries for the given keys. More... | |
std::vector< K > | keySet () |
Returns a vector clone of the keys contained in this map. More... | |
std::vector< K > | keySet (const serialization::IdentifiedDataSerializable &predicate) |
std::vector< K > | keySet (const query::Predicate &predicate) |
Queries the map based on the specified predicate and returns the keys of matching entries. More... | |
std::vector< K > | keySet (query::PagingPredicate< K, V > &predicate) |
Queries the map based on the specified predicate and returns the keys of matching entries. More... | |
std::vector< V > | values () |
Returns a vector clone of the values contained in this map. More... | |
std::vector< V > | values (const serialization::IdentifiedDataSerializable &predicate) |
std::vector< V > | values (const query::Predicate &predicate) |
Returns a vector clone of the values contained in this map. More... | |
std::vector< V > | values (query::PagingPredicate< K, V > &predicate) |
Returns a vector clone of the values contained in this map. More... | |
std::vector< std::pair< K, V > > | entrySet () |
Returns a std::vector< std::pair<K, V> > clone of the mappings contained in this map. More... | |
std::vector< std::pair< K, V > > | entrySet (const serialization::IdentifiedDataSerializable &predicate) |
std::vector< std::pair< K, V > > | entrySet (const query::Predicate &predicate) |
Queries the map based on the specified predicate and returns the matching entries. More... | |
std::vector< std::pair< K, V > > | entrySet (query::PagingPredicate< K, V > &predicate) |
Queries the map based on the specified predicate and returns the matching entries. More... | |
void | addIndex (const std::string &attribute, bool ordered) |
Adds an index to this map for the specified entries so that queries can run faster. More... | |
template<typename ResultType , typename EntryProcessor > | |
boost::shared_ptr< ResultType > | executeOnKey (const K &key, const EntryProcessor &entryProcessor) |
Applies the user defined EntryProcessor to the entry mapped by the key. More... | |
template<typename ResultType , typename EntryProcessor > | |
std::map< K, boost::shared_ptr< ResultType > > | executeOnKeys (const std::set< K > &keys, const EntryProcessor &entryProcessor) |
Applies the user defined EntryProcessor to the entries mapped by the collection of keys. More... | |
template<typename ResultType , typename EntryProcessor > | |
Future< ResultType > | submitToKey (const K &key, const EntryProcessor &entryProcessor) |
Applies the user defined EntryProcessor to the entry mapped by the key. More... | |
template<typename ResultType , typename EntryProcessor > | |
std::map< K, boost::shared_ptr< ResultType > > | executeOnEntries (const EntryProcessor &entryProcessor) |
Applies the user defined EntryProcessor to the all entries in the map. More... | |
template<typename ResultType , typename EntryProcessor > | |
std::map< K, boost::shared_ptr< ResultType > > | executeOnEntries (const EntryProcessor &entryProcessor, const serialization::IdentifiedDataSerializable &predicate) |
template<typename ResultType , typename EntryProcessor > | |
std::map< K, boost::shared_ptr< ResultType > > | executeOnEntries (const EntryProcessor &entryProcessor, const query::Predicate &predicate) |
Applies the user defined EntryProcessor to the all entries in the map. More... | |
void | set (const K &key, const V &value) |
Puts an entry into this map. More... | |
void | set (const K &key, const V &value, long ttl) |
Puts an entry into this map. More... | |
int | size () |
Returns the number of key-value mappings in this map. More... | |
bool | isEmpty () |
Returns true if this map contains no key-value mappings. More... | |
void | putAll (const std::map< K, V > &entries) |
Copies all of the mappings from the specified map to this map (optional operation). More... | |
void | clear () |
Removes all of the mappings from this map (optional operation). More... | |
void | destroy () |
Destroys this object cluster-wide. More... | |
monitor::LocalMapStats & | getLocalMapStats () |
Returns LocalMapStats for this map. More... | |
Static Public Attributes | |
static const std::string | SERVICE_NAME = "hz:impl:mapService" |
Friends | |
class | spi::ProxyManager |
class | impl::HazelcastClientInstanceImpl |
class | adaptor::RawPointerMap< K, V > |
Concurrent, distributed, observable and queryable map client.
Notice that this class have a private constructor. You can access get an IMap in the following way
ClientConfig clientConfig; HazelcastClient client(clientConfig); IMap<int,std::string> imap = client.getMap<int,std::string>("aKey");
<K> | key |
<V> | value |
|
inline |
Adds an entry listener for this map.
Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. otherwise it will slow down the system.
Warning 2: Do not make a call to hazelcast. It can cause deadlock.
listener | entry listener |
includeValue | true if EntryEvent should contain the value. |
|
inline |
Adds an entry listener for this map.
Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. otherwise it will slow down the system.
Warning 2: Do not make a call to hazelcast. It can cause deadlock.
listener | entry listener |
predicate | The query filter to use when returning the events to the user. |
includeValue | true if EntryEvent should contain the value. |
|
inline |
Adds the specified entry listener for the specified key.
Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. otherwise it will slow down the system.
Warning 2: Do not make a call to hazelcast. It can cause deadlock.
listener | entry listener |
key | key to listen |
includeValue | true if EntryEvent should contain the value. |
|
inline |
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 : public serialization::Portable { //... private: bool active; int age; std::string name;
}
If you are querying your values mostly based on age and active then you should consider indexing these fields.
IMap<std::string, Employee > imap = hazelcastInstance.getMap<std::string, Employee >("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
In the server side, Index 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 value |
ordered | true if index should be ordered, false otherwise. |
|
inline |
Adds an interceptor for this map.
Added interceptor will intercept operations and execute user defined methods and will cancel operations if user defined method throw exception.
Interceptor should extend either Portable or IdentifiedSerializable. Notice that map interceptor runs on the nodes. Because of that same class should be implemented in java side with same classId and factoryId.
interceptor | map interceptor |
|
inline |
Removes all of the mappings from this map (optional operation).
The map will be empty after this call returns.
|
inline |
check if this map contains key.
key |
IClassCastException | if the type of the specified element is incompatible with the server side. |
|
inline |
check if this map contains value.
value |
IClassCastException | if the type of the specified element is incompatible with the server side. |
|
inline |
removes entry from map.
Does not return anything.
key | The key of the map entry to remove. |
IClassCastException | if the type of the specified element is incompatible with the server side. |
|
inline |
Destroys this object cluster-wide.
Clears and releases all resources for this object.
|
inline |
Returns a std::vector< std::pair<K, V> > clone of the mappings contained in this map.
The vector is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.
|
inline |
Queries the map based on the specified predicate and returns the matching entries.
Specified predicate runs on all members in parallel.
predicate | query criteria |
|
inline |
Queries the map based on the specified predicate and returns the matching entries.
Specified predicate runs on all members in parallel.
predicate | query criteria |
|
inline |
Queries the map based on the specified predicate and returns the matching entries.
Specified predicate runs on all members in parallel.
predicate | query criteria |
|
inline |
Evicts the specified key from this map.
If a MapStore
defined for this map, then the entry is not deleted from the underlying MapStore
, evict only removes the entry from the memory.
key | key to evict |
true
if the key is evicted, false
otherwise.
|
inline |
Evicts all keys from this map except locked ones.
If a MapStore
is defined for this map, deleteAll is not called by this method. If you do want to deleteAll to be called use the clear() method.
The EVICT_ALL event is fired for any registered listeners. See EntryListener::mapEvicted(MapEvent)}.
|
inline |
Applies the user defined EntryProcessor to the all entries in the map.
Returns the results mapped by each key in the map.
EntryProcessor should extend either Portable or IdentifiedSerializable. Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side with same classId and factoryId.
ResultType | that entry processor will return |
EntryProcessor | type of entry processor class |
entryProcessor | that will be applied |
|
inline |
Applies the user defined EntryProcessor to the all entries in the map. Returns the results mapped by each key in the map.
EntryProcessor should extend either Portable or IdentifiedSerializable. Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side with same classId and factoryId.
ResultType | that entry processor will return |
EntryProcessor | type of entry processor class |
predicate | The filter to apply for selecting the entries at the server side. |
entryProcessor | that will be applied |
|
inline |
Applies the user defined EntryProcessor to the all entries in the map.
Returns the results mapped by each key in the map.
EntryProcessor should extend either Portable or IdentifiedSerializable. Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side with same classId and factoryId.
ResultType | that entry processor will return |
EntryProcessor | type of entry processor class |
predicate | The filter to apply for selecting the entries at the server side. |
entryProcessor | that will be applied |
|
inline |
Applies the user defined EntryProcessor to the entry mapped by the key.
Returns the the ResultType which is result of the process() method of EntryProcessor.
EntryProcessor should extend either Portable or IdentifiedSerializable. Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side with same classId and factoryId.
EntryProcessor | type of entry processor class |
ResultType | that entry processor will return |
entryProcessor | that will be applied |
key | of entry that entryProcessor will be applied on |
|
inline |
Applies the user defined EntryProcessor to the entries mapped by the collection of keys.
Returns the results mapped by each key in the map.
Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side
ResultType | that entry processor will return |
EntryProcessor | type of entry processor class |
keys | The keys for which the entry processor will be applied. |
entryProcessor | that will be applied |
|
inline |
Releases the lock for the specified key regardless of the lock owner.
It always successfully unlocks the key, never blocks and returns immediately.
key | key to lock. |
|
inline |
get the value.
key |
IClassCastException | if the type of the specified element is incompatible with the server side. |
|
inline |
Returns the entries for the given keys.
keys | keys to get |
|
inline |
|
inline |
Returns LocalMapStats for this map.
LocalMapStats is the statistics for the local portion of this distributed map and contains information such as ownedEntryCount backupEntryCount, lastUpdateTime, lockedEntryCount.
Since this stats are only for the local portion of this map, if you need the cluster-wide MapStats then you need to get the LocalMapStats from all members of the cluster and combine them.
|
inline |
Returns true
if this map contains no key-value mappings.
true
if this map contains no key-value mappings
|
inline |
Checks the lock for the specified key.
If the lock is acquired then returns true, else false.
key | key to lock to be checked. |
true
if lock is acquired, false
otherwise.
|
inline |
Returns a vector clone of the keys contained in this map.
The vector is NOT backed by the map, so changes to the map are NOT reflected in the vector, and vice-versa.
|
inline |
Queries the map based on the specified predicate and returns the keys of matching entries.
Specified predicate runs on all members in parallel.
predicate | query criteria |
|
inline |
Queries the map based on the specified predicate and returns the keys of matching entries.
Specified predicate runs on all members in parallel.
predicate | query criteria |
|
inline |
Queries the map based on the specified predicate and returns the keys of matching entries.
Specified predicate runs on all members in parallel.
predicate | query criteria |
|
inline |
Acquires the lock for the specified key.
If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.
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. |
|
inline |
Acquires the lock for the specified key for the specified lease time.
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.
key | key to lock. |
leaseTime | time in milliseconds to wait before releasing the lock. |
|
inline |
put new entry into map.
key | |
value |
IClassCastException | if the type of the specified elements are incompatible with the server side. then returns NULL in shared_ptr. |
|
inline |
Puts an entry into this map with a given ttl (time to live) value.
Entry will expire and get evicted after the ttl. If ttl is 0, then the entry lives forever.
key | key of the entry |
value | value of the entry |
ttlInMillis | maximum time for this entry to stay in the map in milliseconds,0 means infinite. |
|
inline |
Copies all of the mappings from the specified map to this map (optional operation).
The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k
to value v
in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
entries | mappings to be stored in this map |
|
inline |
Puts an entry into this map, if the specified key is not already associated with a value.
key | key with which the specified value is to be associated |
value |
|
inline |
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.
key | key of the entry |
value | value of the entry |
ttlInMillis | maximum time in milliseconds for this entry to stay in the map |
|
inline |
Same as 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.
key | key of the entry |
value | value of the entry |
ttlInMillis | maximum time for this entry to stay in the map in milliseconds, 0 means infinite. |
|
inline |
remove entry form map
key |
IClassCastException | if the type of the specified element is incompatible with the server side. |
|
inline |
removes entry from map if there is an entry with same key and value.
key | |
value |
IClassCastException | if the type of the specified element is incompatible with the server side. |
|
inline |
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 callers Near Cache.
predicate | matching entries with this predicate will be removed from this map |
|
inline |
Removes the specified entry listener Returns silently if there is no such listener added before.
registrationId | id of registered listener |
|
inline |
Removes the given interceptor for this map.
So it will not intercept operations anymore.
id | registration id of map interceptor |
|
inline |
Replaces the entry for a key only if currently mapped to a given value.
key | key with which the specified value is associated |
oldValue | value expected to be associated with the specified key |
newValue |
true
if the value was replaced
|
inline |
Replaces the entry for a key only if currently mapped to some value.
key | key with which the specified value is associated |
value |
|
inline |
Puts an entry into this map.
Similar to put operation except that set doesn't return the old value which is more efficient.
key | |
value |
|
inline |
Puts an entry into this map.
Similar to put operation except that set doesn't return the old value which is more efficient.
key | key with which the specified value is associated |
value | |
ttl | maximum time in milliseconds for this entry to stay in the map 0 means infinite. |
|
inline |
Returns the number of key-value mappings in this map.
If the map contains more than Integer.MAX_VALUE
elements, returns Integer.MAX_VALUE
.
|
inline |
|
inline |
Tries to acquire the lock for the specified key.
If the lock is not available then the current thread doesn't wait and returns false immediately.
key | key to lock. |
true
if lock is acquired, false
otherwise.
|
inline |
Tries to acquire the lock for the specified key.
If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
key | key to lock in this map |
timeInMillis | maximum time in milliseconds to wait for the lock |
true
if the lock was acquired and false
if the waiting time elapsed before the lock was acquired.
|
inline |
Tries to put the given key, value into this map within specified timeout value.
If this method returns false, it means that the caller thread couldn't acquire the lock for the key within timeout duration, thus put operation is not successful.
key | key of the entry |
value | value of the entry |
timeoutInMillis | maximum time to wait in milliseconds |
true
if the put is successful, false
otherwise.
|
inline |
Tries to remove the entry with the given key from this map within specified timeout value.
If the key is already locked by another thread and/or member, then this operation will wait timeout amount for acquiring the lock.
key | key of the entry |
timeoutInMillis | maximum time in milliseconds to wait for acquiring the lock for the key |
|
inline |
Releases the lock for the specified key.
It never blocks and returns immediately.
If the current thread is the holder of this lock then the hold count is decremented. If the hold count is now zero then the lock is released. If the current thread is not the holder of this lock then IllegalMonitorStateException is thrown.
key | key to lock. |
IllegalMonitorStateException | if the current thread does not hold this lock MTODO |
|
inline |
Returns a vector clone of the values contained in this map.
The vector is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.
|
inline |
Returns a vector clone of the values contained in this map. The vector is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.
predicate | the criteria for values to match |
|
inline |
Returns a vector clone of the values contained in this map.
The vector is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.
predicate | the criteria for values to match |
|
inline |
Returns a vector clone of the values contained in this map.
The vector is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.
predicate | the criteria for values to match |