Hazelcast C++ Client
Hazelcast C++ Client Library
config.cpp
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 
17 #include <atomic>
18 
19 #include "hazelcast/client/client_config.h"
20 #include "hazelcast/client/serialization_config.h"
21 #include "hazelcast/client/config/ssl_config.h"
22 #include "hazelcast/util/Preconditions.h"
23 #include "hazelcast/client/config/client_flake_id_generator_config.h"
24 #include "hazelcast/client/exception/protocol_exceptions.h"
25 #include "hazelcast/client/internal/partition/strategy/StringPartitioningStrategy.h"
26 #include "hazelcast/client/address.h"
27 #include "hazelcast/client/config/client_network_config.h"
28 #include "hazelcast/client/config/client_aws_config.h"
29 #include "hazelcast/client/config/reliable_topic_config.h"
30 #include "hazelcast/client/config/client_connection_strategy_config.h"
31 #include "hazelcast/client/config/logger_config.h"
32 #include "hazelcast/client/config/index_config.h"
33 #include "hazelcast/client/config/matcher/matching_point_config_pattern_matcher.h"
34 #include "hazelcast/client/query/predicates.h"
35 #include "hazelcast/client/lifecycle_listener.h"
36 #include "hazelcast/client/config/eviction_strategy_type.h"
37 #include "hazelcast/client/cluster.h"
38 #include "hazelcast/client/initial_membership_event.h"
39 
40 namespace hazelcast {
41  namespace client {
43  }
44 
46  return version_;
47  }
48 
50  this->version_ = v;
51  return *this;
52  }
53 
54  std::shared_ptr<serialization::global_serializer> serialization_config::get_global_serializer() const {
55  return global_serializer_;
56  }
57 
59  const std::shared_ptr<serialization::global_serializer> &global_serializer) {
60  global_serializer_ = global_serializer;
61  return *this;
62  }
63 
64  serialization_config &serialization_config::set_byte_order(boost::endian::order byte_order) {
65  byte_order_ = byte_order;
66  return *this;
67  }
68 
69  boost::endian::order serialization_config::get_byte_order() const {
70  return byte_order_;
71  }
72 
73  namespace config {
74  ssl_config::ssl_config()
75 #ifdef HZ_BUILD_WITH_SSL
76  : enabled_(false), ssl_protocol_(tlsv12)
77 #endif
78  {}
79 
80 #ifdef HZ_BUILD_WITH_SSL
81  ssl_config &ssl_config::set_context(boost::asio::ssl::context ctx) {
82  util::Preconditions::check_ssl("ssl_config::set_context");
83  if (enabled_) {
84  throw exception::illegal_argument(
85  "You should either use the deprecated methods or this method to enable ssl. You already used the deprecated way.");
86  }
87  ssl_context_ = std::make_shared<boost::asio::ssl::context>(std::move(ctx));
88  return *this;
89  }
90 
91  bool ssl_config::is_enabled() const {
92  return ssl_context_ || enabled_;
93  }
94 
95  ssl_config &ssl_config::set_enabled(bool is_enabled) {
96  util::Preconditions::check_ssl("ssl_config::set_enabled");
97  check_context_enabled_already();
98  this->enabled_ = is_enabled;
99  return *this;
100  }
101 
102  void ssl_config::check_context_enabled_already() const {
103  if (ssl_context_) {
104  throw exception::illegal_argument("You should either use set_context or this method.");
105  }
106  }
107 
108  ssl_config &ssl_config::set_protocol(ssl_protocol protocol) {
109  check_context_enabled_already();
110  this->ssl_protocol_ = protocol;
111  return *this;
112  }
113 
114  ssl_protocol ssl_config::get_protocol() const {
115  check_context_enabled_already();
116  return ssl_protocol_;
117  }
118 
119  const std::vector<std::string> &ssl_config::get_verify_files() const {
120  check_context_enabled_already();
121  return client_verify_files_;
122  }
123 
124  ssl_config &ssl_config::add_verify_file(const std::string &filename) {
125  check_context_enabled_already();
126  this->client_verify_files_.push_back(filename);
127  return *this;
128  }
129 
130  const std::string &ssl_config::get_cipher_list() const {
131  return cipher_list_;
132  }
133 
134  ssl_config &ssl_config::set_cipher_list(const std::string &ciphers) {
135  this->cipher_list_ = ciphers;
136  return *this;
137  }
138 #endif
139 
141 
142  client_flake_id_generator_config::client_flake_id_generator_config(const std::string &name)
143  : name_(name), prefetch_count_(client_flake_id_generator_config::DEFAULT_PREFETCH_COUNT),
144  prefetch_validity_duration_(client_flake_id_generator_config::DEFAULT_PREFETCH_VALIDITY_MILLIS) {}
145 
146  const std::string &client_flake_id_generator_config::get_name() const {
147  return name_;
148  }
149 
150  client_flake_id_generator_config &client_flake_id_generator_config::set_name(const std::string &n) {
151  client_flake_id_generator_config::name_ = n;
152  return *this;
153  }
154 
155  int32_t client_flake_id_generator_config::get_prefetch_count() const {
156  return prefetch_count_;
157  }
158 
159  client_flake_id_generator_config &client_flake_id_generator_config::set_prefetch_count(int32_t count) {
160  std::ostringstream out;
161  out << "prefetch-count must be 1.." << MAXIMUM_PREFETCH_COUNT << ", not " << count;
162  util::Preconditions::check_true(count > 0 && count <= MAXIMUM_PREFETCH_COUNT, out.str());
163  prefetch_count_ = count;
164  return *this;
165  }
166 
167  std::chrono::milliseconds client_flake_id_generator_config::get_prefetch_validity_duration() const {
168  return prefetch_validity_duration_;
169  }
170 
172  client_flake_id_generator_config::set_prefetch_validity_duration(std::chrono::milliseconds duration) {
173  util::Preconditions::check_not_negative(duration.count(),
174  "duration must be nonnegative");
175  prefetch_validity_duration_ = duration;
176  return *this;
177  }
178 
179  constexpr std::chrono::milliseconds connection_retry_config::INITIAL_BACKOFF;
180  constexpr std::chrono::milliseconds connection_retry_config::MAX_BACKOFF;
181  constexpr std::chrono::milliseconds connection_retry_config::CLUSTER_CONNECT_TIMEOUT;
182  constexpr double connection_retry_config::JITTER;
183 
184  std::chrono::milliseconds connection_retry_config::get_initial_backoff_duration() const {
185  return initial_backoff_duration_;
186  }
187 
189  connection_retry_config::set_initial_backoff_duration(std::chrono::milliseconds initial_backoff_duration) {
190  util::Preconditions::check_not_negative(initial_backoff_duration.count(),
191  "Initial backoff must be non-negative!");
192  initial_backoff_duration_ = initial_backoff_duration;
193  return *this;
194  }
195 
196  std::chrono::milliseconds connection_retry_config::get_max_backoff_duration() const {
197  return max_backoff_duration_;
198  }
199 
201  connection_retry_config::set_max_backoff_duration(std::chrono::milliseconds max_backoff_duration) {
202  util::Preconditions::check_not_negative(max_backoff_duration.count(),
203  "Max backoff must be non-negative!");
204  max_backoff_duration_ = max_backoff_duration;
205  return *this;
206  }
207 
208  double connection_retry_config::get_multiplier() const {
209  return multiplier_;
210  }
211 
212  connection_retry_config &connection_retry_config::set_multiplier(double m) {
213  util::Preconditions::check_true(m >= 1.0, "Multiplier must be greater than or equal to 1.0!");
214  multiplier_ = m;
215  return *this;
216  }
217 
218  std::chrono::milliseconds connection_retry_config::get_cluster_connect_timeout() const {
219  return cluster_connect_timeout_;
220  }
221 
222  connection_retry_config &connection_retry_config::set_cluster_connect_timeout(
223  std::chrono::milliseconds cluster_connect_timeout) {
224  util::Preconditions::check_not_negative(cluster_connect_timeout.count(),
225  "Cluster connect timeout must be non-negative!");
226  cluster_connect_timeout_ = cluster_connect_timeout;
227  return *this;
228  }
229 
230  double connection_retry_config::get_jitter() const {
231  return jitter_;
232  }
233 
234  connection_retry_config &connection_retry_config::set_jitter(double jitter) {
235  util::Preconditions::check_true(jitter >= 0.0 && jitter <= 1.0, "Jitter must be in range [0.0, 1.0]");
236  jitter_ = jitter;
237  return *this;
238  }
239 
240  client_network_config::client_network_config()
241  : connection_timeout_(5000), smart_routing_(true) {}
242 
244  return ssl_config_;
245  }
246 
248  ssl_config_ = config;
249  return *this;
250  }
251 
252  std::chrono::milliseconds client_network_config::get_connection_timeout() const {
253  return connection_timeout_;
254  }
255 
257  this->client_aws_config_ = client_aws_config;
258  return *this;
259  }
260 
262  return client_aws_config_;
263  }
264 
266  return cloud_config_;
267  }
268 
270  return smart_routing_;
271  }
272 
274  client_network_config::smart_routing_ = smart_routing;
275  return *this;
276  }
277 
278  std::vector<address> client_network_config::get_addresses() const {
279  return address_list_;
280  }
281 
282  client_network_config &client_network_config::add_addresses(const std::vector<address> &addresses) {
283  address_list_.insert(address_list_.end(), addresses.begin(), addresses.end());
284  return *this;
285  }
286 
287  client_network_config &client_network_config::set_addresses(const std::vector<address> &addresses) {
288  address_list_ = addresses;
289  return *this;
290  }
291 
293  address_list_.push_back(address);
294  return *this;
295  }
296 
297  socket_options &client_network_config::get_socket_options() {
298  return socket_options_;
299  }
300 
301  client_network_config &client_network_config::set_connection_timeout(const std::chrono::milliseconds &timeout) {
302  connection_timeout_ = timeout;
303  return *this;
304  }
305 
307  return use_public_address_;
308  }
309 
311  use_public_address_ = should_use_public_address;
312  return *this;
313  }
314 
315  client_connection_strategy_config::client_connection_strategy_config() : async_start_(false), reconnect_mode_(ON) {
316  }
317 
319  return reconnect_mode_;
320  }
321 
323  return async_start_;
324  }
325 
327  this->async_start_ = async_start;
328  return *this;
329  }
330 
333  this->reconnect_mode_ = reconnect_mode;
334  return *this;
335  }
336 
338  return retry_config_;
339  }
340 
343  retry_config_ = std::move(retry_config);
344  return *this;
345  }
346 
347  constexpr int reliable_topic_config::DEFAULT_READ_BATCH_SIZE;
348 
349  reliable_topic_config::reliable_topic_config() = default;
350 
351  reliable_topic_config::reliable_topic_config(std::string topic_name) : read_batch_size_(DEFAULT_READ_BATCH_SIZE),
352 
353  name_(std::move(topic_name)) {
354  }
355 
356  const std::string &reliable_topic_config::get_name() const {
357  return name_;
358  }
359 
361  return read_batch_size_;
362  }
363 
365  if (batch_size <= 0) {
366  BOOST_THROW_EXCEPTION(exception::illegal_argument("ReliableTopicConfig::setReadBatchSize",
367  "readBatchSize should be positive"));
368  }
369 
370  this->read_batch_size_ = batch_size;
371 
372  return *this;
373  }
374 
375  socket_options::socket_options() : tcp_no_delay_(true), keep_alive_(true), reuse_address_(true), linger_seconds_(3),
376  buffer_size_(DEFAULT_BUFFER_SIZE_BYTE) {}
377 
379  return tcp_no_delay_;
380  }
381 
383  socket_options::tcp_no_delay_ = tcp_no_delay;
384  return *this;
385  }
386 
388  return keep_alive_;
389  }
390 
392  socket_options::keep_alive_ = keep_alive;
393  return *this;
394  }
395 
397  return reuse_address_;
398  }
399 
401  socket_options::reuse_address_ = reuse_address;
402  return *this;
403  }
404 
406  return linger_seconds_;
407  }
408 
410  socket_options::linger_seconds_ = linger_seconds;
411  return *this;
412  }
413 
415  return buffer_size_;
416  }
417 
419  socket_options::buffer_size_ = buffer_size;
420  return *this;
421  }
422 
423  client_aws_config::client_aws_config() : enabled_(false), region_("us-east-1"), host_header_("ec2.amazonaws.com"),
424  inside_aws_(false) {
425  }
426 
427  const std::string &client_aws_config::get_access_key() const {
428  return access_key_;
429  }
430 
431  client_aws_config &client_aws_config::set_access_key(const std::string &access_key) {
432  this->access_key_ = util::Preconditions::check_has_text(access_key, "accessKey must contain text");
433  return *this;
434  }
435 
436  const std::string &client_aws_config::get_secret_key() const {
437  return secret_key_;
438  }
439 
440  client_aws_config &client_aws_config::set_secret_key(const std::string &secret_key) {
441  this->secret_key_ = util::Preconditions::check_has_text(secret_key, "secretKey must contain text");
442  return *this;
443  }
444 
445  const std::string &client_aws_config::get_region() const {
446  return region_;
447  }
448 
449  client_aws_config &client_aws_config::set_region(const std::string &region) {
450  this->region_ = util::Preconditions::check_has_text(region, "region must contain text");
451  return *this;
452  }
453 
454  const std::string &client_aws_config::get_host_header() const {
455  return host_header_;
456  }
457 
458  client_aws_config &client_aws_config::set_host_header(const std::string &host_header) {
459  this->host_header_ = util::Preconditions::check_has_text(host_header, "hostHeader must contain text");
460  return *this;
461  }
462 
464  util::Preconditions::check_ssl("get_aws_config");
465  this->enabled_ = enabled;
466  return *this;
467  }
468 
470  return enabled_;
471  }
472 
473  client_aws_config &client_aws_config::set_security_group_name(const std::string &security_group_name) {
474  this->security_group_name_ = security_group_name;
475  return *this;
476  }
477 
478  const std::string &client_aws_config::get_security_group_name() const {
479  return security_group_name_;
480  }
481 
482  client_aws_config &client_aws_config::set_tag_key(const std::string &tag_key) {
483  this->tag_key_ = tag_key;
484  return *this;
485  }
486 
487  const std::string &client_aws_config::get_tag_key() const {
488  return tag_key_;
489  }
490 
491  client_aws_config &client_aws_config::set_tag_value(const std::string &tag_value) {
492  this->tag_value_ = tag_value;
493  return *this;
494  }
495 
496  const std::string &client_aws_config::get_tag_value() const {
497  return tag_value_;
498  }
499 
500  const std::string &client_aws_config::get_iam_role() const {
501  return iam_role_;
502  }
503 
504  client_aws_config &client_aws_config::set_iam_role(const std::string &iam_role) {
505  this->iam_role_ = iam_role;
506  return *this;
507  }
508 
510  return inside_aws_;
511  }
512 
514  this->inside_aws_ = inside_aws;
515  return *this;
516  }
517 
518  std::ostream &operator<<(std::ostream &out, const client_aws_config &config) {
519  return out << "client_aws_config{"
520  << "enabled=" << config.is_enabled()
521  << ", region='" << config.get_region() << '\''
522  << ", securityGroupName='" << config.get_security_group_name() << '\''
523  << ", tagKey='" << config.get_tag_key() << '\''
524  << ", tagValue='" << config.get_tag_value() << '\''
525  << ", hostHeader='" << config.get_host_header() << '\''
526  << ", iamRole='" << config.get_iam_role() << "\'}";
527  }
528 
529  namespace matcher {
530  std::shared_ptr<std::string>
531  matching_point_config_pattern_matcher::matches(const std::vector<std::string> &config_patterns,
532  const std::string &item_name) const {
533  std::shared_ptr<std::string> candidate;
534  std::shared_ptr<std::string> duplicate;
535  int lastMatchingPoint = -1;
536  for (const std::string &pattern : config_patterns) {
537  int matchingPoint = get_matching_point(pattern, item_name);
538  if (matchingPoint > -1 && matchingPoint >= lastMatchingPoint) {
539  if (matchingPoint == lastMatchingPoint) {
540  duplicate = candidate;
541  } else {
542  duplicate.reset();
543  }
544  lastMatchingPoint = matchingPoint;
545  candidate.reset(new std::string(pattern));
546  }
547  }
548  if (duplicate.get() != NULL) {
550  "MatchingPointConfigPatternMatcher::matches") << "Configuration " << item_name
551  << " has duplicate configuration. Candidate:"
552  << *candidate << ", duplicate:"
553  << *duplicate).build();
554  }
555  return candidate;
556  }
557 
558  int matching_point_config_pattern_matcher::get_matching_point(const std::string &pattern,
559  const std::string &item_name) const {
560  size_t index = pattern.find('*');
561  if (index == std::string::npos) {
562  return -1;
563  }
564 
565  std::string firstPart = pattern.substr(0, index);
566  if (item_name.find(firstPart) != 0) {
567  return -1;
568  }
569 
570  std::string secondPart = pattern.substr(index + 1);
571  if (item_name.rfind(secondPart) != (item_name.length() - secondPart.length())) {
572  return -1;
573  }
574 
575  return (int) (firstPart.length() + secondPart.length());
576  }
577  }
578 
579  const std::string index_config::bitmap_index_options::DEFAULT_KEY = query::query_constants::KEY_ATTRIBUTE_NAME;
580  const index_config::bitmap_index_options::unique_key_transformation index_config::bitmap_index_options::DEFAULT_TRANSFORMATION = index_config::bitmap_index_options::unique_key_transformation::OBJECT;
581 
583  transformation(DEFAULT_TRANSFORMATION) {}
584 
585  const index_config::index_type index_config::DEFAULT_TYPE = index_config::index_type::SORTED;
586 
587  index_config::index_config() : type(DEFAULT_TYPE) {}
588 
589  index_config::index_config(index_config::index_type type) : type(type) {}
590 
591  void index_config::add_attributes() {}
592 
593  eviction_config::eviction_config() : size_(DEFAULT_MAX_ENTRY_COUNT), max_size_policy_(DEFAULT_MAX_SIZE_POLICY),
594  eviction_policy_(DEFAULT_EVICTION_POLICY) {}
595 
596  int32_t eviction_config::get_size() const {
597  return size_;
598  }
599 
600  eviction_config &eviction_config::set_size(int32_t size) {
601  this->size_ = util::Preconditions::check_positive(size, "Size must be positive number!");
602  return *this;
603  }
604 
605  eviction_config::max_size_policy eviction_config::get_maximum_size_policy() const {
606  return max_size_policy_;
607  }
608 
609  eviction_config &eviction_config::set_maximum_size_policy(const eviction_config::max_size_policy &max_size_policy) {
610  this->max_size_policy_ = max_size_policy;
611  return *this;
612  }
613 
614  eviction_policy eviction_config::get_eviction_policy() const {
615  return eviction_policy_;
616  }
617 
618  eviction_config &eviction_config::set_eviction_policy(eviction_policy policy) {
619  this->eviction_policy_ = policy;
620  return *this;
621  }
622 
623  eviction_strategy_type eviction_config::get_eviction_strategy_type() const {
624  // TODO: add support for other/custom eviction strategies
625  return eviction_strategy_type::DEFAULT_EVICTION_STRATEGY;
626  }
627 
628  std::ostream &operator<<(std::ostream &out, const eviction_config &config) {
629  out << "EvictionConfig{"
630  << "size=" << config.get_size()
631  << ", maxSizePolicy=" << config.get_maximum_size_policy()
632  << ", evictionPolicy=" << config.get_eviction_policy()
633  << '}';
634 
635  return out;
636  }
637 
638  near_cache_config::near_cache_config() : name_("default"), time_to_live_seconds_(DEFAULT_TTL_SECONDS),
639  max_idle_seconds_(DEFAULT_MAX_IDLE_SECONDS),
640  in_memory_format_(DEFAULT_MEMORY_FORMAT),
641  local_update_policy_(INVALIDATE), invalidate_on_change_(true),
642  cache_local_entries_(false) {
643  }
644 
645  near_cache_config::near_cache_config(const std::string &cache_name) : near_cache_config() {
646  name_ = cache_name;
647  }
648 
649  near_cache_config::near_cache_config(const std::string &cache_name, in_memory_format memory_format)
650  : near_cache_config(name_) {
651  this->in_memory_format_ = memory_format;
652  }
653 
654  near_cache_config::near_cache_config(int32_t time_to_live_seconds, int32_t max_idle_seconds, bool invalidate_on_change,
655  in_memory_format in_memory_format, const eviction_config &evict_config)
656  : near_cache_config(name_, in_memory_format) {
657  this->time_to_live_seconds_ = time_to_live_seconds;
658  this->max_idle_seconds_ = max_idle_seconds;
659  this->invalidate_on_change_ = invalidate_on_change;
660  this->eviction_config_ = evict_config;
661  }
662 
663  const std::string &near_cache_config::get_name() const {
664  return name_;
665  }
666 
667  near_cache_config &near_cache_config::set_name(const std::string &name) {
668  this->name_ = name;
669  return *this;
670  }
671 
673  return time_to_live_seconds_;
674  }
675 
677  this->time_to_live_seconds_ = util::Preconditions::check_not_negative(time_to_live_seconds,
678  "TTL seconds cannot be negative!");
679  return *this;
680  }
681 
683  return max_idle_seconds_;
684  }
685 
687  this->max_idle_seconds_ = util::Preconditions::check_not_negative(max_idle_seconds,
688  "Max-Idle seconds cannot be negative!");
689  return *this;
690  }
691 
693  return invalidate_on_change_;
694  }
695 
697  this->invalidate_on_change_ = invalidate_on_change;
698  return *this;
699  }
700 
701  const in_memory_format &near_cache_config::get_in_memory_format() const {
702  return in_memory_format_;
703  }
704 
705  near_cache_config &near_cache_config::set_in_memory_format(const in_memory_format &in_memory_format) {
706  this->in_memory_format_ = in_memory_format;
707  return *this;
708  }
709 
711  return cache_local_entries_;
712  }
713 
715  this->cache_local_entries_ = cache_local_entries;
716  return *this;
717  }
718 
719  const near_cache_config::local_update_policy &near_cache_config::get_local_update_policy() const {
720  return local_update_policy_;
721  }
722 
723  near_cache_config &near_cache_config::set_local_update_policy(const local_update_policy &local_update_policy) {
724  this->local_update_policy_ = local_update_policy;
725  return *this;
726  }
727 
729  return eviction_config_;
730  }
731 
733  this->eviction_config_ = eviction_config;
734  return *this;
735  }
736 
737  int32_t near_cache_config::calculate_max_size(int32_t max_size) {
738  return (max_size == 0) ? INT32_MAX : util::Preconditions::check_not_negative(max_size,
739  "Max-size cannot be negative!");
740  }
741 
742  std::ostream &operator<<(std::ostream &out, const near_cache_config &config) {
743  out << "NearCacheConfig{"
744  << "timeToLiveSeconds=" << config.time_to_live_seconds_
745  << ", maxIdleSeconds=" << config.max_idle_seconds_
746  << ", invalidateOnChange=" << config.invalidate_on_change_
747  << ", inMemoryFormat=" << config.in_memory_format_
748  << ", cacheLocalEntries=" << config.cache_local_entries_
749  << ", localUpdatePolicy=" << config.local_update_policy_
750  << config.eviction_config_;
751  out << '}';
752 
753  return out;
754  }
755  }
756 
757  client_config::client_config() : cluster_name_("dev"), redo_operation_(false),
758  socket_interceptor_(), executor_pool_size_(-1) {}
759 
761 
762  client_config &client_config::operator=(client_config &&rhs) = default;
763 
765  this->redo_operation_ = redo_operation;
766  return *this;
767  }
768 
770  return redo_operation_;
771  }
772 
774  if (!load_balancer_) {
775  auto index = std::make_shared<std::atomic<size_t>>(0);
776  load_balancer_ = load_balancer().next([=](cluster &c) {
777  auto members = c.get_members();
778  if (members.empty()) {
779  return boost::optional<member>();
780  }
781  auto i = index->fetch_add(1);
782  return boost::make_optional(std::move(members[i % members.size()]));
783  });
784  }
785  return *load_balancer_;
786  }
787 
789  this->load_balancer_ = std::move(load_balancer);
790  return *this;
791  }
792 
794  return logger_config_;
795  }
796 
798  lifecycle_listeners_.emplace_back(std::move(listener));
799  return *this;
800  }
801 
803  membership_listeners_.emplace_back(std::move(listener));
804  return *this;
805  }
806 
807  const std::vector<lifecycle_listener> &client_config::get_lifecycle_listeners() const {
808  return lifecycle_listeners_;
809  }
810 
811  const std::vector<membership_listener> &client_config::get_membership_listeners() const {
812  return membership_listeners_;
813  }
814 
816  this->socket_interceptor_ = std::move(interceptor);
817  return *this;
818  }
819 
821  return socket_interceptor_;
822  }
823 
825  return serialization_config_;
826  }
827 
829  this->serialization_config_ = serialization_config;
830  return *this;
831  }
832 
833  const std::unordered_map<std::string, std::string> &client_config::get_properties() const {
834  return properties_;
835  }
836 
837  client_config &client_config::set_property(const std::string &name, const std::string &value) {
838  properties_[name] = value;
839  return *this;
840  }
841 
843  reliable_topic_config_map_[reliable_topic_config.get_name()] = reliable_topic_config;
844  return *this;
845  }
846 
848  auto it = reliable_topic_config_map_.find(name);
849  if (it != reliable_topic_config_map_.end()) {
850  return it->second;
851  }
852 
853  return reliable_topic_config_map_.emplace(name, config::reliable_topic_config{name}).first->second;
854  }
855 
856  const config::reliable_topic_config *client_config::lookup_reliable_topic_config(const std::string &name) const {
857  auto it = reliable_topic_config_map_.find(name);
858  if (it != reliable_topic_config_map_.end()) {
859  return &it->second;
860  }
861 
862  return nullptr;
863  }
864 
866  return network_config_;
867  }
868 
870  near_cache_config_map_.emplace(near_cache_config.get_name(), near_cache_config);
871  return *this;
872  }
873 
874  const config::near_cache_config *client_config::get_near_cache_config(const std::string &name) const {
875  auto nearCacheConfig = internal::config::ConfigUtils::lookup_by_pattern(
876  config_pattern_matcher_, near_cache_config_map_, name);
877  if (nearCacheConfig) {
878  return nearCacheConfig;
879  }
880 
881  auto config_it = near_cache_config_map_.find("default");
882  if (config_it != near_cache_config_map_.end()) {
883  return &near_cache_config_map_.find("default")->second;
884  }
885 
886  // not needed for c++ client since it is always native memory
887  //initDefaultMaxSizeForOnHeapMaps(nearCacheConfig);
888  return nullptr;
889  }
890 
892  this->network_config_ = network_config;
893  return *this;
894  }
895 
896  const boost::optional<std::string> &client_config::get_instance_name() const {
897  return instance_name_;
898  }
899 
900  client_config &client_config::set_instance_name(const std::string &instance_name) {
901  client_config::instance_name_ = instance_name;
902  return *this;
903  }
904 
906  return executor_pool_size_;
907  }
908 
909  void client_config::set_executor_pool_size(int32_t executor_pool_size) {
910  client_config::executor_pool_size_ = executor_pool_size;
911  }
912 
913  config::client_connection_strategy_config &client_config::get_connection_strategy_config() {
914  return connection_strategy_config_;
915  }
916 
917  client_config &client_config::set_connection_strategy_config(
918  const config::client_connection_strategy_config &connection_strategy_config) {
919  client_config::connection_strategy_config_ = connection_strategy_config;
920  return *this;
921  }
922 
923  const config::client_flake_id_generator_config *
925  std::string baseName = internal::partition::strategy::StringPartitioningStrategy::get_base_name(name);
926  auto config = internal::config::ConfigUtils::lookup_by_pattern<config::client_flake_id_generator_config>(
927  config_pattern_matcher_, flake_id_generator_config_map_, baseName);
928  if (config) {
929  return config;
930  }
931  return get_flake_id_generator_config("default");
932  }
933 
934 
937  std::string baseName = internal::partition::strategy::StringPartitioningStrategy::get_base_name(name);
938  auto config = internal::config::ConfigUtils::lookup_by_pattern<config::client_flake_id_generator_config>(
939  config_pattern_matcher_, flake_id_generator_config_map_, baseName);
940  if (config) {
941  return config;
942  }
943  auto defConfig = flake_id_generator_config_map_.find("default");
944  if (defConfig == flake_id_generator_config_map_.end()) {
945  flake_id_generator_config_map_.emplace("default", config::client_flake_id_generator_config("default"));
946  }
947  defConfig = flake_id_generator_config_map_.find("default");
948  config::client_flake_id_generator_config new_config = defConfig->second;
949  new_config.set_name(name);
950  flake_id_generator_config_map_.emplace(name, std::move(new_config));
951  return &flake_id_generator_config_map_.find(name)->second;
952  }
953 
954  client_config &
956  flake_id_generator_config_map_.emplace(config.get_name(), config);
957  return *this;
958  }
959 
960  const std::string &client_config::get_cluster_name() const {
961  return cluster_name_;
962  }
963 
964  client_config &client_config::set_cluster_name(const std::string &cluster_name) {
965  cluster_name_ = cluster_name;
966  return *this;
967  }
968 
969  const std::unordered_set<std::string> &client_config::get_labels() const {
970  return labels_;
971  }
972 
973  client_config &client_config::set_labels(const std::unordered_set<std::string> &labels) {
974  labels_ = labels;
975  return *this;
976  }
977 
978  client_config &client_config::add_label(const std::string &label) {
979  labels_.insert(label);
980  return *this;
981  }
982 
984  backup_acks_enabled_ = enabled;
985  return *this;
986  }
987 
989  return backup_acks_enabled_;
990  }
991 
992  const std::shared_ptr<security::credentials> &client_config::get_credentials() const {
993  return credentials_;
994  }
995 
996  client_config &client_config::set_credentials(const std::shared_ptr<security::credentials> &credential) {
997  credentials_ = credential;
998  return *this;
999  }
1000 
1001  namespace security {
1002  username_password_credentials::username_password_credentials(const std::string &name,
1003  const std::string &password) : credentials(name),
1004  password_(password) {}
1005 
1006  const std::string &username_password_credentials::password() const {
1007  return password_;
1008  }
1009 
1010  const credentials::credential_type username_password_credentials::type() const {
1011  return credentials::credential_type::username_password;
1012  }
1013 
1014  const std::vector<byte> &token_credentials::token() const {
1015  return token_;
1016  }
1017 
1018  const credentials::credential_type token_credentials::type() const {
1019  return credentials::credential_type::token;
1020  }
1021 
1022  token_credentials::token_credentials(const std::vector<byte> &token) : credentials(
1023  token.empty() ? "<empty>" : "<token>"), token_(token) {}
1024 
1025  credentials::~credentials() {}
1026 
1027  const std::string &credentials::name() const {
1028  return name_;
1029  }
1030 
1031  credentials::credentials(const std::string &name) : name_(name) {}
1032  }
1033  }
1034 }
Represents an address of a client or member in the cluster.
Definition: address.h:36
hazelcast_client configuration class.
client_config & set_serialization_config(serialization_config const &serialization_config)
SerializationConfig is used to.
Definition: config.cpp:828
serialization_config & get_serialization_config()
Definition: config.cpp:824
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:847
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:815
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:764
void set_executor_pool_size(int32_t executor_pool_size)
Sets Client side Executor pool size.
Definition: config.cpp:909
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:874
client_config & add_listener(lifecycle_listener &&listener)
Adds a listener to configuration to be registered when hazelcast_client starts.
Definition: config.cpp:797
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:996
const std::unordered_map< std::string, std::string > & get_properties() const
Gets a reference to properties map.
Definition: config.cpp:833
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:820
client_config()
Constructor with default values.
Definition: config.cpp:757
config::client_network_config & get_network_config()
Gets {}.
Definition: config.cpp:865
int32_t get_executor_pool_size() const
Pool size for internal ExecutorService which handles responses etc.
Definition: config.cpp:905
client_config & add_reliable_topic_config(const config::reliable_topic_config &reliable_topic_config)
Adds a ClientReliableTopicConfig.
Definition: config.cpp:842
bool is_redo_operation() const
see setRedoOperation returns redoOperation
Definition: config.cpp:769
const std::vector< membership_listener > & get_membership_listeners() const
Returns registered membershipListeners.
Definition: config.cpp:811
client_config & add_flake_id_generator_config(const config::client_flake_id_generator_config &config)
Adds a flake ID generator configuration.
Definition: config.cpp:955
const std::string & get_cluster_name() const
Returns the configured cluster name.
Definition: config.cpp:960
config::logger_config & get_logger_config()
Definition: config.cpp:793
bool backup_acks_enabled()
Note that backup acks to client can be enabled only for smart client.
Definition: config.cpp:988
client_config & set_load_balancer(load_balancer &&load_balancer)
Used to distribute the operations to multiple connections.
Definition: config.cpp:788
load_balancer & get_load_balancer()
Used to distribute the operations to multiple Endpoints.
Definition: config.cpp:773
client_config & set_network_config(const config::client_network_config &network_config)
Sets {}.
Definition: config.cpp:891
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:936
client_config & add_near_cache_config(const config::near_cache_config &near_cache_config)
Helper method to add a new NearCacheConfig.
Definition: config.cpp:869
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:924
client_config & set_property(const std::string &name, const std::string &value)
Sets the value of a named property.
Definition: config.cpp:837
const std::vector< lifecycle_listener > & get_lifecycle_listeners() const
Definition: config.cpp:807
Hazelcast cluster interface.
Definition: cluster.h:36
std::vector< member > get_members()
Set of current members of the cluster.
Definition: cluster.cpp:38
The client_aws_config contains the configuration for client to connect to nodes in aws environment.
const std::string & get_access_key() const
Gets the access key to access AWS.
Definition: config.cpp:427
const std::string & get_tag_key() const
Gets the tag key.
Definition: config.cpp:487
const std::string & get_security_group_name() const
Gets the security group name.
Definition: config.cpp:478
const std::string & get_region() const
Gets the region where the EC2 instances running the Hazelcast members will be running.
Definition: config.cpp:445
const std::string & get_host_header() const
Gets the host header; the address where the EC2 API can be found.
Definition: config.cpp:454
client_aws_config & set_secret_key(const std::string &secret_key)
Sets the secret key to access AWS.
Definition: config.cpp:440
client_aws_config & set_host_header(const std::string &host_header)
Sets the host header; the address where the EC2 API can be found.
Definition: config.cpp:458
client_aws_config & set_tag_key(const std::string &tag_key)
Sets the tag key.
Definition: config.cpp:482
client_aws_config & set_iam_role(const std::string &iam_role)
Sets the tag value.
Definition: config.cpp:504
client_aws_config & set_inside_aws(bool inside_aws)
Set to true if client is inside aws environment Default value is false.
Definition: config.cpp:513
client_aws_config & set_region(const std::string &region)
Sets the region where the EC2 instances running the Hazelcast members will be running.
Definition: config.cpp:449
bool is_enabled() const
Checks if the aws join mechanism is enabled.
Definition: config.cpp:469
bool is_inside_aws() const
If client is inside aws, it will use private ip addresses directly, otherwise it will convert private...
Definition: config.cpp:509
const std::string & get_secret_key() const
Gets the secret key to access AWS.
Definition: config.cpp:436
client_aws_config & set_enabled(bool enabled)
Enables or disables the aws join mechanism.
Definition: config.cpp:463
const std::string & get_tag_value() const
Gets the tag value.
Definition: config.cpp:496
client_aws_config & set_access_key(const std::string &access_key)
Sets the access key to access AWS.
Definition: config.cpp:431
client_aws_config & set_tag_value(const std::string &tag_value)
Sets the tag value.
Definition: config.cpp:491
const std::string & get_iam_role() const
Gets the iamRole name.
Definition: config.cpp:500
client_aws_config & set_security_group_name(const std::string &security_group_name)
Sets the security group name.
Definition: config.cpp:473
Client connection strategy configuration is used for setting custom strategies and configuring strate...
client_connection_strategy_config & set_reconnect_mode(reconnect_mode reconnect_mode)
How a client reconnect to cluster after a disconnect can be configured.
Definition: config.cpp:332
client_connection_strategy_config & set_retry_config(connection_retry_config retry_config)
connection_retry_config controls the period among the retries and when a client should give up retryi...
Definition: config.cpp:342
client_connection_strategy_config & set_async_start(bool async_start)
Set true for non blocking hazelcast_client(const client_config &).
Definition: config.cpp:326
connection_retry_config & get_retry_config()
connection_retry_config controls the period among the retries and when a client should give up retryi...
Definition: config.cpp:337
bool is_async_start() const
Client instance creation won't block on hazelcast_client(ClientConfig &) if this value is true.
Definition: config.cpp:322
static constexpr int64_t DEFAULT_PREFETCH_VALIDITY_MILLIS
Default value for getPrefetchValidityMillis().
const std::string & get_name() const
Returns the configuration name.
Definition: config.cpp:146
client_flake_id_generator_config & set_name(const std::string &n)
Sets the name or name pattern for this config.
Definition: config.cpp:150
Contains configuration parameters for client network related behaviour.
client_network_config & set_addresses(const std::vector< address > &addresses)
Adds given addresses to candidate address list that client will use to establish initial connection.
Definition: config.cpp:287
bool is_smart_routing() const
See client_network_config::setSmartRouting(boolean) for details.
Definition: config.cpp:269
std::vector< address > get_addresses() const
Returns the list of candidate addresses that client will use to establish initial connection.
Definition: config.cpp:278
client_network_config & add_addresses(const std::vector< address > &addresses)
Adds given addresses to candidate address list that client will use to establish initial connection.
Definition: config.cpp:282
client_network_config & add_address(const address &address)
Adds given address to candidate address list that client will use to establish initial connection.
Definition: config.cpp:292
client_network_config & set_smart_routing(bool smart_routing)
If.
Definition: config.cpp:273
client_network_config & set_connection_timeout(const std::chrono::milliseconds &timeout)
Definition: config.cpp:301
client_aws_config & get_aws_config()
Returns the current client_aws_config.
Definition: config.cpp:261
ssl_config & get_ssl_config()
Returns the current \ssl_config .
Definition: config.cpp:243
std::chrono::milliseconds get_connection_timeout() const
Connection timeout value for connecting to a member server.
Definition: config.cpp:252
cloud_config & get_cloud_config()
Returns the current cloud_config.
Definition: config.cpp:265
client_network_config & set_aws_config(const client_aws_config &client_aws_config)
Sets configuration to connect nodes in aws environment.
Definition: config.cpp:256
client_network_config & set_ssl_config(const config::ssl_config &config)
Sets the ssl_config.
Definition: config.cpp:247
Connection Retry Config is controls the period among the retries and when should a client gave up ret...
std::shared_ptr< std::string > matches(const std::vector< std::string > &config_patterns, const std::string &item_name) const override
Returns the best match for an item name out of a list of configuration patterns.
Definition: config.cpp:531
Contains the configuration for a Near Cache.
near_cache_config & set_cache_local_entries(bool cache_local_entries)
True to cache local entries also.
Definition: config.cpp:714
virtual near_cache_config & set_in_memory_format(const in_memory_format &in_memory_format)
Sets the data type used to store entries.
Definition: config.cpp:705
near_cache_config & set_eviction_config(const eviction_config &eviction_config)
Sets the eviction configuration.
Definition: config.cpp:732
const in_memory_format & get_in_memory_format() const
Gets the data type used to store entries.
Definition: config.cpp:701
int32_t get_time_to_live_seconds() const
Gets the maximum number of seconds for each entry to stay in the Near Cache.
Definition: config.cpp:672
near_cache_config & set_time_to_live_seconds(int32_t time_to_live_seconds)
Sets the maximum number of seconds for each entry to stay in the Near Cache.
Definition: config.cpp:676
near_cache_config & set_invalidate_on_change(bool invalidate_on_change)
True to evict the cached entries if the entries are changed (updated or removed).
Definition: config.cpp:696
const std::string & get_name() const
Gets the name of the Near Cache.
Definition: config.cpp:663
eviction_config & get_eviction_config()
The eviction configuration.
Definition: config.cpp:728
bool is_cache_local_entries() const
If true, cache local entries also.
Definition: config.cpp:710
bool is_invalidate_on_change() const
True to evict the cached entries if the entries are changed (updated or removed).
Definition: config.cpp:692
near_cache_config & set_name(const std::string &name)
Sets the name of the Near Cache.
Definition: config.cpp:667
int32_t get_max_idle_seconds() const
Maximum number of seconds each entry can stay in the Near Cache as untouched (not-read).
Definition: config.cpp:682
near_cache_config & set_max_idle_seconds(int32_t max_idle_seconds)
Maximum number of seconds each entry can stay in the Near Cache as untouched (not-read).
Definition: config.cpp:686
const std::string & get_name() const
Gets the name of the reliable topic.
Definition: config.cpp:356
reliable_topic_config & set_read_batch_size(int batch_size)
Sets the read batch size.
Definition: config.cpp:364
int get_read_batch_size() const
Gets the maximum number of items to read in a batch.
Definition: config.cpp:360
socket_options & set_tcp_no_delay(bool tcp_no_delay)
Enable/disable TCP_NODELAY socket option.
Definition: config.cpp:382
socket_options & set_reuse_address(bool reuse_address)
Enable/disable the SO_REUSEADDR socket option.
Definition: config.cpp:400
socket_options & set_linger_seconds(int linger_seconds)
Enable/disable SO_LINGER with the specified linger time in seconds.
Definition: config.cpp:409
bool is_keep_alive() const
SO_KEEPALIVE socket option.
Definition: config.cpp:387
socket_options & set_keep_alive(bool keep_alive)
Enable/disable SO_KEEPALIVE socket option.
Definition: config.cpp:391
bool is_reuse_address() const
SO_REUSEADDR socket option.
Definition: config.cpp:396
bool is_tcp_no_delay() const
TCP_NODELAY socket option.
Definition: config.cpp:378
int get_buffer_size_in_bytes() const
If set to 0 or less, then it is not set on the socket.
Definition: config.cpp:414
socket_options & set_buffer_size_in_bytes(int buffer_size)
If set to 0 or less, then it is not set on the socket.
Definition: config.cpp:418
int get_linger_seconds() const
Gets SO_LINGER with the specified linger time in seconds.
Definition: config.cpp:405
Contains configuration parameters for ssl related behaviour.
Definition: ssl_config.h:61
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:37
load_balancer & next(Handler &&h) &
The function returns the next member to route to.
Definition: load_balancer.h:66
SerializationConfig is used to.
serialization_config & set_portable_version(int v)
Definition: config.cpp:49
serialization_config & set_global_serializer(const std::shared_ptr< serialization::global_serializer > &global_serializer)
Definition: config.cpp:58
serialization_config & set_byte_order(boost::endian::order byte_order)
Definition: config.cpp:64
int get_portable_version() const
Portable version will be used to differentiate two same class that have changes on it ,...
Definition: config.cpp:45
serialization_config()
Constructor default value of version is zero.
Definition: config.cpp:42
boost::endian::order get_byte_order() const
Definition: config.cpp:69
An interface that provides the ability to intercept the creation of sockets.
hazelcast.cloud configuration to let the client connect the cluster via hazelcast....
Definition: cloud_config.h:31
bitmap_index_options()
Constructs a new bitmap index options instance with all options set to default values.
Definition: config.cpp:582
static const unique_key_transformation DEFAULT_TRANSFORMATION
The default for \transformation.
Definition: index_config.h:76
static const std::string DEFAULT_KEY
The default for \key.
Definition: index_config.h:71
index_type type
Type of the index.
Definition: index_config.h:100