16 #ifndef HAZELCAST_IMAP 17 #define HAZELCAST_IMAP 25 #include "hazelcast/client/protocol/codec/MapAddEntryListenerWithPredicateCodec.h" 26 #include "hazelcast/client/impl/EntryArrayImpl.h" 27 #include "hazelcast/client/proxy/IMapImpl.h" 28 #include "hazelcast/client/impl/EntryEventHandler.h" 29 #include "hazelcast/client/EntryListener.h" 30 #include "hazelcast/client/EntryView.h" 31 #include "hazelcast/client/map/ClientMapProxy.h" 32 #include "hazelcast/client/Future.h" 34 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 36 #pragma warning(disable: 4251) //for dll export 41 class HazelcastClient;
44 template<
typename K,
typename V>
65 template<
typename K,
typename V>
67 friend class spi::ProxyManager;
69 friend class impl::HazelcastClientInstanceImpl;
74 static const std::string SERVICE_NAME;
83 return mapImpl->containsKey(key);
93 return mapImpl->containsValue(value);
103 boost::shared_ptr<V>
get(
const K &key) {
104 return mapImpl->get(key);
115 boost::shared_ptr<V>
put(
const K &key,
const V &value) {
116 return mapImpl->put(key, value);
130 boost::shared_ptr<V>
put(
const K &key,
const V &value, int64_t ttlInMillis) {
131 return mapImpl->put(key, value, ttlInMillis);
141 boost::shared_ptr<V>
remove(
const K &key) {
142 return mapImpl->remove(key);
154 mapImpl->removeAll(predicate);
164 bool remove(
const K &key,
const V &value) {
165 return mapImpl->remove(key, value);
175 mapImpl->deleteEntry(key);
197 return mapImpl->tryRemove(key, timeoutInMillis);
212 bool tryPut(
const K &key,
const V &value, int64_t timeoutInMillis) {
213 return mapImpl->tryPut(key, value, timeoutInMillis);
226 mapImpl->putTransient(key, value, ttlInMillis);
238 return mapImpl->putIfAbsent(key, value);
252 boost::shared_ptr<V>
putIfAbsent(
const K &key,
const V &value, int64_t ttlInMillis) {
253 return mapImpl->putIfAbsent(key, value, ttlInMillis);
263 bool replace(
const K &key,
const V &oldValue,
const V &newValue) {
264 return mapImpl->replace(key, oldValue, newValue);
274 boost::shared_ptr<V>
replace(
const K &key,
const V &value) {
275 return mapImpl->replace(key, value);
314 void lock(
const K &key, int64_t leaseTime) {
315 mapImpl->lock(key, leaseTime);
327 return mapImpl->isLocked(key);
340 return mapImpl->tryLock(key);
359 bool tryLock(
const K &key, int64_t timeInMillis) {
360 return mapImpl->tryLock(key, timeInMillis);
377 mapImpl->unlock(key);
389 mapImpl->forceUnlock(key);
403 template<
typename MapInterceptor>
405 return mapImpl->template addInterceptor<MapInterceptor>(interceptor);
415 mapImpl->removeInterceptor(
id);
433 return mapImpl->addEntryListener(listener, includeValue);
453 return mapImpl->addEntryListener(listener, predicate, includeValue);
466 return mapImpl->removeEntryListener(registrationId);
484 return mapImpl->addEntryListener(listener, key, includeValue);
496 return mapImpl->getEntryView(key);
510 return mapImpl->evict(key);
534 std::map<K, V>
getAll(
const std::set<K> &keys) {
535 return mapImpl->getAll(keys);
546 return mapImpl->keySet();
562 return mapImpl->keySet(predicate);
577 return mapImpl->keySet(predicate);
592 return mapImpl->keySet(predicate);
603 return mapImpl->values();
617 return mapImpl->values(predicate);
629 return mapImpl->values(predicate);
642 return mapImpl->values(predicate);
653 return mapImpl->entrySet();
669 return mapImpl->entrySet(predicate);
683 return mapImpl->entrySet(predicate);
697 return mapImpl->entrySet(predicate);
732 void addIndex(
const std::string &attribute,
bool ordered) {
733 mapImpl->addIndex(attribute, ordered);
750 template<
typename ResultType,
typename EntryProcessor>
751 boost::shared_ptr<ResultType>
executeOnKey(
const K &key,
const EntryProcessor &entryProcessor) {
752 return mapImpl->template executeOnKey<ResultType, EntryProcessor>(key, entryProcessor);
767 template<
typename ResultType,
typename EntryProcessor>
768 std::map<K, boost::shared_ptr<ResultType> >
769 executeOnKeys(
const std::set<K> &keys,
const EntryProcessor &entryProcessor) {
770 return mapImpl->template executeOnKeys<ResultType, EntryProcessor>(keys, entryProcessor);
782 template<
typename ResultType,
typename EntryProcessor>
784 return mapImpl->template submitToKey<ResultType, EntryProcessor>(key, entryProcessor);
800 template<
typename ResultType,
typename EntryProcessor>
801 std::map<K, boost::shared_ptr<ResultType> >
executeOnEntries(
const EntryProcessor &entryProcessor) {
802 return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor);
822 template<
typename ResultType,
typename EntryProcessor>
823 std::map<K, boost::shared_ptr<ResultType> >
executeOnEntries(
const EntryProcessor &entryProcessor,
825 return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor, predicate);
842 template<
typename ResultType,
typename EntryProcessor>
843 std::map<K, boost::shared_ptr<ResultType> >
845 return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor, predicate);
855 void set(
const K &key,
const V &value) {
856 mapImpl->set(key, value);
868 void set(
const K &key,
const V &value, int64_t ttl) {
869 mapImpl->set(key, value, ttl);
880 return mapImpl->size();
889 return mapImpl->isEmpty();
903 void putAll(
const std::map<K, V> &entries) {
904 return mapImpl->putAll(entries);
936 return mapImpl->getLocalMapStats();
978 boost::shared_ptr<ICompletableFuture<V> >
getAsync(
const K &key) {
979 return mapImpl->getAsync(key);
1037 boost::shared_ptr<ICompletableFuture<V> >
putAsync(
const K &key,
const V &value) {
1038 return mapImpl->putAsync(key, value);
1107 boost::shared_ptr<ICompletableFuture<V> >
1108 putAsync(
const K &key,
const V &value, int64_t ttl,
const util::concurrent::TimeUnit &ttlUnit) {
1109 return mapImpl->putAsync(key, value, ttl, ttlUnit);
1185 boost::shared_ptr<ICompletableFuture<V> >
1186 putAsync(
const K &key,
const V &value, int64_t ttl,
const util::concurrent::TimeUnit &ttlUnit,
1187 int64_t maxIdle,
const util::concurrent::TimeUnit &maxIdleUnit) {
1188 return mapImpl->putAsync(key, value, ttl, ttlUnit, maxIdle, maxIdleUnit);
1238 boost::shared_ptr<ICompletableFuture<void> >
setAsync(
const K &key,
const V &value) {
1239 return mapImpl->setAsync(key, value);
1303 boost::shared_ptr<ICompletableFuture<void> >
1304 setAsync(
const K &key,
const V &value, int64_t ttl,
const util::concurrent::TimeUnit &ttlUnit) {
1305 return mapImpl->setAsync(key, value, ttl, ttlUnit);
1372 boost::shared_ptr<ICompletableFuture<void> >
1373 setAsync(
const K &key,
const V &value, int64_t ttl,
const util::concurrent::TimeUnit &ttlUnit,
1374 int64_t maxIdle,
const util::concurrent::TimeUnit &maxIdleUnit) {
1375 return mapImpl->setAsync(key, value, ttl, ttlUnit, maxIdle, maxIdleUnit);
1403 return mapImpl->removeAsync(key);
1407 IMap(boost::shared_ptr<spi::ClientProxy> clientProxy) {
1408 mapImpl = boost::static_pointer_cast<map::ClientMapProxy<K, V> >(clientProxy);
1411 boost::shared_ptr<map::ClientMapProxy<K, V> > mapImpl;
1414 template<
typename K,
typename V>
1415 const std::string IMap<K, V>::SERVICE_NAME =
"hz:impl:mapService";
1419 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 1420 #pragma warning(pop) void removeAll(const query::Predicate &predicate)
Removes all entries which match with the supplied predicate.
Definition: IMap.h:153
std::vector< std::pair< K, V > > entrySet()
Returns a std::vector< std::pair<K, V> > clone of the mappings contained in this map.
Definition: IMap.h:652
std::map< K, V > getAll(const std::set< K > &keys)
Returns the entries for the given keys.
Definition: IMap.h:534
void putAll(const std::map< K, V > &entries)
Copies all of the mappings from the specified map to this map (optional operation).
Definition: IMap.h:903
void destroy()
Destroys this object cluster-wide.
Definition: IMap.h:919
bool tryLock(const K &key, int64_t timeInMillis)
Tries to acquire the lock for the specified key.
Definition: IMap.h:359
std::map< K, boost::shared_ptr< ResultType > > executeOnEntries(const EntryProcessor &entryProcessor, const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:823
boost::shared_ptr< V > replace(const K &key, const V &value)
Replaces the entry for a key only if currently mapped to some value.
Definition: IMap.h:274
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: IMap.h:339
Map Entry listener to get notified when a map entry is added, removed, updated or evicted...
Definition: EntryListener.h:45
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...
Definition: IMap.h:769
boost::shared_ptr< ICompletableFuture< V > > removeAsync(const K &key)
Asynchronously removes the given key, returning an ICompletableFuture on which the caller can provide...
Definition: IMap.h:1402
std::vector< V > values(const query::Predicate &predicate)
Returns a vector clone of the values contained in this map.
Definition: IMap.h:628
std::vector< V > values()
Returns a vector clone of the values contained in this map.
Definition: IMap.h:602
boost::shared_ptr< ICompletableFuture< void > > setAsync(const K &key, const V &value, int64_t ttl, const util::concurrent::TimeUnit &ttlUnit)
Asynchronously puts an entry into this map with a given TTL (time to live) value, without returning t...
Definition: IMap.h:1304
void deleteEntry(const K &key)
removes entry from map.
Definition: IMap.h:174
void evictAll()
Evicts all keys from this map except locked ones.
Definition: IMap.h:524
std::string addEntryListener(EntryListener< K, V > &listener, bool includeValue)
Adds an entry listener for this map.
Definition: IMap.h:432
bool tryRemove(const K &key, int64_t timeoutInMillis)
Tries to remove the entry with the given key from this map within specified timeout value...
Definition: IMap.h:196
boost::shared_ptr< ICompletableFuture< V > > putAsync(const K &key, const V &value, int64_t ttl, const util::concurrent::TimeUnit &ttlUnit, int64_t maxIdle, const util::concurrent::TimeUnit &maxIdleUnit)
Asynchronously puts the given key and value into this map with a given TTL (time to live) value and m...
Definition: IMap.h:1186
boost::shared_ptr< ICompletableFuture< void > > setAsync(const K &key, const V &value)
Asynchronously puts the given key and value.
Definition: IMap.h:1238
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.
Definition: IMap.h:844
std::vector< K > keySet()
Returns a vector clone of the keys contained in this map.
Definition: IMap.h:545
Definition: LocalMapStats.h:31
boost::shared_ptr< ICompletableFuture< void > > setAsync(const K &key, const V &value, int64_t ttl, const util::concurrent::TimeUnit &ttlUnit, int64_t maxIdle, const util::concurrent::TimeUnit &maxIdleUnit)
Asynchronously puts an entry into this map with a given TTL (time to live) value and max idle time va...
Definition: IMap.h:1373
std::string addEntryListener(EntryListener< K, V > &listener, const K &key, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: IMap.h:483
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.
Definition: IMap.h:696
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.
Definition: IMap.h:263
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...
Definition: IMap.h:237
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: IdentifiedDataSerializable.h:47
NOTE: PagingPredicate can only be used with values(), keySet() and entries() methods!!! ...
Definition: PagingPredicate.h:127
void addIndex(const std::string &attribute, bool ordered)
Adds an index to this map for the specified entries so that queries can run faster.
Definition: IMap.h:732
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: IMap.h:326
std::vector< K > keySet(const query::Predicate &predicate)
Queries the map based on the specified predicate and returns the keys of matching entries...
Definition: IMap.h:576
std::map< K, boost::shared_ptr< ResultType > > executeOnEntries(const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: IMap.h:801
void flush()
If this map has a MapStore this method flushes all the local dirty entries by calling MapStore...
Definition: IMap.h:182
std::string addInterceptor(MapInterceptor &interceptor)
Adds an interceptor for this map.
Definition: IMap.h:404
void putTransient(const K &key, const V &value, int64_t ttlInMillis)
Same as put(K, V, int64_t, TimeUnit) but MapStore, if defined, will not be called to store/persist th...
Definition: IMap.h:225
void lock(const K &key, int64_t leaseTime)
Acquires the lock for the specified key for the specified lease time.
Definition: IMap.h:314
Adaptor class to IMap which provides releasable raw pointers for returned objects.
Definition: RawPointerMap.h:51
void lock(const K &key)
Acquires the lock for the specified key.
Definition: IMap.h:292
void removeInterceptor(const std::string &id)
Removes the given interceptor for this map.
Definition: IMap.h:414
std::string addEntryListener(EntryListener< K, V > &listener, const query::Predicate &predicate, bool includeValue)
Adds an entry listener for this map.
Definition: IMap.h:452
This is a unique Future.
Definition: Future.h:105
bool tryPut(const K &key, const V &value, int64_t timeoutInMillis)
Tries to put the given key, value into this map within specified timeout value.
Definition: IMap.h:212
boost::shared_ptr< ICompletableFuture< V > > getAsync(const K &key)
Asynchronously gets the given key.
Definition: IMap.h:978
boost::shared_ptr< ResultType > executeOnKey(const K &key, const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key.
Definition: IMap.h:751
This is a marker class for Predicate classes.
Definition: Predicate.h:36
std::vector< std::pair< K, V > > entrySet(const query::Predicate &predicate)
Queries the map based on the specified predicate and returns the matching entries.
Definition: IMap.h:682
EntryView represents a readonly view of a map entry.
Definition: EntryView.h:41
std::vector< K > keySet(const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:561
boost::shared_ptr< V > put(const K &key, const V &value, int64_t ttlInMillis)
Puts an entry into this map with a given ttl (time to live) value.
Definition: IMap.h:130
Concurrent, distributed, observable and queryable map client.
Definition: IMap.h:66
bool isEmpty()
Returns true if this map contains no key-value mappings.
Definition: IMap.h:888
void unlock(const K &key)
Releases the lock for the specified key.
Definition: IMap.h:376
boost::shared_ptr< V > putIfAbsent(const K &key, const V &value, int64_t ttlInMillis)
Puts an entry into this map with a given ttl (time to live) value if the specified key is not already...
Definition: IMap.h:252
Future< ResultType > submitToKey(const K &key, const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key.
Definition: IMap.h:783
bool evict(const K &key)
Evicts the specified key from this map.
Definition: IMap.h:509
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: IMap.h:388
monitor::LocalMapStats & getLocalMapStats()
Returns LocalMapStats for this map.
Definition: IMap.h:935
std::vector< V > values(const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:616
void clear()
Removes all of the mappings from this map (optional operation).
Definition: IMap.h:911
std::vector< V > values(query::PagingPredicate< K, V > &predicate)
Returns a vector clone of the values contained in this map.
Definition: IMap.h:641
boost::shared_ptr< V > put(const K &key, const V &value)
put new entry into map.
Definition: IMap.h:115
EntryView< K, V > getEntryView(const K &key)
Returns the EntryView for the specified key.
Definition: IMap.h:495
boost::shared_ptr< ICompletableFuture< V > > putAsync(const K &key, const V &value, int64_t ttl, const util::concurrent::TimeUnit &ttlUnit)
Asynchronously puts the given key and value into this map with a given TTL (time to live) value...
Definition: IMap.h:1108
bool containsValue(const V &value)
check if this map contains value.
Definition: IMap.h:92
boost::shared_ptr< ICompletableFuture< V > > putAsync(const K &key, const V &value)
Asynchronously puts the given key and value.
Definition: IMap.h:1037
std::vector< K > keySet(query::PagingPredicate< K, V > &predicate)
Queries the map based on the specified predicate and returns the keys of matching entries...
Definition: IMap.h:591
bool containsKey(const K &key)
check if this map contains key.
Definition: IMap.h:82
std::vector< std::pair< K, V > > entrySet(const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:668
bool removeEntryListener(const std::string ®istrationId)
Removes the specified entry listener Returns silently if there is no such listener added before...
Definition: IMap.h:465
int size()
Returns the number of key-value mappings in this map.
Definition: IMap.h:879