Hazelcast C++ Client
Hazelcast C++ Client Library
multi_map.h
1 /*
2  * Copyright (c) 2008-2022, 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 #pragma once
17 
18 #include "hazelcast/client/proxy/MultiMapImpl.h"
19 #include "hazelcast/client/impl/EntryEventHandler.h"
20 #include "hazelcast/client/protocol/codec/codecs.h"
21 #include "hazelcast/client/spi/ClientContext.h"
22 
23 namespace hazelcast {
24 namespace client {
31 class HAZELCAST_API multi_map : public proxy::MultiMapImpl
32 {
33  friend class spi::ProxyManager;
34 
35 public:
36  static constexpr const char* SERVICE_NAME = "hz:impl:multiMapService";
37 
47  template<typename K, typename V>
48  boost::future<bool> put(const K& key, const V& value)
49  {
50  return proxy::MultiMapImpl::put(to_data(key), to_data(value));
51  }
52 
59  template<typename K, typename V>
60  boost::future<std::vector<V>> get(const K& key)
61  {
62  return to_object_vector<V>(proxy::MultiMapImpl::get_data(to_data(key)));
63  }
64 
73  template<typename K, typename V>
74  boost::future<bool> remove(const K& key, const V& value)
75  {
76  return proxy::MultiMapImpl::remove(to_data(key), to_data(value));
77  }
78 
87  template<typename K, typename V>
88  boost::future<std::vector<V>> remove(const K& key)
89  {
90  return to_object_vector<V>(
91  proxy::MultiMapImpl::remove_data(to_data(key)));
92  }
93 
100  template<typename K>
101  boost::future<std::vector<K>> key_set()
102  {
103  return to_object_vector<K>(proxy::MultiMapImpl::key_set_data());
104  }
105 
112  template<typename V>
113  boost::future<std::vector<V>> values()
114  {
115  return to_object_vector<V>(proxy::MultiMapImpl::values_data());
116  }
117 
124  template<typename K, typename V>
125  boost::future<std::vector<std::pair<K, V>>> entry_set()
126  {
127  return to_entry_object_vector<K, V>(
128  proxy::MultiMapImpl::entry_set_data());
129  }
130 
138  template<typename K>
139  boost::future<bool> contains_key(const K& key)
140  {
141  return proxy::MultiMapImpl::contains_key(to_data(key));
142  }
143 
151  template<typename V>
152  boost::future<bool> contains_value(const V& value)
153  {
154  return proxy::MultiMapImpl::contains_value(to_data(value));
155  }
156 
165  template<typename K, typename V>
166  boost::future<bool> contains_entry(const K& key, const V& value)
167  {
168  return proxy::MultiMapImpl::contains_entry(to_data(key),
169  to_data(value));
170  }
171 
179  template<typename K>
180  boost::future<int> value_count(const K& key)
181  {
182  return proxy::MultiMapImpl::value_count(to_data(key));
183  }
184 
199  boost::future<boost::uuids::uuid> add_entry_listener(
200  entry_listener&& listener,
201  bool include_value)
202  {
203  return proxy::MultiMapImpl::add_entry_listener(
204  std::unique_ptr<impl::BaseEventHandler>(
205  new impl::EntryEventHandler<
206  protocol::codec::multimap_addentrylistener_handler>(
207  get_name(),
208  get_context().get_client_cluster_service(),
209  get_context().get_serialization_service(),
210  std::move(listener),
211  include_value,
212  get_context().get_logger())),
213  include_value);
214  }
215 
232  template<typename K>
233  boost::future<boost::uuids::uuid> add_entry_listener(
234  entry_listener&& listener,
235  const K& key,
236  bool include_value)
237  {
238  return proxy::MultiMapImpl::add_entry_listener(
239  std::shared_ptr<impl::BaseEventHandler>(
240  new impl::EntryEventHandler<
241  protocol::codec::multimap_addentrylistenertokey_handler>(
242  get_name(),
243  get_context().get_client_cluster_service(),
244  get_context().get_serialization_service(),
245  std::move(listener),
246  include_value,
247  get_context().get_logger())),
248  include_value,
249  to_data(key));
250  }
251 
267  template<typename K>
268  boost::future<void> lock(const K& key)
269  {
270  return proxy::MultiMapImpl::lock(to_data(key));
271  }
272 
289  template<typename K>
290  boost::future<void> lock(const K& key, std::chrono::milliseconds lease_time)
291  {
292  return proxy::MultiMapImpl::lock(to_data(key), lease_time);
293  }
294 
302  template<typename K>
303  boost::future<bool> is_locked(const K& key)
304  {
305  return proxy::MultiMapImpl::is_locked(to_data(key));
306  }
307 
317  template<typename K>
318  boost::future<bool> try_lock(const K& key)
319  {
320  return proxy::MultiMapImpl::try_lock(to_data(key));
321  }
322 
339  template<typename K>
340  boost::future<bool> try_lock(const K& key,
341  std::chrono::milliseconds timeout)
342  {
343  return proxy::MultiMapImpl::try_lock(to_data(key), timeout);
344  }
345 
363  template<typename K>
364  boost::future<bool> try_lock(const K& key,
365  std::chrono::milliseconds timeout,
366  std::chrono::milliseconds lease_time)
367  {
368  return proxy::MultiMapImpl::try_lock(to_data(key), timeout, lease_time);
369  }
370 
378  template<typename K>
379  boost::future<void> unlock(const K& key)
380  {
381  return proxy::MultiMapImpl::unlock(to_data(key));
382  }
383 
390  template<typename K>
391  boost::future<void> force_unlock(const K& key)
392  {
393  return proxy::MultiMapImpl::force_unlock(to_data(key));
394  }
395 
396 private:
397  multi_map(const std::string& instance_name, spi::ClientContext* context)
398  : proxy::MultiMapImpl(instance_name, context)
399  {}
400 };
401 } // namespace client
402 } // namespace hazelcast
Map entry listener to get notified when a map entry is added, removed, updated, evicted,...
A specialized distributed map client whose keys can be associated with multiple values.
Definition: multi_map.h:32
boost::future< bool > try_lock(const K &key)
Tries to acquire the lock for the specified key.
Definition: multi_map.h:318
boost::future< bool > remove(const K &key, const V &value)
Removes the given key value pair from the multimap.
Definition: multi_map.h:74
boost::future< bool > contains_entry(const K &key, const V &value)
Returns whether the multimap contains the given key-value pair.
Definition: multi_map.h:166
boost::future< bool > contains_key(const K &key)
Returns whether the multimap contains an entry with the key.
Definition: multi_map.h:139
boost::future< std::vector< std::pair< K, V > > > entry_set()
Returns the set of key-value pairs in the multimap.
Definition: multi_map.h:125
boost::future< std::vector< V > > values()
Returns the multimap of values in the multimap.
Definition: multi_map.h:113
boost::future< bool > is_locked(const K &key)
Checks the lock for the specified key.
Definition: multi_map.h:303
boost::future< boost::uuids::uuid > add_entry_listener(entry_listener &&listener, bool include_value)
Adds an entry listener for this multimap.
Definition: multi_map.h:199
boost::future< void > force_unlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: multi_map.h:391
boost::future< bool > try_lock(const K &key, std::chrono::milliseconds timeout)
Tries to acquire the lock for the specified key.
Definition: multi_map.h:340
boost::future< void > unlock(const K &key)
Releases the lock for the specified key.
Definition: multi_map.h:379
boost::future< std::vector< K > > key_set()
Returns the set of keys in the multimap.
Definition: multi_map.h:101
boost::future< std::vector< V > > remove(const K &key)
Removes all the entries with the given key.
Definition: multi_map.h:88
boost::future< bool > contains_value(const V &value)
Returns whether the multimap contains an entry with the value.
Definition: multi_map.h:152
boost::future< void > lock(const K &key, std::chrono::milliseconds lease_time)
Acquires the lock for the specified key for the specified lease time.
Definition: multi_map.h:290
boost::future< bool > put(const K &key, const V &value)
Stores a key-value pair in the multimap.
Definition: multi_map.h:48
boost::future< void > lock(const K &key)
Acquires the lock for the specified key.
Definition: multi_map.h:268
boost::future< int > value_count(const K &key)
Returns number of values matching to given key in the multimap.
Definition: multi_map.h:180
boost::future< boost::uuids::uuid > add_entry_listener(entry_listener &&listener, const K &key, bool include_value)
Adds the specified entry listener for the specified key.
Definition: multi_map.h:233
boost::future< bool > try_lock(const K &key, std::chrono::milliseconds timeout, std::chrono::milliseconds lease_time)
Tries to acquire the lock for the specified key for the specified lease time.
Definition: multi_map.h:364
boost::future< std::vector< V > > get(const K &key)
Returns the multimap of values associated with the key.
Definition: multi_map.h:60