Hazelcast C++ Client
client_config.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 <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  public:
57  enum credential_type {
58  username_password,
59  token
60  };
61 
62  credentials(const std::string &name);
63 
64  virtual ~credentials();
65 
66  const std::string &name() const;
67 
68  virtual const credential_type type() const = 0;
69 
70  private:
71  std::string name_;
72  };
73 
74  class HAZELCAST_API username_password_credentials : public credentials {
75  public:
76  username_password_credentials(const std::string &name, const std::string &password);
77 
78  const std::string &password() const;
79 
80  const credential_type type() const override;
81 
82  private:
83  std::string password_;
84  };
85 
86  class HAZELCAST_API token_credentials : public credentials {
87  public:
88  token_credentials(const std::vector<byte> &token);
89 
90  const std::vector<byte> &token() const;
91 
92  const credential_type type() const override;
93 
94  private:
95  std::vector<byte> token_;
96  };
97  };
98 
102  class HAZELCAST_API client_config {
103  friend class spi::impl::ClientClusterServiceImpl;
104  friend class connection::ClientConnectionManagerImpl;
105  public:
106 
115  client_config();
116 
117  client_config(const client_config &rhs) = delete;
118 
119  client_config &operator=(const client_config &rhs) = delete;
120 
122 
123  client_config &operator=(client_config &&rhs);
124 
131  const std::string &get_cluster_name() const;
132 
133  client_config &set_cluster_name(const std::string &cluster_name);
134 
140  client_config &set_credentials(const std::shared_ptr<security::credentials> &credential);
141 
142  const std::shared_ptr<security::credentials> &get_credentials() const;
143 
155  client_config &set_redo_operation(bool redo_operation);
156 
162  bool is_redo_operation() const;
163 
169  client_config &set_socket_interceptor(socket_interceptor &&interceptor);
170 
174  const socket_interceptor &get_socket_interceptor() const;
175 
186  client_config &add_listener(lifecycle_listener &&listener);
187 
192  const std::vector<lifecycle_listener> &get_lifecycle_listeners() const;
193 
204  client_config &add_listener(membership_listener &&listener);
205 
211  const std::vector<membership_listener> &get_membership_listeners() const;
212 
218  load_balancer &get_load_balancer();
219 
228  client_config &set_load_balancer(load_balancer &&load_balancer);
229 
234  serialization_config &get_serialization_config();
235 
243  client_config &set_serialization_config(serialization_config const &serialization_config);
244 
250  const std::unordered_map<std::string, std::string> &get_properties() const;
251 
261  client_config &set_property(const std::string &name, const std::string &value);
262 
269  client_config &add_reliable_topic_config(const config::reliable_topic_config &reliable_topic_config);
270 
277  const config::reliable_topic_config &get_reliable_topic_config(const std::string &name);
278 
288  client_config &add_near_cache_config(const config::near_cache_config &near_cache_config);
289 
297  const config::near_cache_config *get_near_cache_config(const std::string &name) const;
298 
305  config::client_network_config &get_network_config();
306 
314  client_config &set_network_config(const config::client_network_config &network_config);
315 
316  const boost::optional<std::string> &get_instance_name() const;
317 
318  client_config &set_instance_name(const std::string &instance_name);
319 
325  int32_t get_executor_pool_size() const;
326 
333  void set_executor_pool_size(int32_t executor_pool_size);
334 
335  config::client_connection_strategy_config &get_connection_strategy_config();
336 
337  client_config &
338  set_connection_strategy_config(const config::client_connection_strategy_config &connection_strategy_config);
339 
355  const config::client_flake_id_generator_config *find_flake_id_generator_config(const std::string &name);
356 
382  const config::client_flake_id_generator_config *get_flake_id_generator_config(const std::string &name);
383 
392  client_config &add_flake_id_generator_config(const config::client_flake_id_generator_config &config);
393 
398  config::logger_config &get_logger_config();
399 
400  const std::unordered_set<std::string> &get_labels() const;
401 
402  client_config &set_labels(const std::unordered_set<std::string> &labels);
403 
404  client_config &add_label(const std::string &label);
405 
415  client_config &backup_acks_enabled(bool enabled);
416 
423  bool backup_acks_enabled();
424 
425  private:
426  std::string cluster_name_;
427 
428  config::client_network_config network_config_;
429 
430  serialization_config serialization_config_;
431 
432  boost::optional<load_balancer> load_balancer_;
433 
434  std::vector<membership_listener> membership_listeners_;
435 
436  std::vector<lifecycle_listener> lifecycle_listeners_;
437 
438  std::unordered_map<std::string, std::string> properties_;
439 
440  bool redo_operation_;
441 
442  socket_interceptor socket_interceptor_;
443 
444  std::shared_ptr<security::credentials> credentials_;
445 
446  std::unordered_map<std::string, config::reliable_topic_config> reliable_topic_config_map_;
447 
448  std::unordered_map<std::string, config::near_cache_config> near_cache_config_map_;
449 
450  boost::optional<std::string> instance_name_;
451 
455  int32_t executor_pool_size_;
456 
457  config::client_connection_strategy_config connection_strategy_config_;
458 
459  std::unordered_map<std::string, config::client_flake_id_generator_config> flake_id_generator_config_map_;
460 
462 
463  config::logger_config logger_config_;
464 
465  std::unordered_set<std::string> labels_;
466 
467  bool backup_acks_enabled_ = true;
468  };
469 
470  }
471 }
472 
473 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
474 #pragma warning(pop)
475 #endif
476 
477 
Contains configuration parameters for client network related behaviour.
Definition: client_network_config.h:37
SerializationConfig is used to.
Definition: serialization_config.h:38
Contains the configuration for a Near Cache.
Definition: near_cache_config.h:33
Cluster membership listener.
Definition: membership_listener.h:57
Definition: client_config.h:55
This.
Definition: matching_point_config_pattern_matcher.h:34
An interface that provides the ability to intercept the creation of sockets.
Definition: socket_interceptor.h:43
hazelcast_client configuration class.
Definition: client_config.h:102
Client connection strategy configuration is used for setting custom strategies and configuring strate...
Definition: client_connection_strategy_config.h:32
load_balancer allows you to send operations to one of a number of endpoints(Members).
Definition: load_balancer.h:37
Definition: address.h:30
Listener object for listening lifecycle events of hazelcast instance.
Definition: lifecycle_listener.h:48
Definition: logger_config.h:33
Definition: reliable_topic_config.h:29
The.
Definition: client_flake_id_generator_config.h:36