Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
client_config.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 <vector>
19#include <unordered_set>
20#include <unordered_map>
21#include <memory>
22#include <boost/optional.hpp>
23
24#include "hazelcast/client/address.h"
25#include "hazelcast/client/serialization_config.h"
26#include "hazelcast/client/socket_interceptor.h"
27#include "hazelcast/client/load_balancer.h"
28#include "hazelcast/util/SynchronizedMap.h"
29#include "hazelcast/client/config/reliable_topic_config.h"
30#include "hazelcast/client/config/near_cache_config.h"
31#include "hazelcast/client/config/client_network_config.h"
32#include "hazelcast/client/config/client_connection_strategy_config.h"
33#include "hazelcast/client/config/client_flake_id_generator_config.h"
34#include "hazelcast/client/config/matcher/matching_point_config_pattern_matcher.h"
35#include "hazelcast/client/internal/config/ConfigUtils.h"
36#include "hazelcast/client/config/logger_config.h"
37#include "hazelcast/client/serialization/serialization.h"
38#include "hazelcast/client/lifecycle_listener.h"
39#include "hazelcast/client/membership_listener.h"
40
41#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
42#pragma warning(push)
43#pragma warning(disable : 4251) // for dll export
44#endif
45
46namespace hazelcast {
47namespace client {
49
50namespace connection {
51class ClientConnectionManagerImpl;
52};
53
54namespace security {
55class HAZELCAST_API credentials
56{
57public:
58 enum credential_type
59 {
60 username_password,
61 token
62 };
63
64 credentials(const std::string& name);
65
66 virtual ~credentials();
67
68 const std::string& name() const;
69
70 virtual credential_type type() const = 0;
71
72private:
73 std::string name_;
74};
75
76class HAZELCAST_API username_password_credentials : public credentials
77{
78public:
79 username_password_credentials(const std::string& name,
80 const std::string& password);
81
82 const std::string& password() const;
83
84 credential_type type() const override;
85
86private:
87 std::string password_;
88};
89
90class HAZELCAST_API token_credentials : public credentials
91{
92public:
93 token_credentials(const std::vector<byte>& token);
94
95 const std::vector<byte>& token() const;
96
97 credential_type type() const override;
98
99private:
100 std::vector<byte> token_;
101};
102}; // namespace security
103
107class HAZELCAST_API client_config
108{
109 friend class spi::impl::ClientClusterServiceImpl;
110 friend class connection::ClientConnectionManagerImpl;
111
112public:
122
123 client_config(const client_config& rhs) = delete;
124
125 client_config& operator=(const client_config& rhs) = delete;
126
128
129 client_config& operator=(client_config&& rhs);
130
137 const std::string& get_cluster_name() const;
138
139 client_config& set_cluster_name(const std::string& cluster_name);
140
148 const std::shared_ptr<security::credentials>& credential);
149
150 const std::shared_ptr<security::credentials>& get_credentials() const;
151
165 client_config& set_redo_operation(bool redo_operation);
166
172 bool is_redo_operation() const;
173
181
187
200
205 const std::vector<lifecycle_listener>& get_lifecycle_listeners() const;
206
219
225 const std::vector<membership_listener>& get_membership_listeners() const;
226
233
243
249
260
266 const std::unordered_map<std::string, std::string>& get_properties() const;
267
277 client_config& set_property(const std::string& name,
278 const std::string& value);
279
287 const config::reliable_topic_config& reliable_topic_config);
288
297 const std::string& name);
298
309 const config::near_cache_config& near_cache_config);
310
319 const std::string& name) const;
320
328
338 const config::client_network_config& network_config);
339
340 const boost::optional<std::string>& get_instance_name() const;
341
342 client_config& set_instance_name(const std::string& instance_name);
343
349 int32_t get_executor_pool_size() const;
350
357 void set_executor_pool_size(int32_t executor_pool_size);
358
359 config::client_connection_strategy_config& get_connection_strategy_config();
360
361 client_config& set_connection_strategy_config(
363 connection_strategy_config);
364
380 find_flake_id_generator_config(const std::string& name);
381
406 get_flake_id_generator_config(const std::string& name);
407
418
424
425 const std::unordered_set<std::string>& get_labels() const;
426
427 client_config& set_labels(const std::unordered_set<std::string>& labels);
428
429 client_config& add_label(const std::string& label);
430
440 client_config& backup_acks_enabled(bool enabled);
441
448 bool backup_acks_enabled();
449
450private:
451 friend class reliable_topic;
452
453 const config::reliable_topic_config* lookup_reliable_topic_config(
454 const std::string& name) const;
455
456 std::string cluster_name_;
457
458 config::client_network_config network_config_;
459
460 serialization_config serialization_config_;
461
462 boost::optional<load_balancer> load_balancer_;
463
464 std::vector<membership_listener> membership_listeners_;
465
466 std::vector<lifecycle_listener> lifecycle_listeners_;
467
468 std::unordered_map<std::string, std::string> properties_;
469
470 bool redo_operation_;
471
472 socket_interceptor socket_interceptor_;
473
474 std::shared_ptr<security::credentials> credentials_;
475
476 std::unordered_map<std::string, config::reliable_topic_config>
477 reliable_topic_config_map_;
478
479 std::unordered_map<std::string, config::near_cache_config>
480 near_cache_config_map_;
481
482 boost::optional<std::string> instance_name_;
483
487 int32_t executor_pool_size_;
488
489 config::client_connection_strategy_config connection_strategy_config_;
490
491 std::unordered_map<std::string, config::client_flake_id_generator_config>
492 flake_id_generator_config_map_;
493
495 config_pattern_matcher_;
496
497 config::logger_config logger_config_;
498
499 std::unordered_set<std::string> labels_;
500
501 bool backup_acks_enabled_ = true;
502};
503
504} // namespace client
505} // namespace hazelcast
506
507#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
508#pragma warning(pop)
509#endif
client_config & set_serialization_config(serialization_config const &serialization_config)
SerializationConfig is used to.
Definition config.cpp:1149
serialization_config & get_serialization_config()
Definition config.cpp:1143
const config::reliable_topic_config & get_reliable_topic_config(const std::string &name)
Gets the ClientReliableTopicConfig for a given reliable topic name.
Definition config.cpp:1179
client_config & set_socket_interceptor(socket_interceptor &&interceptor)
Will be called with the Socket, each time client creates a connection to any Member.
Definition config.cpp:1130
client_config & set_redo_operation(bool redo_operation)
If true, client will redo the operations that were executing on the server and client lost the connec...
Definition config.cpp:1061
void set_executor_pool_size(int32_t executor_pool_size)
Sets Client side Executor pool size.
Definition config.cpp:1264
const config::near_cache_config * get_near_cache_config(const std::string &name) const
Gets the NearCacheConfig configured for the map / cache with name.
Definition config.cpp:1218
client_config & add_listener(lifecycle_listener &&listener)
Adds a listener to configuration to be registered when hazelcast_client starts.
Definition config.cpp:1104
client_config & set_credentials(const std::shared_ptr< security::credentials > &credential)
There are two types of credentials you can provide, \username_password_credentials and \token_credent...
Definition config.cpp:1383
const std::unordered_map< std::string, std::string > & get_properties() const
Gets a reference to properties map.
Definition config.cpp:1157
const socket_interceptor & get_socket_interceptor() const
Will be called with the Socket, each time client creates a connection to any Member.
Definition config.cpp:1137
client_config()
Constructor with default values.
Definition config.cpp:1048
config::client_network_config & get_network_config()
Gets {}.
Definition config.cpp:1203
int32_t get_executor_pool_size() const
Pool size for internal ExecutorService which handles responses etc.
Definition config.cpp:1258
client_config & add_reliable_topic_config(const config::reliable_topic_config &reliable_topic_config)
Adds a ClientReliableTopicConfig.
Definition config.cpp:1170
bool is_redo_operation() const
see setRedoOperation returns redoOperation
Definition config.cpp:1068
const std::vector< membership_listener > & get_membership_listeners() const
Returns registered membershipListeners.
Definition config.cpp:1124
client_config & backup_acks_enabled(bool enabled)
This feature reduces number of hops and increase performance for smart clients.
Definition config.cpp:1364
client_config & add_flake_id_generator_config(const config::client_flake_id_generator_config &config)
Adds a flake ID generator configuration.
Definition config.cpp:1323
const std::string & get_cluster_name() const
Returns the configured cluster name.
Definition config.cpp:1331
config::logger_config & get_logger_config()
Definition config.cpp:1098
client_config & set_load_balancer(load_balancer &&load_balancer)
Used to distribute the operations to multiple connections.
Definition config.cpp:1091
load_balancer & get_load_balancer()
Used to distribute the operations to multiple Endpoints.
Definition config.cpp:1074
client_config & set_network_config(const config::client_network_config &network_config)
Sets {}.
Definition config.cpp:1237
const config::client_flake_id_generator_config * get_flake_id_generator_config(const std::string &name)
Returns the {} for the given name, creating one if necessary and adding it to the collection of known...
Definition config.cpp:1299
client_config & add_near_cache_config(const config::near_cache_config &near_cache_config)
Helper method to add a new NearCacheConfig.
Definition config.cpp:1209
const config::client_flake_id_generator_config * find_flake_id_generator_config(const std::string &name)
Returns a {} configuration for the given flake ID generator name.
Definition config.cpp:1284
client_config & set_property(const std::string &name, const std::string &value)
Sets the value of a named property.
Definition config.cpp:1163
const std::vector< lifecycle_listener > & get_lifecycle_listeners() const
Definition config.cpp:1118
Client connection strategy configuration is used for setting custom strategies and configuring strate...
The ClientFlakeIdGeneratorConfig contains the configuration for the client regarding Flake ID Generat...
Contains configuration parameters for client network related behaviour.
This ConfigPatternMatcher supports a simplified wildcard matching.
Contains the configuration for a Near Cache.
A event that is sent when a MembershipListener is registered.
Listener object for listening lifecycle events of hazelcast instance.
load_balancer allows you to send operations to one of a number of endpoints(Members).
An interface that provides the ability to intercept the creation of sockets.