Hazelcast C++ Client
MultiMap.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_MULTIMAP_H_
17 #define HAZELCAST_CLIENT_MIXEDTYPE_MULTIMAP_H_
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  namespace mixedtype {
36  class HAZELCAST_API MultiMap : public proxy::MultiMapImpl {
37  friend class client::HazelcastClient;
38 
39  public:
49  template <typename K, typename V>
50  bool put(const K &key, const V &value) {
51  return proxy::MultiMapImpl::put(toData(key), toData(value));
52  }
53 
60  template <typename K>
61  std::vector<TypedData> get(const K &key) {
62  return toTypedDataCollection(proxy::MultiMapImpl::getData(toData(key)));
63  }
64 
72  template <typename K, typename V>
73  bool remove(const K &key, const V &value) {
74  return proxy::MultiMapImpl::remove(toData(key), toData(value));
75  }
76 
84  template <typename K>
85  std::vector<TypedData> remove(const K &key) {
86  return toTypedDataCollection(proxy::MultiMapImpl::removeData(toData(key)));
87  }
88 
95  std::vector<TypedData> keySet();
96 
103  std::vector<TypedData> values();
104 
111  std::vector<std::pair<TypedData, TypedData> > entrySet();
112 
119  template <typename K>
120  bool containsKey(const K &key) {
121  return proxy::MultiMapImpl::containsKey(toData(key));
122  }
123 
130  template <typename V>
131  bool containsValue(const V &value) {
132  return proxy::MultiMapImpl::containsValue(toData(value));
133  }
134 
142  template <typename K, typename V>
143  bool containsEntry(const K &key, const V &value) {
144  return proxy::MultiMapImpl::containsEntry(toData(key), toData(value));
145  }
146 
152  int size();
153 
157  void clear();
158 
166  template <typename K>
167  int valueCount(const K &key) {
168  return proxy::MultiMapImpl::valueCount(toData(key));
169  }
170 
185  std::string addEntryListener(MixedEntryListener &listener, bool includeValue);
186 
203  template <typename K>
204  std::string addEntryListener(MixedEntryListener &listener, const K &key, bool includeValue) {
205  impl::MixedEntryEventHandler<protocol::codec::MultiMapAddEntryListenerCodec::AbstractEventHandler> *entryEventHandler =
206  new impl::MixedEntryEventHandler<protocol::codec::MultiMapAddEntryListenerCodec::AbstractEventHandler>(
207  getName(), context->getClusterService(), context->getSerializationService(), listener,
208  includeValue);
209  return proxy::MultiMapImpl::addEntryListener(entryEventHandler, toData(key), includeValue);
210  }
211 
220  bool removeEntryListener(const std::string &registrationId);
236  template <typename K>
237  void lock(const K &key) {
238  proxy::MultiMapImpl::lock(toData(key));
239  }
240 
257  template <typename K>
258  void lock(const K &key, long leaseTimeInMillis) {
259  proxy::MultiMapImpl::lock(toData(key), leaseTimeInMillis);
260  }
261 
269  template <typename K>
270  bool isLocked(const K &key) {
271  return proxy::MultiMapImpl::isLocked(toData(key));
272  }
273 
283  template <typename K>
284  bool tryLock(const K &key) {
285  return proxy::MultiMapImpl::tryLock(toData(key));
286  }
287 
304  template <typename K>
305  bool tryLock(const K &key, long timeoutInMillis) {
306  return proxy::MultiMapImpl::tryLock(toData(key), timeoutInMillis);
307  }
308 
316  template <typename K>
317  void unlock(const K &key) {
318  proxy::MultiMapImpl::unlock(toData(key));
319  }
320 
327  template <typename K>
328  void forceUnlock(const K &key) {
329  proxy::MultiMapImpl::forceUnlock(toData(key));
330  }
331 
332  private:
333  MultiMap(const std::string &instanceName, spi::ClientContext *context);
334  };
335  }
336  }
337 }
338 
339 #endif /* HAZELCAST_CLIENT_MIXEDTYPE_MULTIMAP_H_ */
340 
void lock(const K &key, long leaseTimeInMillis)
Acquires the lock for the specified key for the specified lease time.
Definition: MultiMap.h:258
bool containsEntry(const K &key, const V &value)
Returns whether the multimap contains the given key-value pair.
Definition: MultiMap.h:143
void unlock(const K &key)
Releases the lock for the specified key.
Definition: MultiMap.h:317
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: MultiMap.h:270
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: MultiMap.h:328
bool containsKey(const K &key)
Returns whether the multimap contains an entry with the key.
Definition: MultiMap.h:120
Definition: EntryListener.h:108
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: MultiMap.h:284
int valueCount(const K &key)
Returns number of values matching to given key in the multimap.
Definition: MultiMap.h:167
bool tryLock(const K &key, long timeoutInMillis)
Tries to acquire the lock for the specified key.
Definition: MultiMap.h:305
bool put(const K &key, const V &value)
Stores a key-value pair in the multimap.
Definition: MultiMap.h:50
std::string addEntryListener(MixedEntryListener &listener, const K &key, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: MultiMap.h:204
A specialized distributed map client whose keys can be associated with multiple values.
Definition: MultiMap.h:36
void lock(const K &key)
Acquires the lock for the specified key.
Definition: MultiMap.h:237
Definition: MapEntryView.h:32
bool containsValue(const V &value)
Returns whether the multimap contains an entry with the value.
Definition: MultiMap.h:131
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:459