Hazelcast C++ Client
Hazelcast C++ Client Library
multi_map.h
1 /*
2  * Copyright (c) 2008-2021, 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 {
30  class HAZELCAST_API multi_map : public proxy::MultiMapImpl {
31  friend class spi::ProxyManager;
32  public:
33  static constexpr const char *SERVICE_NAME = "hz:impl:multiMapService";
34 
44  template<typename K, typename V>
45  boost::future<bool> put(const K &key, const V &value) {
46  return proxy::MultiMapImpl::put(to_data(key), to_data(value));
47  }
48 
55  template<typename K, typename V>
56  boost::future<std::vector<V>> get(const K &key) {
57  return to_object_vector<V>(proxy::MultiMapImpl::get_data(to_data(key)));
58  }
59 
67  template<typename K, typename V>
68  boost::future<bool> remove(const K &key, const V &value) {
69  return proxy::MultiMapImpl::remove(to_data(key), to_data(value));
70  }
71 
79  template<typename K, typename V>
80  boost::future<std::vector<V>> remove(const K &key) {
81  return to_object_vector<V>(proxy::MultiMapImpl::remove_data(to_data(key)));
82  }
83 
90  template<typename K>
91  boost::future<std::vector<K>> key_set() {
92  return to_object_vector<K>(proxy::MultiMapImpl::key_set_data());
93  }
94 
101  template<typename V>
102  boost::future<std::vector<V>> values() {
103  return to_object_vector<V>(proxy::MultiMapImpl::values_data());
104  }
105 
112  template<typename K, typename V>
113  boost::future<std::vector<std::pair<K, V>>> entry_set() {
114  return to_entry_object_vector<K, V>(proxy::MultiMapImpl::entry_set_data());
115  }
116 
123  template<typename K>
124  boost::future<bool> contains_key(const K &key) {
125  return proxy::MultiMapImpl::contains_key(to_data(key));
126  }
127 
134  template<typename V>
135  boost::future<bool> contains_value(const V &value) {
136  return proxy::MultiMapImpl::contains_value(to_data(value));
137  }
138 
146  template<typename K, typename V>
147  boost::future<bool> contains_entry(const K &key, const V &value) {
148  return proxy::MultiMapImpl::contains_entry(to_data(key), to_data(value));
149  }
150 
158  template<typename K>
159  boost::future<int> value_count(const K &key) {
160  return proxy::MultiMapImpl::value_count(to_data(key));
161  }
162 
177  boost::future<boost::uuids::uuid> add_entry_listener(entry_listener &&listener, bool include_value) {
178  return proxy::MultiMapImpl::add_entry_listener(
179  std::unique_ptr<impl::BaseEventHandler>(
180  new impl::EntryEventHandler<protocol::codec::multimap_addentrylistener_handler>(
181  get_name(), get_context().get_client_cluster_service(),
182  get_context().get_serialization_service(), std::move(listener), include_value, get_context().get_logger())), include_value);
183  }
184 
201  template<typename K>
202  boost::future<boost::uuids::uuid> add_entry_listener(entry_listener &&listener, const K &key, bool include_value) {
203  return proxy::MultiMapImpl::add_entry_listener(
204  std::shared_ptr<impl::BaseEventHandler>(
205  new impl::EntryEventHandler<protocol::codec::multimap_addentrylistenertokey_handler>(
206  get_name(), get_context().get_client_cluster_service(),
207  get_context().get_serialization_service(), std::move(listener), include_value, get_context().get_logger())), include_value,
208  to_data(key));
209  }
210 
226  template<typename K>
227  boost::future<void> lock(const K &key) {
228  return proxy::MultiMapImpl::lock(to_data(key));
229  }
230 
247  template<typename K>
248  boost::future<void> lock(const K &key, std::chrono::milliseconds lease_time) {
249  return proxy::MultiMapImpl::lock(to_data(key), lease_time);
250  }
251 
259  template<typename K>
260  boost::future<bool> is_locked(const K &key) {
261  return proxy::MultiMapImpl::is_locked(to_data(key));
262  }
263 
273  template<typename K>
274  boost::future<bool> try_lock(const K &key) {
275  return proxy::MultiMapImpl::try_lock(to_data(key));
276  }
277 
294  template<typename K>
295  boost::future<bool> try_lock(const K &key, std::chrono::milliseconds timeout) {
296  return proxy::MultiMapImpl::try_lock(to_data(key), timeout);
297  }
298 
317  template <typename K>
318  boost::future<bool> try_lock(const K &key, std::chrono::milliseconds timeout, std::chrono::milliseconds lease_time) {
319  return proxy::MultiMapImpl::try_lock(to_data(key), timeout, lease_time);
320  }
321 
329  template<typename K>
330  boost::future<void> unlock(const K &key) {
331  return proxy::MultiMapImpl::unlock(to_data(key));
332  }
333 
340  template<typename K>
341  boost::future<void> force_unlock(const K &key) {
342  return proxy::MultiMapImpl::force_unlock(to_data(key));
343  }
344  private:
345  multi_map(const std::string &instance_name, spi::ClientContext *context)
346  : proxy::MultiMapImpl(instance_name, context) {}
347  };
348  }
349 }
350 
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:30
boost::future< bool > try_lock(const K &key)
Tries to acquire the lock for the specified key.
Definition: multi_map.h:274
boost::future< bool > remove(const K &key, const V &value)
Removes the given key value pair from the multimap.
Definition: multi_map.h:68
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:147
boost::future< bool > contains_key(const K &key)
Returns whether the multimap contains an entry with the key.
Definition: multi_map.h:124
boost::future< std::vector< std::pair< K, V > > > entry_set()
Returns the set of key-value pairs in the multimap.
Definition: multi_map.h:113
boost::future< std::vector< V > > values()
Returns the multimap of values in the multimap.
Definition: multi_map.h:102
boost::future< bool > is_locked(const K &key)
Checks the lock for the specified key.
Definition: multi_map.h:260
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:177
boost::future< void > force_unlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: multi_map.h:341
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:295
boost::future< void > unlock(const K &key)
Releases the lock for the specified key.
Definition: multi_map.h:330
boost::future< std::vector< K > > key_set()
Returns the set of keys in the multimap.
Definition: multi_map.h:91
boost::future< std::vector< V > > remove(const K &key)
Removes all the entries with the given key.
Definition: multi_map.h:80
boost::future< bool > contains_value(const V &value)
Returns whether the multimap contains an entry with the value.
Definition: multi_map.h:135
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:248
boost::future< bool > put(const K &key, const V &value)
Stores a key-value pair in the multimap.
Definition: multi_map.h:45
boost::future< void > lock(const K &key)
Acquires the lock for the specified key.
Definition: multi_map.h:227
boost::future< int > value_count(const K &key)
Returns number of values matching to given key in the multimap.
Definition: multi_map.h:159
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:202
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:318
boost::future< std::vector< V > > get(const K &key)
Returns the multimap of values associated with the key.
Definition: multi_map.h:56