Hazelcast C++ Client
 All Classes Functions Variables Enumerations Enumerator Pages
IMap.h
1 /*
2  * Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef HAZELCAST_IMAP
17 #define HAZELCAST_IMAP
18 
19 #include <string>
20 #include <map>
21 #include <set>
22 #include <vector>
23 #include <stdexcept>
24 #include <climits>
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 
33 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
34 #pragma warning(push)
35 #pragma warning(disable: 4251) //for dll export
36 #endif
37 
38 namespace hazelcast {
39  namespace client {
40  class HazelcastClient;
41 
42  namespace adaptor {
43  template<typename K, typename V>
44  class RawPointerMap;
45  }
46 
47  namespace spi {
48  class ProxyManager;
49  }
50 
64  template<typename K, typename V>
65  class IMap {
66  friend class spi::ProxyManager;
67  friend class HazelcastClient;
68  friend class adaptor::RawPointerMap<K, V>;
69 
70  public:
71  static const std::string SERVICE_NAME;
72 
79  bool containsKey(const K &key) {
80  return mapImpl->containsKey(key);
81  }
82 
89  bool containsValue(const V &value) {
90  return mapImpl->containsValue(value);
91  }
92 
100  boost::shared_ptr<V> get(const K &key) {
101  return mapImpl->get(key);
102  }
103 
112  boost::shared_ptr<V> put(const K &key, const V &value) {
113  return mapImpl->put(key, value);
114  }
115 
127  boost::shared_ptr<V> put(const K &key, const V &value, long ttlInMillis) {
128  return mapImpl->put(key, value, ttlInMillis);
129  }
130 
138  boost::shared_ptr<V> remove(const K &key) {
139  return mapImpl->remove(key);
140  }
141 
149  bool remove(const K &key, const V &value) {
150  return mapImpl->remove(key, value);
151  }
152 
159  void deleteEntry(const K &key) {
160  mapImpl->deleteEntry(key);
161  }
162 
167  void flush() {
168  mapImpl->flush();
169  }
170 
181  bool tryRemove(const K &key, long timeoutInMillis) {
182  return mapImpl->tryRemove(key, timeoutInMillis);
183  }
184 
197  bool tryPut(const K &key, const V &value, long timeoutInMillis) {
198  return mapImpl->tryPut(key, value, timeoutInMillis);
199  }
200 
210  void putTransient(const K &key, const V &value, long ttlInMillis) {
211  mapImpl->putTransient(key, value, ttlInMillis);
212  }
213 
222  boost::shared_ptr<V> putIfAbsent(const K &key, const V &value) {
223  return mapImpl->putIfAbsent(key, value);
224  }
225 
237  boost::shared_ptr<V> putIfAbsent(const K &key, const V &value, long ttlInMillis) {
238  return mapImpl->putIfAbsent(key, value, ttlInMillis);
239  }
240 
248  bool replace(const K &key, const V &oldValue, const V &newValue) {
249  return mapImpl->replace(key, oldValue, newValue);
250  }
251 
259  boost::shared_ptr<V> replace(const K &key, const V &value) {
260  return mapImpl->replace(key, value);
261  }
262 
277  void lock(const K &key) {
278  mapImpl->lock(key);
279  }
280 
299  void lock(const K &key, long leaseTime) {
300  mapImpl->lock(key, leaseTime);
301  }
302 
311  bool isLocked(const K &key) {
312  return mapImpl->isLocked(key);
313  }
314 
324  bool tryLock(const K &key) {
325  return mapImpl->tryLock(key);
326  }
327 
344  bool tryLock(const K &key, long timeInMillis) {
345  return mapImpl->tryLock(key, timeInMillis);
346  }
347 
361  void unlock(const K &key) {
362  mapImpl->unlock(key);
363  }
364 
373  void forceUnlock(const K &key) {
374  mapImpl->forceUnlock(key);
375  }
376 
388  template<typename MapInterceptor>
389  std::string addInterceptor(MapInterceptor &interceptor) {
390  return mapImpl->template addInterceptor<MapInterceptor>(interceptor);
391  }
392 
399  void removeInterceptor(const std::string &id) {
400  mapImpl->removeInterceptor(id);
401  }
402 
417  std::string addEntryListener(EntryListener<K, V> &listener, bool includeValue) {
418  return mapImpl->addEntryListener(listener, includeValue);
419  }
420 
436  std::string
437  addEntryListener(EntryListener<K, V> &listener, const query::Predicate &predicate, bool includeValue) {
438  return mapImpl->addEntryListener(listener, predicate, includeValue);
439  }
440 
450  bool removeEntryListener(const std::string &registrationId) {
451  return mapImpl->removeEntryListener(registrationId);
452  }
453 
454 
468  std::string addEntryListener(EntryListener<K, V> &listener, const K &key, bool includeValue) {
469  return mapImpl->addEntryListener(listener, key, includeValue);
470  }
471 
481  return mapImpl->getEntryView(key);
482  }
483 
494  bool evict(const K &key) {
495  return mapImpl->evict(key);
496  }
497 
509  void evictAll() {
510  mapImpl->evictAll();
511  }
512 
519  std::map<K, V> getAll(const std::set<K> &keys) {
520  return mapImpl->getAll(keys);
521  }
522 
530  std::vector<K> keySet() {
531  return mapImpl->keySet();
532  }
533 
546  std::vector<K> keySet(const serialization::IdentifiedDataSerializable &predicate) {
547  return mapImpl->keySet(predicate);
548  }
549 
561  std::vector<K> keySet(const query::Predicate &predicate) {
562  return mapImpl->keySet(predicate);
563  }
564 
576  std::vector<K> keySet(query::PagingPredicate<K, V> &predicate) {
577  return mapImpl->keySet(predicate);
578  }
579 
587  std::vector<V> values() {
588  return mapImpl->values();
589  }
590 
601  std::vector<V> values(const serialization::IdentifiedDataSerializable &predicate) {
602  return mapImpl->values(predicate);
603  }
604 
613  std::vector<V> values(const query::Predicate &predicate) {
614  return mapImpl->values(predicate);
615  }
616 
626  std::vector<V> values(query::PagingPredicate<K, V> &predicate) {
627  return mapImpl->values(predicate);
628  }
629 
637  std::vector<std::pair<K, V> > entrySet() {
638  return mapImpl->entrySet();
639  }
640 
653  std::vector<std::pair<K, V> > entrySet(const serialization::IdentifiedDataSerializable &predicate) {
654  return mapImpl->entrySet(predicate);
655  }
656 
667  std::vector<std::pair<K, V> > entrySet(const query::Predicate &predicate) {
668  return mapImpl->entrySet(predicate);
669  }
670 
681  std::vector<std::pair<K, V> > entrySet(query::PagingPredicate<K, V> &predicate) {
682  return mapImpl->entrySet(predicate);
683  }
684 
717  void addIndex(const std::string &attribute, bool ordered) {
718  mapImpl->addIndex(attribute, ordered);
719  }
720 
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);
738  }
739 
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);
756  }
757 
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);
779  }
780 
795  template<typename ResultType, typename EntryProcessor>
796  std::map<K, boost::shared_ptr<ResultType> >
797  executeOnEntries(EntryProcessor &entryProcessor, const query::Predicate &predicate) {
798  return mapImpl->template executeOnEntries<ResultType, EntryProcessor>(entryProcessor, predicate);
799  }
800 
808  void set(const K &key, const V &value) {
809  mapImpl->set(key, value);
810  }
811 
821  void set(const K &key, const V &value, long ttl) {
822  mapImpl->set(key, value, ttl);
823  }
824 
832  int size() {
833  return mapImpl->size();
834  }
835 
841  bool isEmpty() {
842  return mapImpl->isEmpty();
843  }
844 
845 
856  void putAll(const std::map<K, V> &entries) {
857  return mapImpl->putAll(entries);
858  }
859 
864  void clear() {
865  mapImpl->clear();
866  }
867 
872  void destroy() {
873  mapImpl->destroy();
874  }
875 
889  return mapImpl->getLocalMapStats();
890  }
891  private:
892  IMap(boost::shared_ptr<spi::ClientProxy> clientProxy) {
893  mapImpl = boost::static_pointer_cast<map::ClientMapProxy<K, V> >(clientProxy);
894  }
895 
896  boost::shared_ptr<map::ClientMapProxy<K, V> > mapImpl;
897  };
898 
899  template <typename K, typename V>
900  const std::string IMap<K, V>::SERVICE_NAME = "hz:impl:mapService";
901  }
902 }
903 
904 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
905 #pragma warning(pop)
906 #endif
907 
908 #endif /* HAZELCAST_IMAP */
909 
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 &registrationId)
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