Hazelcast C++ Client
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_CLIENT_MIXEDTYPE_IMAP_H_
17 #define HAZELCAST_CLIENT_MIXEDTYPE_IMAP_H_
18 
19 #include <string>
20 #include <map>
21 #include <vector>
22 #include "hazelcast/client/mixedtype/ClientMapProxy.h"
23 
24 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25 #pragma warning(push)
26 #pragma warning(disable: 4251) //for dll export
27 #endif
28 
29 namespace hazelcast {
30  namespace client {
31  namespace mixedtype {
32  namespace impl {
33  class HazelcastClientImpl;
34  }
35 
47  class HAZELCAST_API IMap {
48  friend class impl::HazelcastClientImpl;
49  public:
56  template <typename K>
57  bool containsKey(const K &key) {
58  return mapImpl->containsKey<K>(key);
59  }
60 
67  template <typename V>
68  bool containsValue(const V &value) {
69  return mapImpl->containsValue(value);
70  }
71 
79  template <typename K>
80  TypedData get(const K &key) {
81  return mapImpl->get<K>(key);
82  }
83 
92  template <typename K, typename V>
93  TypedData put(const K &key, const V &value) {
94  return mapImpl->put(key, value);
95  }
96 
108  template <typename K, typename V>
109  TypedData put(const K &key, const V &value, long ttlInMillis) {
110  return mapImpl->put<K, V>(key, value, ttlInMillis);
111  }
112 
120  template <typename K>
121  TypedData remove(const K &key) {
122  return mapImpl->remove<K>(key);
123  }
124 
132  template <typename K, typename V>
133  bool remove(const K &key, const V &value) {
134  return mapImpl->remove<K, V>(key, value);
135  }
136 
143  void removeAll(const query::Predicate &predicate);
144 
151  template <typename K>
152  void deleteEntry(const K &key) {
153  return mapImpl->deleteEntry<K>(key);
154  }
155 
160  void flush();
161 
172  template <typename K>
173  bool tryRemove(const K &key, long timeoutInMillis) {
174  return mapImpl->tryRemove<K>(key, timeoutInMillis);
175  }
176 
189  template <typename K, typename V>
190  bool tryPut(const K &key, const V &value, long timeoutInMillis) {
191  return mapImpl->tryPut<K, V>(key, value, timeoutInMillis);
192  }
193 
203  template <typename K, typename V>
204  void putTransient(const K &key, const V &value, long ttlInMillis) {
205  return mapImpl->putTransient<K, V>(key, value, ttlInMillis);
206  }
207 
216  template <typename K, typename V>
217  TypedData putIfAbsent(const K &key, const V &value) {
218  return mapImpl->putIfAbsent<K, V>(key, value);
219  }
220 
232  template <typename K, typename V>
233  TypedData putIfAbsent(const K &key, const V &value, long ttlInMillis) {
234  return mapImpl->putIfAbsent<K, V>(key, value, ttlInMillis);
235  }
236 
244  template <typename K, typename V, typename NEWTYPE>
245  bool replace(const K &key, const V &oldValue, const NEWTYPE &newValue) {
246  return mapImpl->replace<K, V, NEWTYPE>(key, oldValue, newValue);
247  }
248 
256  template <typename K, typename V>
257  TypedData replace(const K &key, const V &value) {
258  return mapImpl->replace<K, V>(key, value);
259  }
260 
268  template <typename K, typename V>
269  void set(const K &key, const V &value) {
270  return mapImpl->set<K, V>(key, value);
271  }
272 
282  template <typename K, typename V>
283  void set(const K &key, const V &value, long ttl) {
284  return mapImpl->set<K, V>(key, value, ttl);
285  }
286 
301  template <typename K>
302  void lock(const K &key) {
303  return mapImpl->lock<K>(key);
304  }
305 
324  template <typename K>
325  void lock(const K &key, long leaseTime) {
326  return mapImpl->lock<K>(key, leaseTime);
327  }
328 
337  template <typename K>
338  bool isLocked(const K &key) {
339  return mapImpl->isLocked<K>(key);
340  }
341 
351  template <typename K>
352  bool tryLock(const K &key) {
353  return mapImpl->tryLock<K>(key);
354  }
355 
372  template <typename K>
373  bool tryLock(const K &key, long timeInMillis) {
374  return mapImpl->tryLock<K>(key, timeInMillis);
375  }
376 
390  template <typename K>
391  void unlock(const K &key) {
392  mapImpl->unlock<K>(key);
393  }
394 
403  template <typename K>
404  void forceUnlock(const K &key) {
405  mapImpl->forceUnlock<K>(key);
406  }
407 
419  template<typename MapInterceptor>
420  std::string addInterceptor(MapInterceptor &interceptor) {
421  return mapImpl->addInterceptor<MapInterceptor>(interceptor);
422  }
423 
430  void removeInterceptor(const std::string &id);
431 
446  std::string addEntryListener(MixedEntryListener &listener, bool includeValue);
447 
463  std::string
464  addEntryListener(MixedEntryListener &listener, const query::Predicate &predicate, bool includeValue);
465 
475  bool removeEntryListener(const std::string &registrationId);
476 
490  template <typename K>
491  std::string addEntryListener(const K &key, MixedEntryListener &listener, bool includeValue) {
492  return mapImpl->addEntryListener<K>(key, listener, includeValue);
493  }
494 
503  template <typename K>
504  std::auto_ptr<EntryView<TypedData, TypedData> > getEntryView(const K &key) {
505  return mapImpl->getEntryView<K>(key);
506  }
507 
518  template <typename K>
519  bool evict(const K &key) {
520  return mapImpl->evict<K>(key);
521  }
522 
534  void evictAll();
535 
542  template <typename K>
543  std::vector<std::pair<TypedData, TypedData> > getAll(const std::set<K> &keys) {
544  return mapImpl->getAll<K>(keys);
545  }
546 
554  std::vector<TypedData> keySet();
555 
568  std::vector<TypedData> keySet(const serialization::IdentifiedDataSerializable &predicate);
569 
581  std::vector<TypedData> keySet(const query::Predicate &predicate);
582 
594  template <typename K, typename V>
595  std::vector<K> keySet(query::PagingPredicate <K, V> &predicate) {
596  return mapImpl->keySet<K, V>(predicate);
597  }
598 
606  std::vector<TypedData> values();
607 
618  std::vector<TypedData> values(const serialization::IdentifiedDataSerializable &predicate);
619 
628  std::vector<TypedData> values(const query::Predicate &predicate);
629 
639  template <typename K, typename V>
640  std::vector<V> values(query::PagingPredicate <K, V> &predicate) {
641  return mapImpl->values<K, V>(predicate);
642  }
643 
651  std::vector<std::pair<TypedData, TypedData> > entrySet();
652 
665  std::vector<std::pair<TypedData, TypedData> > entrySet(const serialization::IdentifiedDataSerializable &predicate);
666 
677  std::vector<std::pair<TypedData, TypedData> > entrySet(const query::Predicate &predicate);
678 
689  template <typename K, typename V>
690  std::vector<std::pair<K, V> > entrySet(query::PagingPredicate <K, V> &predicate) {
691  return mapImpl->entrySet<K, V>(predicate);
692  }
693 
726  void addIndex(const std::string &attribute, bool ordered);
727 
742  template<typename K, typename EntryProcessor>
743  TypedData executeOnKey(const K &key, const EntryProcessor &entryProcessor) {
744  return mapImpl->executeOnKey<K, EntryProcessor>(key, entryProcessor);
745  }
746 
747  template<typename K, typename EntryProcessor>
748  Future<TypedData> submitToKey(const K &key, const EntryProcessor &entryProcessor) {
749  return mapImpl->submitToKey<K, EntryProcessor>(key, entryProcessor);
750  }
751 
752  template<typename K, typename EntryProcessor>
753  std::map<K, TypedData> executeOnKeys(const std::set<K> &keys, const EntryProcessor &entryProcessor) {
754  return mapImpl->executeOnKeys<K>(keys, entryProcessor);
755  }
756 
769  template<typename EntryProcessor>
770  std::map<TypedData, TypedData > executeOnEntries(const EntryProcessor &entryProcessor) {
771  return mapImpl->executeOnEntries<EntryProcessor>(entryProcessor);
772  }
773 
788  template<typename EntryProcessor>
789  std::map<TypedData, TypedData>
790  executeOnEntries(const EntryProcessor &entryProcessor, const query::Predicate &predicate) {
791  return mapImpl->executeOnEntries<EntryProcessor>(entryProcessor, predicate);
792  }
793 
801  int size();
802 
808  bool isEmpty();
809 
810 
821  template<typename K, typename V>
822  void putAll(const std::map<K, V> &entries) {
823  return mapImpl->putAll<K, V>(entries);
824  }
825 
830  void clear();
831 
836  void destroy();
837 
838  monitor::LocalMapStats &getLocalMapStats();
839 
840  private:
841  IMap(boost::shared_ptr<mixedtype::ClientMapProxy> proxy);
842 
843  boost::shared_ptr<mixedtype::ClientMapProxy> mapImpl;
844  };
845  }
846  }
847 }
848 
849 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
850 #pragma warning(pop)
851 #endif
852 
853 #endif /* HAZELCAST_CLIENT_MIXEDTYPE_IMAP_H_ */
854 
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: IMap.h:338
bool evict(const K &key)
Evicts the specified key from this map.
Definition: IMap.h:519
std::auto_ptr< T > get() const
Deserializes the underlying binary data and produces the object of type T.
Definition: TypedData.h:69
void set(const K &key, const V &value)
Puts an entry into this map.
Definition: IMap.h:269
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:173
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:690
bool tryLock(const K &key, long timeInMillis)
Tries to acquire the lock for the specified key.
Definition: IMap.h:373
TypedData put(const K &key, const V &value)
put new entry into map.
Definition: IMap.h:93
bool replace(const K &key, const V &oldValue, const NEWTYPE &newValue)
Replaces the entry for a key only if currently mapped to a given value.
Definition: IMap.h:245
Definition: LocalMapStats.h:31
Definition: EntryListener.h:108
bool containsValue(const V &value)
check if this map contains value.
Definition: IMap.h:68
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
TypedData 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:233
void set(const K &key, const V &value, long ttl)
Puts an entry into this map.
Definition: IMap.h:283
void unlock(const K &key)
Releases the lock for the specified key.
Definition: IMap.h:391
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:822
std::map< TypedData, TypedData > executeOnEntries(const EntryProcessor &entryProcessor, const query::Predicate &predicate)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: IMap.h:790
bool containsKey(const K &key)
check if this map contains key.
Definition: IMap.h:57
std::map< TypedData, TypedData > executeOnEntries(const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: IMap.h:770
std::vector< std::pair< TypedData, TypedData > > getAll(const std::set< K > &keys)
Returns the entries for the given keys.
Definition: IMap.h:543
This is a merker class for Predicate classes.
Definition: Predicate.h:36
std::string addInterceptor(MapInterceptor &interceptor)
Adds an interceptor for this map.
Definition: IMap.h:420
Concurrent, distributed, observable and queryable map client.
Definition: IMap.h:47
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:204
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: IMap.h:404
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:595
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:190
Definition: MapEntryView.h:32
void deleteEntry(const K &key)
removes entry from map.
Definition: IMap.h:152
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: IMap.h:352
std::auto_ptr< EntryView< TypedData, TypedData > > getEntryView(const K &key)
Returns the EntryView for the specified key.
Definition: IMap.h:504
TypedData 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:109
This specialization overwrites the get method to return TypedData.
Definition: Future.h:236
void lock(const K &key)
Acquires the lock for the specified key.
Definition: IMap.h:302
TypedData class is a wrapper class for the serialized binary data.
Definition: TypedData.h:40
TypedData 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:217
TypedData executeOnKey(const K &key, const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key.
Definition: IMap.h:743
std::string addEntryListener(const K &key, MixedEntryListener &listener, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: IMap.h:491
TypedData replace(const K &key, const V &value)
Replaces the entry for a key only if currently mapped to some value.
Definition: IMap.h:257
void lock(const K &key, long leaseTime)
Acquires the lock for the specified key for the specified lease time.
Definition: IMap.h:325
std::vector< V > values(query::PagingPredicate< K, V > &predicate)
Returns a vector clone of the values contained in this map.
Definition: IMap.h:640