Hazelcast C++ Client
MultiMap.h
1 /*
2  * Copyright (c) 2008-2018, 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::impl::HazelcastClientInstanceImpl;;
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->getClientClusterService(), context->getSerializationService(), listener,
208  includeValue);
209  serialization::pimpl::Data keyData = toData(key);
210  return proxy::MultiMapImpl::addEntryListener(entryEventHandler, keyData, includeValue);
211  }
212 
221  bool removeEntryListener(const std::string &registrationId);
237  template <typename K>
238  void lock(const K &key) {
239  proxy::MultiMapImpl::lock(toData(key));
240  }
241 
258  template <typename K>
259  void lock(const K &key, long leaseTimeInMillis) {
260  proxy::MultiMapImpl::lock(toData(key), leaseTimeInMillis);
261  }
262 
270  template <typename K>
271  bool isLocked(const K &key) {
272  return proxy::MultiMapImpl::isLocked(toData(key));
273  }
274 
284  template <typename K>
285  bool tryLock(const K &key) {
286  return proxy::MultiMapImpl::tryLock(toData(key));
287  }
288 
305  template <typename K>
306  bool tryLock(const K &key, long timeoutInMillis) {
307  return proxy::MultiMapImpl::tryLock(toData(key), timeoutInMillis);
308  }
309 
317  template <typename K>
318  void unlock(const K &key) {
319  proxy::MultiMapImpl::unlock(toData(key));
320  }
321 
328  template <typename K>
329  void forceUnlock(const K &key) {
330  proxy::MultiMapImpl::forceUnlock(toData(key));
331  }
332 
333  private:
334  MultiMap(const std::string &instanceName, spi::ClientContext *context);
335  };
336  }
337  }
338 }
339 
340 #endif /* HAZELCAST_CLIENT_MIXEDTYPE_MULTIMAP_H_ */
341 
void lock(const K &key, long leaseTimeInMillis)
Acquires the lock for the specified key for the specified lease time.
Definition: MultiMap.h:259
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:318
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: MultiMap.h:271
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: MultiMap.h:329
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:285
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:306
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:238
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
bool containsValue(const V &value)
Returns whether the multimap contains an entry with the value.
Definition: MultiMap.h:131