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;
68 friend class impl::HazelcastClientInstanceImpl;
72 static const std::string SERVICE_NAME;
81 return mapImpl->containsKey(key);
91 return mapImpl->containsValue(value);
101 boost::shared_ptr<V>
get(
const K &key) {
102 return mapImpl->get(key);
113 boost::shared_ptr<V>
put(
const K &key,
const V &value) {
114 return mapImpl->put(key, value);
128 boost::shared_ptr<V>
put(
const K &key,
const V &value,
long ttlInMillis) {
129 return mapImpl->put(key, value, ttlInMillis);
139 boost::shared_ptr<V>
remove(
const K &key) {
140 return mapImpl->remove(key);
152 mapImpl->removeAll(predicate);
162 bool remove(
const K &key,
const V &value) {
163 return mapImpl->remove(key, value);
173 mapImpl->deleteEntry(key);
195 return mapImpl->tryRemove(key, timeoutInMillis);
210 bool tryPut(
const K &key,
const V &value,
long timeoutInMillis) {
211 return mapImpl->tryPut(key, value, timeoutInMillis);
224 mapImpl->putTransient(key, value, ttlInMillis);
236 return mapImpl->putIfAbsent(key, value);
250 boost::shared_ptr<V>
putIfAbsent(
const K &key,
const V &value,
long ttlInMillis) {
251 return mapImpl->putIfAbsent(key, value, ttlInMillis);
261 bool replace(
const K &key,
const V &oldValue,
const V &newValue) {
262 return mapImpl->replace(key, oldValue, newValue);
272 boost::shared_ptr<V>
replace(
const K &key,
const V &value) {
273 return mapImpl->replace(key, value);
312 void lock(
const K &key,
long leaseTime) {
313 mapImpl->lock(key, leaseTime);
325 return mapImpl->isLocked(key);
338 return mapImpl->tryLock(key);
357 bool tryLock(
const K &key,
long timeInMillis) {
358 return mapImpl->tryLock(key, timeInMillis);
375 mapImpl->unlock(key);
387 mapImpl->forceUnlock(key);
401 template<
typename MapInterceptor>
403 return mapImpl->template addInterceptor<MapInterceptor>(interceptor);
413 mapImpl->removeInterceptor(
id);
431 return mapImpl->addEntryListener(listener, includeValue);
451 return mapImpl->addEntryListener(listener, predicate, includeValue);
464 return mapImpl->removeEntryListener(registrationId);
482 return mapImpl->addEntryListener(listener, key, includeValue);
494 return mapImpl->getEntryView(key);
508 return mapImpl->evict(key);
532 std::map<K, V>
getAll(
const std::set<K> &keys) {
533 return mapImpl->getAll(keys);
544 return mapImpl->keySet();
560 return mapImpl->keySet(predicate);
575 return mapImpl->keySet(predicate);
590 return mapImpl->keySet(predicate);
601 return mapImpl->values();
615 return mapImpl->values(predicate);
627 return mapImpl->values(predicate);
640 return mapImpl->values(predicate);
651 return mapImpl->entrySet();
667 return mapImpl->entrySet(predicate);
681 return mapImpl->entrySet(predicate);
695 return mapImpl->entrySet(predicate);
730 void addIndex(
const std::string &attribute,
bool ordered) {
731 mapImpl->addIndex(attribute, ordered);
748 template<
typename ResultType,
typename EntryProcessor>
749 boost::shared_ptr<ResultType>
executeOnKey(
const K &key,
const EntryProcessor &entryProcessor) {
750 return mapImpl->template executeOnKey<ResultType, EntryProcessor>(key, entryProcessor);
765 template<
typename ResultType,
typename EntryProcessor>
766 std::map<K, boost::shared_ptr<ResultType> >
767 executeOnKeys(
const std::set<K> &keys,
const EntryProcessor &entryProcessor) {
768 return mapImpl->template executeOnKeys<ResultType, EntryProcessor>(keys, entryProcessor);
780 template<
typename ResultType,
typename EntryProcessor>
782 return mapImpl->template submitToKey<ResultType, EntryProcessor>(key, entryProcessor);
798 template<
typename ResultType,
typename EntryProcessor>
799 std::map<K, boost::shared_ptr<ResultType> >
executeOnEntries(
const EntryProcessor &entryProcessor) {
800 return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor);
820 template<
typename ResultType,
typename EntryProcessor>
821 std::map<K, boost::shared_ptr<ResultType> >
executeOnEntries(
const EntryProcessor &entryProcessor,
823 return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor, predicate);
840 template<
typename ResultType,
typename EntryProcessor>
841 std::map<K, boost::shared_ptr<ResultType> >
843 return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor, predicate);
853 void set(
const K &key,
const V &value) {
854 mapImpl->set(key, value);
866 void set(
const K &key,
const V &value,
long ttl) {
867 mapImpl->set(key, value, ttl);
878 return mapImpl->size();
887 return mapImpl->isEmpty();
901 void putAll(
const std::map<K, V> &entries) {
902 return mapImpl->putAll(entries);
934 return mapImpl->getLocalMapStats();
937 IMap(boost::shared_ptr<spi::ClientProxy> clientProxy) {
938 mapImpl = boost::static_pointer_cast<map::ClientMapProxy<K, V> >(clientProxy);
941 boost::shared_ptr<map::ClientMapProxy<K, V> > mapImpl;
944 template <
typename K,
typename V>
945 const std::string IMap<K, V>::SERVICE_NAME =
"hz:impl:mapService";
949 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) void removeAll(const query::Predicate &predicate)
Removes all entries which match with the supplied predicate.
Definition: IMap.h:151
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 e...
Definition: IMap.h:223
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:650
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...
Definition: IMap.h:250
std::map< K, V > getAll(const std::set< K > &keys)
Returns the entries for the given keys.
Definition: IMap.h:532
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:901
void destroy()
Destroys this object cluster-wide.
Definition: IMap.h:917
std::map< K, boost::shared_ptr< ResultType > > executeOnEntries(const EntryProcessor &entryProcessor, const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:821
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:272
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: IMap.h:337
Map Entry listener to get notified when a map entry is added, removed, updated or evicted...
Definition: EntryListener.h:45
bool tryLock(const K &key, long timeInMillis)
Tries to acquire the lock for the specified key.
Definition: IMap.h:357
bool tryPut(const K &key, const V &value, long timeoutInMillis)
Tries to put the given key, value into this map within specified timeout value.
Definition: IMap.h:210
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:767
std::vector< V > values(const query::Predicate &predicate)
Returns a vector clone of the values contained in this map.
Definition: IMap.h:626
std::vector< V > values()
Returns a vector clone of the values contained in this map.
Definition: IMap.h:600
void deleteEntry(const K &key)
removes entry from map.
Definition: IMap.h:172
void evictAll()
Evicts all keys from this map except locked ones.
Definition: IMap.h:522
std::string addEntryListener(EntryListener< K, V > &listener, bool includeValue)
Adds an entry listener for this map.
Definition: IMap.h:430
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:842
std::vector< K > keySet()
Returns a vector clone of the keys contained in this map.
Definition: IMap.h:543
Definition: LocalMapStats.h:31
std::string addEntryListener(EntryListener< K, V > &listener, const K &key, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: IMap.h:481
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:694
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:261
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:235
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:730
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: IMap.h:324
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:574
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.
Definition: IMap.h:128
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:799
void flush()
If this map has a MapStore this method flushes all the local dirty entries by calling MapStore...
Definition: IMap.h:180
std::string addInterceptor(MapInterceptor &interceptor)
Adds an interceptor for this map.
Definition: IMap.h:402
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:290
bool tryRemove(const K &key, long timeoutInMillis)
Tries to remove the entry with the given key from this map within specified timeout value...
Definition: IMap.h:194
void lock(const K &key, long leaseTime)
Acquires the lock for the specified key for the specified lease time.
Definition: IMap.h:312
void removeInterceptor(const std::string &id)
Removes the given interceptor for this map.
Definition: IMap.h:412
std::string addEntryListener(EntryListener< K, V > &listener, const query::Predicate &predicate, bool includeValue)
Adds an entry listener for this map.
Definition: IMap.h:450
This is a unique Future.
Definition: Future.h:105
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:749
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:680
EntryView represents a readonly view of a map entry.
Definition: EntryView.h:41
std::vector< K > keySet(const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:559
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:886
void unlock(const K &key)
Releases the lock for the specified key.
Definition: IMap.h:374
Future< ResultType > submitToKey(const K &key, const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key.
Definition: IMap.h:781
bool evict(const K &key)
Evicts the specified key from this map.
Definition: IMap.h:507
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:386
monitor::LocalMapStats & getLocalMapStats()
Returns LocalMapStats for this map.
Definition: IMap.h:933
std::vector< V > values(const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:614
void clear()
Removes all of the mappings from this map (optional operation).
Definition: IMap.h:909
std::vector< V > values(query::PagingPredicate< K, V > &predicate)
Returns a vector clone of the values contained in this map.
Definition: IMap.h:639
boost::shared_ptr< V > put(const K &key, const V &value)
put new entry into map.
Definition: IMap.h:113
EntryView< K, V > getEntryView(const K &key)
Returns the EntryView for the specified key.
Definition: IMap.h:493
bool containsValue(const V &value)
check if this map contains value.
Definition: IMap.h:90
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:589
bool containsKey(const K &key)
check if this map contains key.
Definition: IMap.h:80
std::vector< std::pair< K, V > > entrySet(const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:666
bool removeEntryListener(const std::string ®istrationId)
Removes the specified entry listener Returns silently if there is no such listener added before...
Definition: IMap.h:463
int size()
Returns the number of key-value mappings in this map.
Definition: IMap.h:877