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"
33 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
35 #pragma warning(disable: 4251) //for dll export
40 class HazelcastClient;
43 template<
typename K,
typename V>
64 template<
typename K,
typename V>
66 friend class spi::ProxyManager;
71 static const std::string SERVICE_NAME;
80 return mapImpl->containsKey(key);
90 return mapImpl->containsValue(value);
100 boost::shared_ptr<V>
get(
const K &key) {
101 return mapImpl->get(key);
112 boost::shared_ptr<V>
put(
const K &key,
const V &value) {
113 return mapImpl->put(key, value);
127 boost::shared_ptr<V>
put(
const K &key,
const V &value,
long ttlInMillis) {
128 return mapImpl->put(key, value, ttlInMillis);
138 boost::shared_ptr<V>
remove(
const K &key) {
139 return mapImpl->remove(key);
149 bool remove(
const K &key,
const V &value) {
150 return mapImpl->remove(key, value);
160 mapImpl->deleteEntry(key);
182 return mapImpl->tryRemove(key, timeoutInMillis);
197 bool tryPut(
const K &key,
const V &value,
long timeoutInMillis) {
198 return mapImpl->tryPut(key, value, timeoutInMillis);
211 mapImpl->putTransient(key, value, ttlInMillis);
223 return mapImpl->putIfAbsent(key, value);
237 boost::shared_ptr<V>
putIfAbsent(
const K &key,
const V &value,
long ttlInMillis) {
238 return mapImpl->putIfAbsent(key, value, ttlInMillis);
248 bool replace(
const K &key,
const V &oldValue,
const V &newValue) {
249 return mapImpl->replace(key, oldValue, newValue);
259 boost::shared_ptr<V>
replace(
const K &key,
const V &value) {
260 return mapImpl->replace(key, value);
299 void lock(
const K &key,
long leaseTime) {
300 mapImpl->lock(key, leaseTime);
312 return mapImpl->isLocked(key);
325 return mapImpl->tryLock(key);
344 bool tryLock(
const K &key,
long timeInMillis) {
345 return mapImpl->tryLock(key, timeInMillis);
362 mapImpl->unlock(key);
374 mapImpl->forceUnlock(key);
388 template<
typename MapInterceptor>
390 return mapImpl->template addInterceptor<MapInterceptor>(interceptor);
400 mapImpl->removeInterceptor(
id);
418 return mapImpl->addEntryListener(listener, includeValue);
438 return mapImpl->addEntryListener(listener, predicate, includeValue);
451 return mapImpl->removeEntryListener(registrationId);
469 return mapImpl->addEntryListener(listener, key, includeValue);
481 return mapImpl->getEntryView(key);
495 return mapImpl->evict(key);
519 std::map<K, V>
getAll(
const std::set<K> &keys) {
520 return mapImpl->getAll(keys);
531 return mapImpl->keySet();
547 return mapImpl->keySet(predicate);
562 return mapImpl->keySet(predicate);
577 return mapImpl->keySet(predicate);
588 return mapImpl->values();
602 return mapImpl->values(predicate);
614 return mapImpl->values(predicate);
627 return mapImpl->values(predicate);
638 return mapImpl->entrySet();
654 return mapImpl->entrySet(predicate);
668 return mapImpl->entrySet(predicate);
682 return mapImpl->entrySet(predicate);
717 void addIndex(
const std::string &attribute,
bool ordered) {
718 mapImpl->addIndex(attribute, ordered);
735 template<
typename ResultType,
typename EntryProcessor>
736 boost::shared_ptr<ResultType>
executeOnKey(
const K &key, EntryProcessor &entryProcessor) {
737 return mapImpl->template executeOnKey<ResultType, EntryProcessor>(key, entryProcessor);
753 template<
typename ResultType,
typename EntryProcessor>
754 std::map<K, boost::shared_ptr<ResultType> >
executeOnEntries(EntryProcessor &entryProcessor) {
755 return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor);
775 template<
typename ResultType,
typename EntryProcessor>
776 std::map<K, boost::shared_ptr<ResultType> >
executeOnEntries(EntryProcessor &entryProcessor,
778 return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor, predicate);
795 template<
typename ResultType,
typename EntryProcessor>
796 std::map<K, boost::shared_ptr<ResultType> >
798 return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor, predicate);
808 void set(
const K &key,
const V &value) {
809 mapImpl->set(key, value);
821 void set(
const K &key,
const V &value,
long ttl) {
822 mapImpl->set(key, value, ttl);
833 return mapImpl->size();
842 return mapImpl->isEmpty();
856 void putAll(
const std::map<K, V> &entries) {
857 return mapImpl->putAll(entries);
889 return mapImpl->getLocalMapStats();
892 IMap(boost::shared_ptr<spi::ClientProxy> clientProxy) {
893 mapImpl = boost::static_pointer_cast<map::ClientMapProxy<K, V> >(clientProxy);
896 boost::shared_ptr<map::ClientMapProxy<K, V> > mapImpl;
899 template <
typename K,
typename V>
900 const std::string IMap<K, V>::SERVICE_NAME =
"hz:impl:mapService";
904 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
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:210
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:637
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:237
std::map< K, V > getAll(const std::set< K > &keys)
Returns the entries for the given keys.
Definition: IMap.h:519
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:856
void destroy()
Destroys this object cluster-wide.
Definition: IMap.h:872
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:259
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: IMap.h:324
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:344
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:197
void set(const K &key, const V &value)
Puts an entry into this map.
Definition: IMap.h:808
std::vector< V > values(const query::Predicate &predicate)
Returns a vector clone of the values contained in this map.
Definition: IMap.h:613
std::vector< V > values()
Returns a vector clone of the values contained in this map.
Definition: IMap.h:587
void deleteEntry(const K &key)
removes entry from map.
Definition: IMap.h:159
void evictAll()
Evicts all keys from this map except locked ones.
Definition: IMap.h:509
std::map< K, boost::shared_ptr< ResultType > > executeOnEntries(EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: IMap.h:754
std::string addEntryListener(EntryListener< K, V > &listener, bool includeValue)
Adds an entry listener for this map.
Definition: IMap.h:417
std::vector< K > keySet()
Returns a vector clone of the keys contained in this map.
Definition: IMap.h:530
Definition: LocalMapStats.h:31
void set(const K &key, const V &value, long ttl)
Puts an entry into this map.
Definition: IMap.h:821
std::string addEntryListener(EntryListener< K, V > &listener, const K &key, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: IMap.h:468
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:681
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:248
std::map< K, boost::shared_ptr< ResultType > > executeOnEntries(EntryProcessor &entryProcessor, const query::Predicate &predicate)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: IMap.h:797
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:222
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: IdentifiedDataSerializable.h:42
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:717
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: IMap.h:311
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:561
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:127
void flush()
If this map has a MapStore this method flushes all the local dirty entries by calling MapStore...
Definition: IMap.h:167
std::string addInterceptor(MapInterceptor &interceptor)
Adds an interceptor for this map.
Definition: IMap.h:389
std::map< K, boost::shared_ptr< ResultType > > executeOnEntries(EntryProcessor &entryProcessor, const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:776
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:277
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:181
void lock(const K &key, long leaseTime)
Acquires the lock for the specified key for the specified lease time.
Definition: IMap.h:299
void removeInterceptor(const std::string &id)
Removes the given interceptor for this map.
Definition: IMap.h:399
std::string addEntryListener(EntryListener< K, V > &listener, const query::Predicate &predicate, bool includeValue)
Adds an entry listener for this map.
Definition: IMap.h:437
This is a merker 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:667
EntryView represents a readonly view of a map entry.
Definition: EntryView.h:39
std::vector< K > keySet(const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:546
Concurrent, distributed, observable and queryable map client.
Definition: IMap.h:65
bool isEmpty()
Returns true if this map contains no key-value mappings.
Definition: IMap.h:841
void unlock(const K &key)
Releases the lock for the specified key.
Definition: IMap.h:361
bool evict(const K &key)
Evicts the specified key from this map.
Definition: IMap.h:494
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: IMap.h:373
monitor::LocalMapStats & getLocalMapStats()
Returns LocalMapStats for this map.
Definition: IMap.h:888
std::vector< V > values(const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:601
void clear()
Removes all of the mappings from this map (optional operation).
Definition: IMap.h:864
std::vector< V > values(query::PagingPredicate< K, V > &predicate)
Returns a vector clone of the values contained in this map.
Definition: IMap.h:626
boost::shared_ptr< V > put(const K &key, const V &value)
put new entry into map.
Definition: IMap.h:112
EntryView< K, V > getEntryView(const K &key)
Returns the EntryView for the specified key.
Definition: IMap.h:480
bool containsValue(const V &value)
check if this map contains value.
Definition: IMap.h:89
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:576
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:458
bool containsKey(const K &key)
check if this map contains key.
Definition: IMap.h:79
std::vector< std::pair< K, V > > entrySet(const serialization::IdentifiedDataSerializable &predicate)
Definition: IMap.h:653
bool removeEntryListener(const std::string ®istrationId)
Removes the specified entry listener Returns silently if there is no such listener added before...
Definition: IMap.h:450
int size()
Returns the number of key-value mappings in this map.
Definition: IMap.h:832
boost::shared_ptr< ResultType > executeOnKey(const K &key, EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key.
Definition: IMap.h:736