Hazelcast C++ Client
Hazelcast C++ Client Library
hazelcast_client.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 <boost/utility/string_view.hpp>
19 
20 #include "hazelcast/client/impl/hazelcast_client_instance_impl.h"
21 
22 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
23 #pragma warning(push)
24 #pragma warning(disable : 4251) // for dll export
25 #endif
26 
27 namespace hazelcast {
28 namespace client {
29 class hazelcast_client;
30 }
31 
35 boost::future<client::hazelcast_client> HAZELCAST_API
36 new_client();
37 
42 boost::future<client::hazelcast_client> HAZELCAST_API
43 new_client(client::client_config config);
44 
45 namespace client {
46 /*
47  * You can use native C++ Client to connect to hazelcast nodes and make almost
48  * all operations that a node does. Different from nodes, clients do not hold
49  * data.
50  *
51  * Some of features of C++ Clients are:
52  * * Access to distributed data structures like IMap, IQueue, MultiMap, ITopic
53  * etc... For complete list see the classes extending DistributedObject
54  * * Access to transactional distributed data structures like TransactionalMap,
55  * TransactionalQueue etc...
56  * * Ability to add cluster listeners to a cluster and entry/item listeners to
57  * distributed data structures.
58  * @see MembershipListener, IMap#add_entry_listener , IQueue#add_item_listener
59  * etc .
60  * * C++ Client is smart by default, which means that it knows where the data is
61  * and asks directly to correct node. Note that you can turn this feature off (
62  * client_config#setSmart), if you don't want your clients to connect every
63  * node.
64  *
65  * Our C++ client is completely open source and the source code is freely
66  * available at https://github.com/hazelcast/hazelcast-cpp-client . Please feel
67  * free to contribute. You can join our community at
68  * https://groups.google.com/forum/#!forum/hazelcast where you can find answers
69  * to your questions.
70  */
71 class HAZELCAST_API hazelcast_client
72 {
73  friend class spi::ClientContext;
74 
75 public:
76  friend boost::future<hazelcast_client> hazelcast::new_client();
77 
78  friend boost::future<hazelcast_client> hazelcast::new_client(
80 
81  virtual ~hazelcast_client();
82 
88  const std::string& get_name() const;
89 
96  template<typename T>
97  boost::shared_future<std::shared_ptr<T>> get_distributed_object(
98  const std::string& name)
99  {
100  return client_impl_->get_distributed_object<T>(name);
101  }
102 
112  boost::shared_future<std::shared_ptr<imap>> get_map(const std::string& name)
113  {
114  return client_impl_->get_distributed_object<imap>(name);
115  }
116 
123  boost::shared_future<std::shared_ptr<multi_map>> get_multi_map(
124  const std::string& name)
125  {
126  return client_impl_->get_distributed_object<multi_map>(name);
127  }
128 
129  boost::shared_future<std::shared_ptr<replicated_map>> get_replicated_map(
130  const std::string& name)
131  {
132  return client_impl_->get_distributed_object<replicated_map>(name);
133  }
134 
141  boost::shared_future<std::shared_ptr<iqueue>> get_queue(
142  const std::string& name)
143  {
144  return client_impl_->get_distributed_object<iqueue>(name);
145  }
146 
154  boost::shared_future<std::shared_ptr<iset>> get_set(const std::string& name)
155  {
156  return client_impl_->get_distributed_object<iset>(name);
157  }
158 
166  boost::shared_future<std::shared_ptr<ilist>> get_list(
167  const std::string& name)
168  {
169  return client_impl_->get_distributed_object<ilist>(name);
170  }
171 
178  boost::shared_future<std::shared_ptr<itopic>> get_topic(
179  const std::string& name)
180  {
181  return client_impl_->get_distributed_object<itopic>(name);
182  };
183 
190  boost::shared_future<std::shared_ptr<reliable_topic>> get_reliable_topic(
191  const std::string& name)
192  {
193  return client_impl_->get_distributed_object<reliable_topic>(name);
194  }
195 
212  boost::shared_future<std::shared_ptr<flake_id_generator>>
213  get_flake_id_generator(const std::string& name)
214  {
215  return client_impl_->get_distributed_object<flake_id_generator>(name);
216  }
217 
230  boost::shared_future<std::shared_ptr<pn_counter>> get_pn_counter(
231  const std::string& name)
232  {
233  return client_impl_->get_distributed_object<pn_counter>(name);
234  }
235 
242  boost::shared_future<std::shared_ptr<ringbuffer>> get_ringbuffer(
243  const std::string& name)
244  {
245  return client_impl_->get_distributed_object<ringbuffer>(name);
246  }
247 
258  boost::shared_future<std::shared_ptr<iexecutor_service>>
259  get_executor_service(const std::string& name)
260  {
261  return client_impl_->get_distributed_object<iexecutor_service>(name);
262  }
263 
268  client_config& get_client_config();
269 
276  transaction_context new_transaction_context();
277 
285  transaction_context new_transaction_context(
286  const transaction_options& options);
287 
295  cluster& get_cluster();
296 
304  local_endpoint get_local_endpoint() const;
305 
316  boost::uuids::uuid add_lifecycle_listener(
318 
324  bool remove_lifecycle_listener(const boost::uuids::uuid& registration_id);
325 
329  boost::future<void> shutdown();
330 
339  spi::lifecycle_service& get_lifecycle_service();
340 
346  cp::cp_subsystem& get_cp_subsystem();
347 
352  sql::sql_service& get_sql();
353 
354 private:
356 
357  explicit hazelcast_client(client_config config);
358 
359  std::shared_ptr<impl::hazelcast_client_instance_impl> client_impl_;
360 };
361 
365 const boost::string_view HAZELCAST_API
366 version();
367 
368 } // namespace client
369 } // namespace hazelcast
370 
371 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
372 #pragma warning(pop)
373 #endif
hazelcast_client configuration class.
Hazelcast cluster interface.
Definition: cluster.h:37
A cluster-wide unique ID generator.
boost::shared_future< std::shared_ptr< imap > > get_map(const std::string &name)
Returns the distributed map instance with the specified name.
boost::shared_future< std::shared_ptr< T > > get_distributed_object(const std::string &name)
boost::shared_future< std::shared_ptr< reliable_topic > > get_reliable_topic(const std::string &name)
Returns the distributed topic instance with the specified name.
boost::shared_future< std::shared_ptr< pn_counter > > get_pn_counter(const std::string &name)
Obtain a pn_counter with the given name.
boost::shared_future< std::shared_ptr< ringbuffer > > get_ringbuffer(const std::string &name)
Returns the distributed ringbuffer instance with the specified name.
boost::shared_future< std::shared_ptr< iqueue > > get_queue(const std::string &name)
Returns the distributed queue instance with the specified name.
boost::shared_future< std::shared_ptr< iset > > get_set(const std::string &name)
Returns the distributed set instance with the specified name.
boost::shared_future< std::shared_ptr< ilist > > get_list(const std::string &name)
Returns the distributed list instance with the specified name.
boost::shared_future< std::shared_ptr< multi_map > > get_multi_map(const std::string &name)
Returns the distributed multimap instance with the specified name.
boost::shared_future< std::shared_ptr< iexecutor_service > > get_executor_service(const std::string &name)
Creates or returns the distributed executor service for the given name.
boost::shared_future< std::shared_ptr< itopic > > get_topic(const std::string &name)
Returns the distributed topic instance with the specified name.
boost::shared_future< std::shared_ptr< flake_id_generator > > get_flake_id_generator(const std::string &name)
Returns a generator that creates a cluster-wide unique IDs.
Distributed implementation of java.util.concurrent.ExecutorService.
Concurrent, distributed, client implementation of list.
Definition: ilist.h:29
Concurrent, distributed, observable and queryable map client.
Definition: imap.h:63
Concurrent, blocking, distributed, observable, client queue.
Definition: iqueue.h:30
Concurrent, distributed client implementation of std::unordered_set.
Definition: iset.h:29
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
Definition: itopic.h:43
Listener object for listening lifecycle events of hazelcast instance.
The Client interface allows to get information about a connected client's socket address,...
A specialized distributed map client whose keys can be associated with multiple values.
Definition: multi_map.h:32
PN (Positive-Negative) CRDT counter.
Definition: pn_counter.h:76
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
A Ringbuffer is a data-structure where the content is stored in a ring like structure.
Definition: ringbuffer.h:66
A service to execute SQL statements.
Definition: sql_service.h:89
Provides a context to do transactional operations; so beginning/committing transactions,...
Contains the configuration for a Hazelcast transaction.
CP Subsystem is a component of Hazelcast that builds a strongly consistent layer for a set of distrib...
Definition: cp.h:1407