Hazelcast C++ Client
Hazelcast C++ Client Library
client_config.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 <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 
46 namespace hazelcast {
47 namespace client {
48 class initial_membership_event;
49 
50 namespace connection {
51 class ClientConnectionManagerImpl;
52 };
53 
54 namespace security {
55 class HAZELCAST_API credentials
56 {
57 public:
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 
72 private:
73  std::string name_;
74 };
75 
76 class HAZELCAST_API username_password_credentials : public credentials
77 {
78 public:
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 
86 private:
87  std::string password_;
88 };
89 
90 class HAZELCAST_API token_credentials : public credentials
91 {
92 public:
93  token_credentials(const std::vector<byte>& token);
94 
95  const std::vector<byte>& token() const;
96 
97  credential_type type() const override;
98 
99 private:
100  std::vector<byte> token_;
101 };
102 }; // namespace security
103 
107 class HAZELCAST_API client_config
108 {
109  friend class spi::impl::ClientClusterServiceImpl;
110  friend class connection::ClientConnectionManagerImpl;
111 
112 public:
121  client_config();
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 
147  client_config& set_credentials(
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 
180  client_config& set_socket_interceptor(socket_interceptor&& interceptor);
181 
186  const socket_interceptor& get_socket_interceptor() const;
187 
199  client_config& add_listener(lifecycle_listener&& listener);
200 
205  const std::vector<lifecycle_listener>& get_lifecycle_listeners() const;
206 
218  client_config& add_listener(membership_listener&& listener);
219 
225  const std::vector<membership_listener>& get_membership_listeners() const;
226 
232  load_balancer& get_load_balancer();
233 
242  client_config& set_load_balancer(load_balancer&& load_balancer);
243 
248  serialization_config& get_serialization_config();
249 
258  client_config& set_serialization_config(
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 
286  client_config& add_reliable_topic_config(
287  const config::reliable_topic_config& reliable_topic_config);
288 
296  const config::reliable_topic_config& get_reliable_topic_config(
297  const std::string& name);
298 
308  client_config& add_near_cache_config(
309  const config::near_cache_config& near_cache_config);
310 
318  const config::near_cache_config* get_near_cache_config(
319  const std::string& name) const;
320 
327  config::client_network_config& get_network_config();
328 
337  client_config& set_network_config(
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 
416  client_config& add_flake_id_generator_config(
418 
423  config::logger_config& get_logger_config();
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 
450 private:
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
hazelcast_client configuration class.
Client connection strategy configuration is used for setting custom strategies and configuring strate...
Contains configuration parameters for client network related behaviour.
Contains the configuration for a Near Cache.
Listener object for listening lifecycle events of hazelcast instance.
load_balancer allows you to send operations to one of a number of endpoints(Members).
Definition: load_balancer.h:41
Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subs...
SerializationConfig is used to.
An interface that provides the ability to intercept the creation of sockets.