Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
MultiMap.h
1 /*
2  * Copyright (c) 2008-2015, 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_MULTI_MAP
17 #define HAZELCAST_MULTI_MAP
18 
19 #include "hazelcast/client/proxy/MultiMapImpl.h"
20 #include "hazelcast/client/impl/EntryEventHandler.h"
21 #include "hazelcast/client/protocol/codec/MultiMapAddEntryListenerCodec.h"
22 #include <string>
23 #include <map>
24 #include <set>
25 #include <vector>
26 #include <stdexcept>
27 
28 namespace hazelcast {
29  namespace client {
30 
36  template<typename K, typename V>
37  class MultiMap : public proxy::MultiMapImpl {
38  friend class HazelcastClient;
39 
40  public:
50  bool put(const K &key, const V &value) {
51  return proxy::MultiMapImpl::put(toData(key), toData(value));
52  }
53 
60  std::vector<V> get(const K &key) {
61  return toObjectCollection<V>(proxy::MultiMapImpl::get(toData(key)));
62  }
63 
71  bool remove(const K &key, const V &value) {
72  return proxy::MultiMapImpl::remove(toData(key), toData(value));
73  }
74 
82  std::vector<V> remove(const K &key) {
83  return toObjectCollection<V>(proxy::MultiMapImpl::remove(toData(key)));
84  }
85 
92  std::vector<K> keySet() {
93  return toObjectCollection<K>(proxy::MultiMapImpl::keySet());
94  }
95 
102  std::vector<V> values() {
103  return toObjectCollection<V>(proxy::MultiMapImpl::values());
104  }
105 
112  std::vector<std::pair<K, V> > entrySet() {
113  return toObjectEntrySet<K, V>(proxy::MultiMapImpl::entrySet());
114  }
115 
122  bool containsKey(const K &key) {
123  return proxy::MultiMapImpl::containsKey(toData(key));
124  }
125 
132  bool containsValue(const V &value) {
133  return proxy::MultiMapImpl::containsValue(toData(value));
134  }
135 
143  bool containsEntry(const K &key, const V &value) {
144  return proxy::MultiMapImpl::containsEntry(toData(key), toData(value));
145  }
146 
152  int size() {
153  return proxy::MultiMapImpl::size();
154  }
155 
159  void clear() {
160  proxy::MultiMapImpl::clear();
161  }
162 
170  int valueCount(const K &key) {
171  return proxy::MultiMapImpl::valueCount(toData(key));
172  }
173 
188  std::string addEntryListener(EntryListener<K, V> &listener, bool includeValue) {
189  spi::ClusterService &clusterService = context->getClusterService();
190  serialization::pimpl::SerializationService &ss = context->getSerializationService();
191  impl::EntryEventHandler<K, V, protocol::codec::MultiMapAddEntryListenerCodec::AbstractEventHandler> *entryEventHandler =
192  new impl::EntryEventHandler<K, V, protocol::codec::MultiMapAddEntryListenerCodec::AbstractEventHandler>(
193  getName(), clusterService, ss, listener, includeValue);
194  return proxy::MultiMapImpl::addEntryListener(entryEventHandler, includeValue);
195  }
196 
213  std::string addEntryListener(EntryListener<K, V> &listener, const K &key, bool includeValue) {
214  impl::EntryEventHandler<K, V, protocol::codec::MultiMapAddEntryListenerCodec::AbstractEventHandler> *entryEventHandler =
215  new impl::EntryEventHandler<K, V, protocol::codec::MultiMapAddEntryListenerCodec::AbstractEventHandler>(
216  getName(), context->getClusterService(), context->getSerializationService(), listener,
217  includeValue);
218  return proxy::MultiMapImpl::addEntryListener(entryEventHandler, toData(key), includeValue);
219  }
220 
229  bool removeEntryListener(const std::string &registrationId) {
230  return proxy::MultiMapImpl::removeEntryListener(registrationId);
231  }
232 
248  void lock(const K &key) {
249  proxy::MultiMapImpl::lock(toData(key));
250  }
251 
268  void lock(const K &key, long leaseTimeInMillis) {
269  proxy::MultiMapImpl::lock(toData(key), leaseTimeInMillis);
270  }
271 
279  bool isLocked(const K &key) {
280  return proxy::MultiMapImpl::isLocked(toData(key));
281  }
282 
292  bool tryLock(const K &key) {
293  return proxy::MultiMapImpl::tryLock(toData(key));
294  }
295 
312  bool tryLock(const K &key, long timeoutInMillis) {
313  return proxy::MultiMapImpl::tryLock(toData(key), timeoutInMillis);
314  }
315 
323  void unlock(const K &key) {
324  proxy::MultiMapImpl::unlock(toData(key));
325  }
326 
333  void forceUnlock(const K &key) {
334  proxy::MultiMapImpl::forceUnlock(toData(key));
335  }
336 
337  private:
338  MultiMap(const std::string &instanceName, spi::ClientContext *context)
339  : proxy::MultiMapImpl(instanceName, context) {
340 
341  }
342  };
343  }
344 }
345 
346 #endif /* HAZELCAST_MULTI_MAP */
347 
std::vector< std::pair< K, V > > entrySet()
Returns the set of key-value pairs in the multimap.
Definition: MultiMap.h:112
Map Entry listener to get notified when a map entry is added, removed, updated or evicted...
Definition: EntryListener.h:45
void lock(const K &key, long leaseTimeInMillis)
Acquires the lock for the specified key for the specified lease time.
Definition: MultiMap.h:268
void lock(const K &key)
Acquires the lock for the specified key.
Definition: MultiMap.h:248
bool tryLock(const K &key, long timeoutInMillis)
Tries to acquire the lock for the specified key.
Definition: MultiMap.h:312
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: MultiMap.h:279
int size()
Returns the number of key-value pairs in the multimap.
Definition: MultiMap.h:152
std::string addEntryListener(EntryListener< K, V > &listener, bool includeValue)
Adds an entry listener for this multimap.
Definition: MultiMap.h:188
std::vector< K > keySet()
Returns the set of keys in the multimap.
Definition: MultiMap.h:92
int valueCount(const K &key)
Returns number of values matching to given key in the multimap.
Definition: MultiMap.h:170
A specialized distributed map client whose keys can be associated with multiple values.
Definition: MultiMap.h:37
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: MultiMap.h:292
bool containsValue(const V &value)
Returns whether the multimap contains an entry with the value.
Definition: MultiMap.h:132
void clear()
Clears the multimap.
Definition: MultiMap.h:159
std::string addEntryListener(EntryListener< K, V > &listener, const K &key, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: MultiMap.h:213
bool put(const K &key, const V &value)
Stores a key-value pair in the multimap.
Definition: MultiMap.h:50
bool containsKey(const K &key)
Returns whether the multimap contains an entry with the key.
Definition: MultiMap.h:122
std::vector< V > values()
Returns the multimap of values in the multimap.
Definition: MultiMap.h:102
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: MultiMap.h:333
void unlock(const K &key)
Releases the lock for the specified key.
Definition: MultiMap.h:323
bool removeEntryListener(const std::string &registrationId)
Removes the specified entry listener Returns silently if there is no such listener added before...
Definition: MultiMap.h:229
bool containsEntry(const K &key, const V &value)
Returns whether the multimap contains the given key-value pair.
Definition: MultiMap.h:143
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:412