Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
hazelcast_client.h
1/*
2 * Copyright (c) 2008-2025, 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#include "hazelcast/client/flake_id_generator.h"
22#include "hazelcast/client/iexecutor_service.h"
23#include "hazelcast/client/itopic.h"
24#include "hazelcast/client/pn_counter.h"
25#include "hazelcast/client/reliable_topic.h"
26#include "hazelcast/client/replicated_map.h"
27
28#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
29#pragma warning(push)
30#pragma warning(disable : 4251) // for dll export
31#endif
32
33namespace hazelcast {
34namespace client {
36}
37
41boost::future<client::hazelcast_client> HAZELCAST_API
42new_client();
43
48boost::future<client::hazelcast_client> HAZELCAST_API
49new_client(client::client_config config);
50
51namespace client {
52/*
53 * You can use native C++ Client to connect to hazelcast nodes and make almost
54 * all operations that a node does. Different from nodes, clients do not hold
55 * data.
56 *
57 * Some of features of C++ Clients are:
58 * * Access to distributed data structures like IMap, IQueue, MultiMap, ITopic
59 * etc... For complete list see the classes extending DistributedObject
60 * * Access to transactional distributed data structures like TransactionalMap,
61 * TransactionalQueue etc...
62 * * Ability to add cluster listeners to a cluster and entry/item listeners to
63 * distributed data structures.
64 * @see MembershipListener, IMap#add_entry_listener , IQueue#add_item_listener
65 * etc .
66 * * C++ Client is smart by default, which means that it knows where the data is
67 * and asks directly to correct node. Note that you can turn this feature off (
68 * client_config#setSmart), if you don't want your clients to connect every
69 * node.
70 *
71 * Our C++ client is completely open source and the source code is freely
72 * available at https://github.com/hazelcast/hazelcast-cpp-client . Please feel
73 * free to contribute. You can join our community at
74 * https://hazelcastcommunity.slack.com/channels/cpp-client where you can find answers
75 * to your questions.
76 */
77class HAZELCAST_API hazelcast_client
78{
79 friend class spi::ClientContext;
80
81public:
82 friend boost::future<hazelcast_client> hazelcast::new_client();
83
84 friend boost::future<hazelcast_client> hazelcast::new_client(
86
87 virtual ~hazelcast_client();
88
94 const std::string& get_name() const;
95
102 template<typename T>
103 boost::shared_future<std::shared_ptr<T>> get_distributed_object(
104 const std::string& name)
105 {
106 return client_impl_->get_distributed_object<T>(name);
107 }
108
118 boost::shared_future<std::shared_ptr<imap>> get_map(const std::string& name)
119 {
120 return client_impl_->get_distributed_object<imap>(name);
121 }
122
129 boost::shared_future<std::shared_ptr<multi_map>> get_multi_map(
130 const std::string& name)
131 {
132 return client_impl_->get_distributed_object<multi_map>(name);
133 }
134
135 boost::shared_future<std::shared_ptr<replicated_map>> get_replicated_map(
136 const std::string& name)
137 {
138 return client_impl_->get_distributed_object<replicated_map>(name);
139 }
140
147 boost::shared_future<std::shared_ptr<iqueue>> get_queue(
148 const std::string& name)
149 {
150 return client_impl_->get_distributed_object<iqueue>(name);
151 }
152
160 boost::shared_future<std::shared_ptr<iset>> get_set(const std::string& name)
161 {
162 return client_impl_->get_distributed_object<iset>(name);
163 }
164
172 boost::shared_future<std::shared_ptr<ilist>> get_list(
173 const std::string& name)
174 {
175 return client_impl_->get_distributed_object<ilist>(name);
176 }
177
184 boost::shared_future<std::shared_ptr<itopic>> get_topic(
185 const std::string& name)
186 {
187 return client_impl_->get_distributed_object<itopic>(name);
188 };
189
196 boost::shared_future<std::shared_ptr<reliable_topic>> get_reliable_topic(
197 const std::string& name)
198 {
199 return client_impl_->get_distributed_object<reliable_topic>(name);
200 }
201
218 boost::shared_future<std::shared_ptr<flake_id_generator>>
219 get_flake_id_generator(const std::string& name)
220 {
221 return client_impl_->get_distributed_object<flake_id_generator>(name);
222 }
223
236 boost::shared_future<std::shared_ptr<pn_counter>> get_pn_counter(
237 const std::string& name)
238 {
239 return client_impl_->get_distributed_object<pn_counter>(name);
240 }
241
248 boost::shared_future<std::shared_ptr<ringbuffer>> get_ringbuffer(
249 const std::string& name)
250 {
251 return client_impl_->get_distributed_object<ringbuffer>(name);
252 }
253
264 boost::shared_future<std::shared_ptr<iexecutor_service>>
265 get_executor_service(const std::string& name)
266 {
267 return client_impl_->get_distributed_object<iexecutor_service>(name);
268 }
269
274 client_config& get_client_config();
275
282 transaction_context new_transaction_context();
283
291 transaction_context new_transaction_context(
292 const transaction_options& options);
293
301 cluster& get_cluster();
302
310 local_endpoint get_local_endpoint() const;
311
322 boost::uuids::uuid add_lifecycle_listener(
324
330 bool remove_lifecycle_listener(const boost::uuids::uuid& registration_id);
331
335 boost::future<void> shutdown();
336
345 spi::lifecycle_service& get_lifecycle_service();
346
352 cp::cp_subsystem& get_cp_subsystem();
353
358 sql::sql_service& get_sql();
359
360private:
362
363 explicit hazelcast_client(client_config config);
364
365 std::shared_ptr<impl::hazelcast_client_instance_impl> client_impl_;
366};
367
371const boost::string_view HAZELCAST_API
372version();
373
374} // namespace client
375} // namespace hazelcast
376
377#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
378#pragma warning(pop)
379#endif
hazelcast_client configuration class.
Hazelcast cluster interface.
Definition cluster.h:37
A cluster-wide unique ID generator.
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< iqueue > > get_queue(const std::string &name)
Returns the distributed queue instance with the specified 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< iset > > get_set(const std::string &name)
Returns the distributed set 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< 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< ringbuffer > > get_ringbuffer(const std::string &name)
Returns the distributed ringbuffer instance with the specified name.
boost::shared_future< std::shared_ptr< imap > > get_map(const std::string &name)
Returns the distributed map instance with the specified name.
const std::string & get_name() const
Returns the name of this client instance.
boost::shared_future< std::shared_ptr< T > > get_distributed_object(const std::string &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.
boost::shared_future< std::shared_ptr< reliable_topic > > get_reliable_topic(const std::string &name)
Returns the distributed topic instance with the specified name.
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:31
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:67
A service to execute SQL statements.
Definition sql_service.h:90
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:1408