Hazelcast C++ Client
Hazelcast C++ Client Library
hazelcast_client.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 <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 new_client();
36 
41  boost::future<client::hazelcast_client> HAZELCAST_API new_client(client::client_config config);
42 
43  namespace client {
44  /*
45  * You can use native C++ Client to connect to hazelcast nodes and make almost all operations that a node does.
46  * Different from nodes, clients do not hold data.
47  *
48  * Some of features of C++ Clients are:
49  * * Access to distributed data structures like IMap, IQueue, MultiMap, ITopic etc... For complete list see the classes
50  * extending DistributedObject
51  * * Access to transactional distributed data structures like TransactionalMap, TransactionalQueue etc...
52  * * Ability to add cluster listeners to a cluster and entry/item listeners to distributed data structures.
53  * @see MembershipListener, IMap#add_entry_listener , IQueue#add_item_listener etc .
54  * * C++ Client is smart by default, which means that it knows where the data is and asks directly to correct node.
55  * Note that you can turn this feature off ( client_config#setSmart), if you don't want your clients to connect every
56  * node.
57  *
58  * Our C++ client is completely open source and the source code is freely available at https://github.com/hazelcast/hazelcast-cpp-client .
59  * Please feel free to contribute. You can join our community at https://groups.google.com/forum/#!forum/hazelcast where
60  * you can find answers to your questions.
61  */
62  class HAZELCAST_API hazelcast_client {
63  friend class spi::ClientContext;
64 
65  public:
66  friend boost::future<hazelcast_client> hazelcast::new_client();
67 
68  friend boost::future<hazelcast_client> hazelcast::new_client(hazelcast::client::client_config config);
69 
70  virtual ~hazelcast_client();
71 
77  const std::string &get_name() const;
78 
85  template<typename T>
86  boost::shared_future<std::shared_ptr<T>> get_distributed_object(const std::string& name) {
87  return client_impl_->get_distributed_object<T>(name);
88  }
89 
99  boost::shared_future<std::shared_ptr<imap>> get_map(const std::string &name) {
100  return client_impl_->get_distributed_object<imap>(name);
101  }
102 
109  boost::shared_future<std::shared_ptr<multi_map>> get_multi_map(const std::string& name) {
110  return client_impl_->get_distributed_object<multi_map>(name);
111  }
112 
113  boost::shared_future<std::shared_ptr<replicated_map>> get_replicated_map(const std::string &name) {
114  return client_impl_->get_distributed_object<replicated_map>(name);
115  }
116 
123  boost::shared_future<std::shared_ptr<iqueue>> get_queue(const std::string& name) {
124  return client_impl_->get_distributed_object<iqueue>(name);
125  }
126 
134  boost::shared_future<std::shared_ptr<iset>> get_set(const std::string& name) {
135  return client_impl_->get_distributed_object<iset>(name);
136  }
137 
145  boost::shared_future<std::shared_ptr<ilist>> get_list(const std::string& name) {
146  return client_impl_->get_distributed_object<ilist>(name);
147  }
148 
155  boost::shared_future<std::shared_ptr<itopic>> get_topic(const std::string& name) {
156  return client_impl_->get_distributed_object<itopic>(name);
157  };
158 
165  boost::shared_future<std::shared_ptr<reliable_topic>> get_reliable_topic(const std::string &name) {
166  return client_impl_->get_distributed_object<reliable_topic>(name);
167  }
168 
185  boost::shared_future<std::shared_ptr<flake_id_generator>> get_flake_id_generator(const std::string& name) {
186  return client_impl_->get_distributed_object<flake_id_generator>(name);
187  }
188 
201  boost::shared_future<std::shared_ptr<pn_counter>> get_pn_counter(const std::string& name) {
202  return client_impl_->get_distributed_object<pn_counter>(name);
203  }
204 
211  boost::shared_future<std::shared_ptr<ringbuffer>> get_ringbuffer(const std::string& name) {
212  return client_impl_->get_distributed_object<ringbuffer>(name);
213  }
214 
226  boost::shared_future<std::shared_ptr<iexecutor_service>> get_executor_service(const std::string &name) {
227  return client_impl_->get_distributed_object<iexecutor_service>(name);
228  }
229 
234  client_config& get_client_config();
235 
241  transaction_context new_transaction_context();
242 
249  transaction_context new_transaction_context(const transaction_options& options);
250 
258  cluster& get_cluster();
259 
267  local_endpoint get_local_endpoint() const;
268 
279  boost::uuids::uuid add_lifecycle_listener(lifecycle_listener &&lifecycle_listener);
280 
286  bool remove_lifecycle_listener(const boost::uuids::uuid &registration_id);
287 
291  boost::future<void> shutdown();
292 
300  spi::lifecycle_service &get_lifecycle_service();
301 
306  cp::cp_subsystem &get_cp_subsystem();
307 
308  private:
310 
311  explicit hazelcast_client(client_config config);
312 
313  std::shared_ptr<impl::hazelcast_client_instance_impl> client_impl_;
314  };
315 
319  const boost::string_view HAZELCAST_API version();
320 
321  }
322 }
323 
324 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
325 #pragma warning(pop)
326 #endif
hazelcast_client configuration class.
Hazelcast cluster interface.
Definition: cluster.h:36
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:28
Concurrent, distributed, observable and queryable map client.
Definition: imap.h:63
Concurrent, blocking, distributed, observable, client queue.
Definition: iqueue.h:29
Concurrent, distributed client implementation of std::unordered_set.
Definition: iset.h:28
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
Definition: itopic.h:39
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:30
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:59
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:1300