Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
config.cpp
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#include <atomic>
17
18#include "hazelcast/client/client_config.h"
19#include "hazelcast/client/serialization_config.h"
20#include "hazelcast/client/config/ssl_config.h"
21#include "hazelcast/util/Preconditions.h"
22#include "hazelcast/client/config/client_flake_id_generator_config.h"
23#include "hazelcast/client/exception/protocol_exceptions.h"
24#include "hazelcast/client/internal/partition/strategy/StringPartitioningStrategy.h"
25#include "hazelcast/client/address.h"
26#include "hazelcast/client/config/client_network_config.h"
27#include "hazelcast/client/config/client_aws_config.h"
28#include "hazelcast/client/config/reliable_topic_config.h"
29#include "hazelcast/client/config/client_connection_strategy_config.h"
30#include "hazelcast/client/config/logger_config.h"
31#include "hazelcast/client/config/index_config.h"
32#include "hazelcast/client/config/matcher/matching_point_config_pattern_matcher.h"
33#include "hazelcast/client/query/predicates.h"
34#include "hazelcast/client/lifecycle_listener.h"
35#include "hazelcast/client/config/eviction_strategy_type.h"
36#include "hazelcast/client/cluster.h"
37#include "hazelcast/client/initial_membership_event.h"
38
39namespace hazelcast {
40namespace client {
44
45int
47{
48 return version_;
49}
50
53{
54 this->version_ = v;
55 return *this;
56}
57
58std::shared_ptr<serialization::global_serializer>
59serialization_config::get_global_serializer() const
60{
61 return global_serializer_;
62}
63
64serialization_config&
66 const std::shared_ptr<serialization::global_serializer>& global_serializer)
67{
68 global_serializer_ = global_serializer;
69 return *this;
70}
71
73serialization_config::set_byte_order(boost::endian::order byte_order)
74{
75 byte_order_ = byte_order;
76 return *this;
77}
78
79boost::endian::order
81{
82 return byte_order_;
83}
84
85namespace config {
86ssl_config::ssl_config()
87#ifdef HZ_BUILD_WITH_SSL
88 : enabled_(false)
89 , ssl_protocol_(tlsv12)
90#endif
91{}
92
93#ifdef HZ_BUILD_WITH_SSL
94ssl_config&
95ssl_config::set_context(boost::asio::ssl::context ctx)
96{
97 util::Preconditions::check_ssl("ssl_config::set_context");
98 if (enabled_) {
99 throw exception::illegal_argument(
100 "You should either use the deprecated methods or this method to "
101 "enable ssl. You already used the deprecated way.");
102 }
103 ssl_context_ = std::make_shared<boost::asio::ssl::context>(std::move(ctx));
104 return *this;
105}
106
107bool
108ssl_config::is_enabled() const
109{
110 return ssl_context_ || enabled_;
111}
112
114ssl_config::set_enabled(bool is_enabled)
115{
116 util::Preconditions::check_ssl("ssl_config::set_enabled");
117 check_context_enabled_already();
118 this->enabled_ = is_enabled;
119 return *this;
120}
121
122void
123ssl_config::check_context_enabled_already() const
124{
125 if (ssl_context_) {
126 throw exception::illegal_argument(
127 "You should either use set_context or this method.");
128 }
129}
130
132ssl_config::set_protocol(ssl_protocol protocol)
133{
134 check_context_enabled_already();
135 this->ssl_protocol_ = protocol;
136 return *this;
137}
138
139ssl_protocol
140ssl_config::get_protocol() const
141{
142 check_context_enabled_already();
143 return ssl_protocol_;
144}
145
146const std::vector<std::string>&
147ssl_config::get_verify_files() const
148{
149 check_context_enabled_already();
150 return client_verify_files_;
151}
152
154ssl_config::add_verify_file(const std::string& filename)
155{
156 check_context_enabled_already();
157 this->client_verify_files_.push_back(filename);
158 return *this;
159}
160
161const std::string&
162ssl_config::get_cipher_list() const
163{
164 return cipher_list_;
165}
166
168ssl_config::set_cipher_list(const std::string& ciphers)
169{
170 this->cipher_list_ = ciphers;
171 return *this;
172}
173#endif
174
175constexpr int64_t
177
178client_flake_id_generator_config::client_flake_id_generator_config(
179 const std::string& name)
180 : name_(name)
181 , prefetch_count_(client_flake_id_generator_config::DEFAULT_PREFETCH_COUNT)
182 , prefetch_validity_duration_(
183 client_flake_id_generator_config::DEFAULT_PREFETCH_VALIDITY_MILLIS)
184{}
185
186const std::string&
188{
189 return name_;
190}
191
194{
195 client_flake_id_generator_config::name_ = n;
196 return *this;
197}
198
199int32_t
201{
202 return prefetch_count_;
203}
204
207{
208 std::ostringstream out;
209 out << "prefetch-count must be 1.." << MAXIMUM_PREFETCH_COUNT << ", not "
210 << count;
211 util::Preconditions::check_true(
212 count > 0 && count <= MAXIMUM_PREFETCH_COUNT, out.str());
213 prefetch_count_ = count;
214 return *this;
215}
216
217std::chrono::milliseconds
219{
220 return prefetch_validity_duration_;
221}
222
225 std::chrono::milliseconds duration)
226{
227 util::Preconditions::check_not_negative(duration.count(),
228 "duration must be nonnegative");
229 prefetch_validity_duration_ = duration;
230 return *this;
231}
232
233constexpr std::chrono::milliseconds connection_retry_config::INITIAL_BACKOFF;
234constexpr std::chrono::milliseconds connection_retry_config::MAX_BACKOFF;
235constexpr std::chrono::milliseconds
236 connection_retry_config::CLUSTER_CONNECT_TIMEOUT;
237constexpr double connection_retry_config::JITTER;
238
239std::chrono::milliseconds
241{
242 return initial_backoff_duration_;
243}
244
247 std::chrono::milliseconds initial_backoff_duration)
248{
249 util::Preconditions::check_not_negative(
250 initial_backoff_duration.count(),
251 "Initial backoff must be non-negative!");
252 initial_backoff_duration_ = initial_backoff_duration;
253 return *this;
254}
255
256std::chrono::milliseconds
258{
259 return max_backoff_duration_;
260}
261
264 std::chrono::milliseconds max_backoff_duration)
265{
266 util::Preconditions::check_not_negative(
267 max_backoff_duration.count(), "Max backoff must be non-negative!");
268 max_backoff_duration_ = max_backoff_duration;
269 return *this;
270}
271
272double
274{
275 return multiplier_;
276}
277
280{
281 util::Preconditions::check_true(
282 m >= 1.0, "Multiplier must be greater than or equal to 1.0!");
283 multiplier_ = m;
284 return *this;
285}
286
287std::chrono::milliseconds
289{
290 return cluster_connect_timeout_;
291}
292
295 std::chrono::milliseconds cluster_connect_timeout)
296{
297 util::Preconditions::check_not_negative(
298 cluster_connect_timeout.count(),
299 "Cluster connect timeout must be non-negative!");
300 cluster_connect_timeout_ = cluster_connect_timeout;
301 return *this;
302}
303
304double
306{
307 return jitter_;
308}
309
312{
313 util::Preconditions::check_true(jitter >= 0.0 && jitter <= 1.0,
314 "Jitter must be in range [0.0, 1.0]");
315 jitter_ = jitter;
316 return *this;
317}
318
320 : connection_timeout_(5000)
321 , smart_routing_(true)
322{}
323
326{
327 return ssl_config_;
328}
329
332{
333 ssl_config_ = config;
334 return *this;
335}
336
337std::chrono::milliseconds
339{
340 return connection_timeout_;
341}
342
346{
347 this->client_aws_config_ = client_aws_config;
348 return *this;
349}
350
353{
354 return client_aws_config_;
355}
356
359{
360 return cloud_config_;
361}
362
363bool
365{
366 return smart_routing_;
367}
368
371{
372 client_network_config::smart_routing_ = smart_routing;
373 return *this;
374}
375
376std::vector<address>
378{
379 return address_list_;
380}
381
383client_network_config::add_addresses(const std::vector<address>& addresses)
384{
385 address_list_.insert(
386 address_list_.end(), addresses.begin(), addresses.end());
387 return *this;
388}
389
391client_network_config::set_addresses(const std::vector<address>& addresses)
392{
393 address_list_ = addresses;
394 return *this;
395}
396
399{
400 address_list_.push_back(address);
401 return *this;
402}
403
405client_network_config::get_socket_options()
406{
407 return socket_options_;
408}
409
410client_network_config&
412 const std::chrono::milliseconds& timeout)
413{
414 connection_timeout_ = timeout;
415 return *this;
416}
417
418bool
420{
421 return use_public_address_;
422}
423
425client_network_config::use_public_address(bool should_use_public_address)
426{
427 use_public_address_ = should_use_public_address;
428 return *this;
429}
430
431client_connection_strategy_config::client_connection_strategy_config()
432 : async_start_(false)
433 , reconnect_mode_(ON)
434{}
435
438{
439 return reconnect_mode_;
440}
441
442bool
444{
445 return async_start_;
446}
447
450{
451 this->async_start_ = async_start;
452 return *this;
453}
454
458{
459 this->reconnect_mode_ = reconnect_mode;
460 return *this;
461}
462
465{
466 return retry_config_;
467}
468
471 connection_retry_config retry_config)
472{
473 retry_config_ = std::move(retry_config);
474 return *this;
475}
476
477constexpr int reliable_topic_config::DEFAULT_READ_BATCH_SIZE;
478
479reliable_topic_config::reliable_topic_config() = default;
480
481reliable_topic_config::reliable_topic_config(std::string topic_name)
482 : read_batch_size_(DEFAULT_READ_BATCH_SIZE)
483 ,
484
485 name_(std::move(topic_name))
486{}
487
488const std::string&
490{
491 return name_;
492}
493
494int
496{
497 return read_batch_size_;
498}
499
502{
503 if (batch_size <= 0) {
504 BOOST_THROW_EXCEPTION(
505 exception::illegal_argument("ReliableTopicConfig::setReadBatchSize",
506 "readBatchSize should be positive"));
507 }
508
509 this->read_batch_size_ = batch_size;
510
511 return *this;
512}
513
514socket_options::socket_options()
515 : tcp_no_delay_(true)
516 , keep_alive_(true)
517 , reuse_address_(true)
518 , linger_seconds_(3)
519 , buffer_size_(DEFAULT_BUFFER_SIZE_BYTE)
520{}
521
522bool
524{
525 return tcp_no_delay_;
526}
527
530{
531 socket_options::tcp_no_delay_ = tcp_no_delay;
532 return *this;
533}
534
535bool
537{
538 return keep_alive_;
539}
540
543{
544 socket_options::keep_alive_ = keep_alive;
545 return *this;
546}
547
548bool
550{
551 return reuse_address_;
552}
553
556{
557 socket_options::reuse_address_ = reuse_address;
558 return *this;
559}
560
561int
563{
564 return linger_seconds_;
565}
566
569{
570 socket_options::linger_seconds_ = linger_seconds;
571 return *this;
572}
573
574int
576{
577 return buffer_size_;
578}
579
582{
583 socket_options::buffer_size_ = buffer_size;
584 return *this;
585}
586
587client_aws_config::client_aws_config()
588 : enabled_(false)
589 , region_("us-east-1")
590 , host_header_("ec2.amazonaws.com")
591 , inside_aws_(false)
592{}
593
594const std::string&
596{
597 return access_key_;
598}
599
601client_aws_config::set_access_key(const std::string& access_key)
602{
603 this->access_key_ = util::Preconditions::check_has_text(
604 access_key, "accessKey must contain text");
605 return *this;
606}
607
608const std::string&
610{
611 return secret_key_;
612}
613
615client_aws_config::set_secret_key(const std::string& secret_key)
616{
617 this->secret_key_ = util::Preconditions::check_has_text(
618 secret_key, "secretKey must contain text");
619 return *this;
620}
621
622const std::string&
624{
625 return region_;
626}
627
629client_aws_config::set_region(const std::string& region)
630{
631 this->region_ =
632 util::Preconditions::check_has_text(region, "region must contain text");
633 return *this;
634}
635
636const std::string&
638{
639 return host_header_;
640}
641
643client_aws_config::set_host_header(const std::string& host_header)
644{
645 this->host_header_ = util::Preconditions::check_has_text(
646 host_header, "hostHeader must contain text");
647 return *this;
648}
649
652{
653 util::Preconditions::check_ssl("get_aws_config");
654 this->enabled_ = enabled;
655 return *this;
656}
657
658bool
660{
661 return enabled_;
662}
663
666 const std::string& security_group_name)
667{
668 this->security_group_name_ = security_group_name;
669 return *this;
670}
671
672const std::string&
674{
675 return security_group_name_;
676}
677
679client_aws_config::set_tag_key(const std::string& tag_key)
680{
681 this->tag_key_ = tag_key;
682 return *this;
683}
684
685const std::string&
687{
688 return tag_key_;
689}
690
692client_aws_config::set_tag_value(const std::string& tag_value)
693{
694 this->tag_value_ = tag_value;
695 return *this;
696}
697
698const std::string&
700{
701 return tag_value_;
702}
703
704const std::string&
706{
707 return iam_role_;
708}
709
711client_aws_config::set_iam_role(const std::string& iam_role)
712{
713 this->iam_role_ = iam_role;
714 return *this;
715}
716
717bool
719{
720 return inside_aws_;
721}
722
725{
726 this->inside_aws_ = inside_aws;
727 return *this;
728}
729
730std::ostream&
731operator<<(std::ostream& out, const client_aws_config& config)
732{
733 return out << "client_aws_config{"
734 << "enabled=" << config.is_enabled() << ", region='"
735 << config.get_region() << '\'' << ", securityGroupName='"
736 << config.get_security_group_name() << '\'' << ", tagKey='"
737 << config.get_tag_key() << '\'' << ", tagValue='"
738 << config.get_tag_value() << '\'' << ", hostHeader='"
739 << config.get_host_header() << '\'' << ", iamRole='"
740 << config.get_iam_role() << "\'}";
741}
742
743namespace matcher {
744std::shared_ptr<std::string>
746 const std::vector<std::string>& config_patterns,
747 const std::string& item_name) const
748{
749 std::shared_ptr<std::string> candidate;
750 std::shared_ptr<std::string> duplicate;
751 int lastMatchingPoint = -1;
752 for (const std::string& pattern : config_patterns) {
753 int matchingPoint = get_matching_point(pattern, item_name);
754 if (matchingPoint > -1 && matchingPoint >= lastMatchingPoint) {
755 if (matchingPoint == lastMatchingPoint) {
756 duplicate = candidate;
757 } else {
758 duplicate.reset();
759 }
760 lastMatchingPoint = matchingPoint;
761 candidate.reset(new std::string(pattern));
762 }
763 }
764 if (duplicate.get() != NULL) {
766 "MatchingPointConfigPatternMatcher::matches")
767 << "Configuration " << item_name
768 << " has duplicate configuration. Candidate:" << *candidate
769 << ", duplicate:" << *duplicate)
770 .build();
771 }
772 return candidate;
773}
774
775int
776matching_point_config_pattern_matcher::get_matching_point(
777 const std::string& pattern,
778 const std::string& item_name) const
779{
780 size_t index = pattern.find('*');
781 if (index == std::string::npos) {
782 return -1;
783 }
784
785 std::string firstPart = pattern.substr(0, index);
786 if (item_name.find(firstPart) != 0) {
787 return -1;
788 }
789
790 std::string secondPart = pattern.substr(index + 1);
791 if (item_name.rfind(secondPart) !=
792 (item_name.length() - secondPart.length())) {
793 return -1;
794 }
795
796 return (int)(firstPart.length() + secondPart.length());
797}
798} // namespace matcher
799
801 query::query_constants::KEY_ATTRIBUTE_NAME;
805
810
811const index_config::index_type index_config::DEFAULT_TYPE =
813
817
818void
819index_config::add_attributes()
820{}
821
822eviction_config::eviction_config()
823 : size_(DEFAULT_MAX_ENTRY_COUNT)
824 , max_size_policy_(DEFAULT_MAX_SIZE_POLICY)
825 , eviction_policy_(DEFAULT_EVICTION_POLICY)
826{}
827
828int32_t
829eviction_config::get_size() const
830{
831 return size_;
832}
833
834eviction_config&
835eviction_config::set_size(int32_t size)
836{
837 this->size_ = util::Preconditions::check_positive(
838 size, "Size must be positive number!");
839 return *this;
840}
841
843eviction_config::get_maximum_size_policy() const
844{
845 return max_size_policy_;
846}
847
849eviction_config::set_maximum_size_policy(
850 const eviction_config::max_size_policy& max_size_policy)
851{
852 this->max_size_policy_ = max_size_policy;
853 return *this;
854}
855
856eviction_policy
857eviction_config::get_eviction_policy() const
858{
859 return eviction_policy_;
860}
861
863eviction_config::set_eviction_policy(eviction_policy policy)
864{
865 this->eviction_policy_ = policy;
866 return *this;
867}
868
869eviction_strategy_type
870eviction_config::get_eviction_strategy_type() const
871{
872 // TODO: add support for other/custom eviction strategies
873 return eviction_strategy_type::DEFAULT_EVICTION_STRATEGY;
874}
875
876std::ostream&
877operator<<(std::ostream& out, const eviction_config& config)
878{
879 out << "EvictionConfig{"
880 << "size=" << config.get_size()
881 << ", maxSizePolicy=" << config.get_maximum_size_policy()
882 << ", evictionPolicy=" << config.get_eviction_policy() << '}';
883
884 return out;
885}
886
887near_cache_config::near_cache_config()
888 : name_("default")
889 , time_to_live_seconds_(DEFAULT_TTL_SECONDS)
890 , max_idle_seconds_(DEFAULT_MAX_IDLE_SECONDS)
891 , in_memory_format_(DEFAULT_MEMORY_FORMAT)
892 , local_update_policy_(INVALIDATE)
893 , invalidate_on_change_(true)
894 , cache_local_entries_(false)
895{}
896
897near_cache_config::near_cache_config(const std::string& cache_name)
899{
900 name_ = cache_name;
901}
902
903near_cache_config::near_cache_config(const std::string& cache_name,
904 in_memory_format memory_format)
905 : near_cache_config(cache_name)
906{
907 this->in_memory_format_ = memory_format;
908}
909
910near_cache_config::near_cache_config(int32_t time_to_live_seconds,
911 int32_t max_idle_seconds,
912 bool invalidate_on_change,
913 in_memory_format in_memory_format,
914 const eviction_config& evict_config)
915 : near_cache_config(name_, in_memory_format)
916{
917 this->time_to_live_seconds_ = time_to_live_seconds;
918 this->max_idle_seconds_ = max_idle_seconds;
919 this->invalidate_on_change_ = invalidate_on_change;
920 this->eviction_config_ = evict_config;
921}
922
923const std::string&
925{
926 return name_;
927}
928
930near_cache_config::set_name(const std::string& name)
931{
932 this->name_ = name;
933 return *this;
934}
935
936int32_t
938{
939 return time_to_live_seconds_;
940}
941
944{
945 this->time_to_live_seconds_ = util::Preconditions::check_not_negative(
946 time_to_live_seconds, "TTL seconds cannot be negative!");
947 return *this;
948}
949
950int32_t
952{
953 return max_idle_seconds_;
954}
955
958{
959 this->max_idle_seconds_ = util::Preconditions::check_not_negative(
960 max_idle_seconds, "Max-Idle seconds cannot be negative!");
961 return *this;
962}
963
964bool
966{
967 return invalidate_on_change_;
968}
969
972{
973 this->invalidate_on_change_ = invalidate_on_change;
974 return *this;
975}
976
977const in_memory_format&
979{
980 return in_memory_format_;
981}
982
985 const in_memory_format& in_memory_format)
986{
987 this->in_memory_format_ = in_memory_format;
988 return *this;
989}
990
991bool
993{
994 return cache_local_entries_;
995}
996
999{
1000 this->cache_local_entries_ = cache_local_entries;
1001 return *this;
1002}
1003
1005near_cache_config::get_local_update_policy() const
1006{
1007 return local_update_policy_;
1008}
1009
1010near_cache_config&
1011near_cache_config::set_local_update_policy(
1012 const local_update_policy& local_update_policy)
1013{
1014 this->local_update_policy_ = local_update_policy;
1015 return *this;
1016}
1017
1018eviction_config&
1020{
1021 return eviction_config_;
1022}
1023
1026{
1027 this->eviction_config_ = eviction_config;
1028 return *this;
1029}
1030
1031std::ostream&
1032operator<<(std::ostream& out, const near_cache_config& config)
1033{
1034 out << "NearCacheConfig{"
1035 << "timeToLiveSeconds=" << config.time_to_live_seconds_
1036 << ", maxIdleSeconds=" << config.max_idle_seconds_
1037 << ", invalidateOnChange=" << config.invalidate_on_change_
1038 << ", inMemoryFormat=" << config.in_memory_format_
1039 << ", cacheLocalEntries=" << config.cache_local_entries_
1040 << ", localUpdatePolicy=" << config.local_update_policy_
1041 << config.eviction_config_;
1042 out << '}';
1043
1044 return out;
1045}
1046} // namespace config
1047
1049 : cluster_name_("dev")
1050 , redo_operation_(false)
1051 , socket_interceptor_()
1052 , executor_pool_size_(-1)
1053{}
1054
1056
1058client_config::operator=(client_config&& rhs) = default;
1059
1062{
1063 this->redo_operation_ = redo_operation;
1064 return *this;
1065}
1066
1067bool
1069{
1070 return redo_operation_;
1071}
1072
1075{
1076 if (!load_balancer_) {
1077 auto index = std::make_shared<std::atomic<size_t>>(0);
1078 load_balancer_ = load_balancer().next([=](cluster& c) {
1079 auto members = c.get_members();
1080 if (members.empty()) {
1081 return boost::optional<member>();
1082 }
1083 auto i = index->fetch_add(1);
1084 return boost::make_optional(std::move(members[i % members.size()]));
1085 });
1086 }
1087 return *load_balancer_;
1088}
1089
1092{
1093 this->load_balancer_ = std::move(load_balancer);
1094 return *this;
1095}
1096
1099{
1100 return logger_config_;
1101}
1102
1105{
1106 lifecycle_listeners_.emplace_back(std::move(listener));
1107 return *this;
1108}
1109
1112{
1113 membership_listeners_.emplace_back(std::move(listener));
1114 return *this;
1115}
1116
1117const std::vector<lifecycle_listener>&
1119{
1120 return lifecycle_listeners_;
1121}
1122
1123const std::vector<membership_listener>&
1125{
1126 return membership_listeners_;
1127}
1128
1131{
1132 this->socket_interceptor_ = std::move(interceptor);
1133 return *this;
1134}
1135
1136const socket_interceptor&
1138{
1139 return socket_interceptor_;
1140}
1141
1144{
1145 return serialization_config_;
1146}
1147
1151{
1152 this->serialization_config_ = serialization_config;
1153 return *this;
1154}
1155
1156const std::unordered_map<std::string, std::string>&
1158{
1159 return properties_;
1160}
1161
1163client_config::set_property(const std::string& name, const std::string& value)
1164{
1165 properties_[name] = value;
1166 return *this;
1167}
1168
1171 const config::reliable_topic_config& reliable_topic_config)
1172{
1173 reliable_topic_config_map_[reliable_topic_config.get_name()] =
1174 reliable_topic_config;
1175 return *this;
1176}
1177
1180{
1181 auto it = reliable_topic_config_map_.find(name);
1182 if (it != reliable_topic_config_map_.end()) {
1183 return it->second;
1184 }
1185
1186 return reliable_topic_config_map_
1187 .emplace(name, config::reliable_topic_config{ name })
1188 .first->second;
1189}
1190
1192client_config::lookup_reliable_topic_config(const std::string& name) const
1193{
1194 auto it = reliable_topic_config_map_.find(name);
1195 if (it != reliable_topic_config_map_.end()) {
1196 return &it->second;
1197 }
1198
1199 return nullptr;
1200}
1201
1202config::client_network_config&
1204{
1205 return network_config_;
1206}
1207
1210 const config::near_cache_config& near_cache_config)
1211{
1212 near_cache_config_map_.emplace(near_cache_config.get_name(),
1213 near_cache_config);
1214 return *this;
1215}
1216
1218client_config::get_near_cache_config(const std::string& name) const
1219{
1220 auto nearCacheConfig = internal::config::ConfigUtils::lookup_by_pattern(
1221 config_pattern_matcher_, near_cache_config_map_, name);
1222 if (nearCacheConfig) {
1223 return nearCacheConfig;
1224 }
1225
1226 auto config_it = near_cache_config_map_.find("default");
1227 if (config_it != near_cache_config_map_.end()) {
1228 return &near_cache_config_map_.find("default")->second;
1229 }
1230
1231 // not needed for c++ client since it is always native memory
1232 // initDefaultMaxSizeForOnHeapMaps(nearCacheConfig);
1233 return nullptr;
1234}
1235
1238 const config::client_network_config& network_config)
1239{
1240 this->network_config_ = network_config;
1241 return *this;
1242}
1243
1244const boost::optional<std::string>&
1245client_config::get_instance_name() const
1246{
1247 return instance_name_;
1248}
1249
1250client_config&
1251client_config::set_instance_name(const std::string& instance_name)
1252{
1253 instance_name_ = instance_name;
1254 return *this;
1255}
1256
1257int32_t
1259{
1260 return executor_pool_size_;
1261}
1262
1263void
1264client_config::set_executor_pool_size(int32_t executor_pool_size)
1265{
1266 executor_pool_size_ = executor_pool_size;
1267}
1268
1270client_config::get_connection_strategy_config()
1271{
1272 return connection_strategy_config_;
1273}
1274
1275client_config&
1276client_config::set_connection_strategy_config(
1277 const config::client_connection_strategy_config& connection_strategy_config)
1278{
1279 connection_strategy_config_ = connection_strategy_config;
1280 return *this;
1281}
1282
1283const config::client_flake_id_generator_config*
1285{
1286 std::string baseName =
1287 internal::partition::strategy::StringPartitioningStrategy::get_base_name(
1288 name);
1289 auto config = internal::config::ConfigUtils::lookup_by_pattern<
1291 config_pattern_matcher_, flake_id_generator_config_map_, baseName);
1292 if (config) {
1293 return config;
1294 }
1295 return get_flake_id_generator_config("default");
1296}
1297
1300{
1301 std::string baseName =
1302 internal::partition::strategy::StringPartitioningStrategy::get_base_name(
1303 name);
1304 auto config = internal::config::ConfigUtils::lookup_by_pattern<
1306 config_pattern_matcher_, flake_id_generator_config_map_, baseName);
1307 if (config) {
1308 return config;
1309 }
1310 auto defConfig = flake_id_generator_config_map_.find("default");
1311 if (defConfig == flake_id_generator_config_map_.end()) {
1312 flake_id_generator_config_map_.emplace(
1313 "default", config::client_flake_id_generator_config("default"));
1314 }
1315 defConfig = flake_id_generator_config_map_.find("default");
1316 config::client_flake_id_generator_config new_config = defConfig->second;
1317 new_config.set_name(name);
1318 flake_id_generator_config_map_.emplace(name, std::move(new_config));
1319 return &flake_id_generator_config_map_.find(name)->second;
1320}
1321
1325{
1326 flake_id_generator_config_map_.emplace(config.get_name(), config);
1327 return *this;
1328}
1329
1330const std::string&
1332{
1333 return cluster_name_;
1334}
1335
1337client_config::set_cluster_name(const std::string& cluster_name)
1338{
1339 cluster_name_ = cluster_name;
1340 return *this;
1341}
1342
1343const std::unordered_set<std::string>&
1344client_config::get_labels() const
1345{
1346 return labels_;
1347}
1348
1349client_config&
1350client_config::set_labels(const std::unordered_set<std::string>& labels)
1351{
1352 labels_ = labels;
1353 return *this;
1354}
1355
1357client_config::add_label(const std::string& label)
1358{
1359 labels_.insert(label);
1360 return *this;
1361}
1362
1365{
1366 backup_acks_enabled_ = enabled;
1367 return *this;
1368}
1369
1370bool
1372{
1373 return backup_acks_enabled_;
1374}
1375
1376const std::shared_ptr<security::credentials>&
1377client_config::get_credentials() const
1378{
1379 return credentials_;
1380}
1381
1382client_config&
1384 const std::shared_ptr<security::credentials>& credential)
1385{
1386 credentials_ = credential;
1387 return *this;
1388}
1389
1390namespace security {
1391username_password_credentials::username_password_credentials(
1392 const std::string& name,
1393 const std::string& password)
1394 : credentials(name)
1395 , password_(password)
1396{}
1397
1398const std::string&
1399username_password_credentials::password() const
1400{
1401 return password_;
1402}
1403
1404credentials::credential_type
1405username_password_credentials::type() const
1406{
1407 return credentials::credential_type::username_password;
1408}
1409
1410const std::vector<byte>&
1411token_credentials::token() const
1412{
1413 return token_;
1414}
1415
1416credentials::credential_type
1417token_credentials::type() const
1418{
1419 return credentials::credential_type::token;
1420}
1421
1422token_credentials::token_credentials(const std::vector<byte>& token)
1423 : credentials(token.empty() ? "<empty>" : "<token>")
1424 , token_(token)
1425{}
1426
1427credentials::~credentials() {}
1428
1429const std::string&
1430credentials::name() const
1431{
1432 return name_;
1433}
1434
1435credentials::credentials(const std::string& name)
1436 : name_(name)
1437{}
1438} // namespace security
1439} // namespace client
1440} // namespace hazelcast
Represents an address of a client or member in the cluster.
Definition address.h:37
hazelcast_client configuration class.
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 & 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
bool backup_acks_enabled()
Note that backup acks to client can be enabled only for smart client.
Definition config.cpp:1371
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
Hazelcast cluster interface.
Definition cluster.h:37
std::vector< member > get_members()
Set of current members of the cluster.
Definition cluster.cpp:39
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:595
const std::string & get_tag_key() const
Gets the tag key.
Definition config.cpp:686
const std::string & get_security_group_name() const
Gets the security group name.
Definition config.cpp:673
const std::string & get_region() const
Gets the region where the EC2 instances running the Hazelcast members will be running.
Definition config.cpp:623
const std::string & get_host_header() const
Gets the host header; the address where the EC2 API can be found.
Definition config.cpp:637
client_aws_config & set_secret_key(const std::string &secret_key)
Sets the secret key to access AWS.
Definition config.cpp:615
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:643
client_aws_config & set_tag_key(const std::string &tag_key)
Sets the tag key.
Definition config.cpp:679
client_aws_config & set_iam_role(const std::string &iam_role)
Sets the tag value.
Definition config.cpp:711
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:724
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:629
bool is_enabled() const
Checks if the aws join mechanism is enabled.
Definition config.cpp:659
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:718
const std::string & get_secret_key() const
Gets the secret key to access AWS.
Definition config.cpp:609
client_aws_config & set_enabled(bool enabled)
Enables or disables the aws join mechanism.
Definition config.cpp:651
const std::string & get_tag_value() const
Gets the tag value.
Definition config.cpp:699
client_aws_config & set_access_key(const std::string &access_key)
Sets the access key to access AWS.
Definition config.cpp:601
client_aws_config & set_tag_value(const std::string &tag_value)
Sets the tag value.
Definition config.cpp:692
const std::string & get_iam_role() const
Gets the iamRole name.
Definition config.cpp:705
client_aws_config & set_security_group_name(const std::string &security_group_name)
Sets the security group name.
Definition config.cpp:665
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:456
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:470
client_connection_strategy_config & set_async_start(bool async_start)
Set true for non blocking hazelcast_client(const client_config&).
Definition config.cpp:449
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:464
bool is_async_start() const
Client instance creation won't block on hazelcast_client(ClientConfig &) if this value is true.
Definition config.cpp:443
The ClientFlakeIdGeneratorConfig contains the configuration for the client regarding Flake ID Generat...
static constexpr int64_t DEFAULT_PREFETCH_VALIDITY_MILLIS
Default value for getPrefetchValidityMillis().
client_flake_id_generator_config & set_prefetch_count(int32_t count)
Sets how many IDs are pre-fetched on the background when one call to FlakeIdGenerator#newId() is made...
Definition config.cpp:206
static constexpr int32_t MAXIMUM_PREFETCH_COUNT
Maximum value for prefetch count.
std::chrono::milliseconds get_prefetch_validity_duration() const
Definition config.cpp:218
const std::string & get_name() const
Returns the configuration name.
Definition config.cpp:187
client_flake_id_generator_config & set_name(const std::string &n)
Sets the name or name pattern for this config.
Definition config.cpp:193
client_flake_id_generator_config & set_prefetch_validity_duration(std::chrono::milliseconds duration)
Sets for how long the pre-fetched IDs can be used.
Definition config.cpp:224
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:391
bool is_smart_routing() const
See client_network_config::setSmartRouting(boolean) for details.
Definition config.cpp:364
std::vector< address > get_addresses() const
Returns the list of candidate addresses that client will use to establish initial connection.
Definition config.cpp:377
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:383
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:398
client_network_config & set_smart_routing(bool smart_routing)
If true, client will route the key based operations to owner of the key on best-effort basis.
Definition config.cpp:370
client_network_config & set_connection_timeout(const std::chrono::milliseconds &timeout)
Definition config.cpp:411
client_aws_config & get_aws_config()
Returns the current client_aws_config.
Definition config.cpp:352
ssl_config & get_ssl_config()
Returns the current \ssl_config .
Definition config.cpp:325
client_network_config()
Constructor with default values.
Definition config.cpp:319
std::chrono::milliseconds get_connection_timeout() const
Connection timeout value for connecting to a member server.
Definition config.cpp:338
cloud_config & get_cloud_config()
Returns the current cloud_config.
Definition config.cpp:358
client_network_config & set_aws_config(const client_aws_config &client_aws_config)
Sets configuration to connect nodes in aws environment.
Definition config.cpp:344
client_network_config & set_ssl_config(const config::ssl_config &config)
Sets the ssl_config.
Definition config.cpp:331
Connection Retry Config is controls the period among the retries and when should a client gave up ret...
connection_retry_config & set_initial_backoff_duration(std::chrono::milliseconds initial_backoff_duration)
Definition config.cpp:246
connection_retry_config & set_cluster_connect_timeout(std::chrono::milliseconds cluster_connect_timeout)
Definition config.cpp:294
std::chrono::milliseconds get_cluster_connect_timeout() const
Timeout value for the client to give up to connect to the current cluster Theclient can shutdown afte...
Definition config.cpp:288
std::chrono::milliseconds get_max_backoff_duration() const
When backoff reaches this upper bound, it does not increase any more.
Definition config.cpp:257
connection_retry_config & set_multiplier(double multiplier)
Definition config.cpp:279
connection_retry_config & set_jitter(double jitter)
At each iteration calculated back-off is randomized via following method random(-jitter * current_bac...
Definition config.cpp:311
double get_multiplier() const
factor with which to multiply backoff time after a failed retry
Definition config.cpp:273
connection_retry_config & set_max_backoff_duration(std::chrono::milliseconds max_backoff_duration)
When backoff reaches this upper bound, it does not increase any more.
Definition config.cpp:263
double get_jitter() const
by how much to randomize backoffs.
Definition config.cpp:305
std::chrono::milliseconds get_initial_backoff_duration() const
how long to wait after the first failure before retrying
Definition config.cpp:240
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:745
Contains the configuration for a Near Cache.
near_cache_config & set_cache_local_entries(bool cache_local_entries)
Definition config.cpp:998
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:984
near_cache_config & set_eviction_config(const eviction_config &eviction_config)
Sets the eviction configuration.
Definition config.cpp:1025
const in_memory_format & get_in_memory_format() const
Gets the data type used to store entries.
Definition config.cpp:978
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:937
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:943
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:971
const std::string & get_name() const
Gets the name of the Near Cache.
Definition config.cpp:924
eviction_config & get_eviction_config()
The eviction configuration.
Definition config.cpp:1019
bool is_invalidate_on_change() const
True to evict the cached entries if the entries are changed (updated or removed).
Definition config.cpp:965
near_cache_config & set_name(const std::string &name)
Sets the name of the Near Cache.
Definition config.cpp:930
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:951
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:957
const std::string & get_name() const
Gets the name of the reliable topic.
Definition config.cpp:489
reliable_topic_config & set_read_batch_size(int batch_size)
Sets the read batch size.
Definition config.cpp:501
int get_read_batch_size() const
Gets the maximum number of items to read in a batch.
Definition config.cpp:495
socket_options & set_tcp_no_delay(bool tcp_no_delay)
Enable/disable TCP_NODELAY socket option.
Definition config.cpp:529
socket_options & set_reuse_address(bool reuse_address)
Enable/disable the SO_REUSEADDR socket option.
Definition config.cpp:555
socket_options & set_linger_seconds(int linger_seconds)
Enable/disable SO_LINGER with the specified linger time in seconds.
Definition config.cpp:568
bool is_keep_alive() const
SO_KEEPALIVE socket option.
Definition config.cpp:536
socket_options & set_keep_alive(bool keep_alive)
Enable/disable SO_KEEPALIVE socket option.
Definition config.cpp:542
bool is_reuse_address() const
SO_REUSEADDR socket option.
Definition config.cpp:549
bool is_tcp_no_delay() const
TCP_NODELAY socket option.
Definition config.cpp:523
int get_buffer_size_in_bytes() const
If set to 0 or less, then it is not set on the socket.
Definition config.cpp:575
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:581
int get_linger_seconds() const
Gets SO_LINGER with the specified linger time in seconds.
Definition config.cpp:562
Contains configuration parameters for ssl related behaviour.
Definition ssl_config.h:67
Listener object for listening lifecycle events of hazelcast instance.
load_balancer allows you to send operations to one of a number of endpoints(Members).
load_balancer & next(Handler &&h) &
The function returns the next member to route to.
serialization_config & set_portable_version(int v)
Definition config.cpp:52
serialization_config & set_global_serializer(const std::shared_ptr< serialization::global_serializer > &global_serializer)
Definition config.cpp:65
serialization_config & set_byte_order(boost::endian::order byte_order)
Definition config.cpp:73
int get_portable_version() const
Portable version will be used to differentiate two same class that have changes on it ,...
Definition config.cpp:46
serialization_config()
Constructor default value of version is zero.
Definition config.cpp:41
boost::endian::order get_byte_order() const
Definition config.cpp:80
An interface that provides the ability to intercept the creation of sockets.
STL namespace.
hazelcast.cloud configuration to let the client connect the cluster via hazelcast....
bitmap_index_options()
Constructs a new bitmap index options instance with all options set to default values.
Definition config.cpp:806
@ OBJECT
Extracted unique key value is interpreted as an object value.
static const unique_key_transformation DEFAULT_TRANSFORMATION
The default for \transformation.
static const std::string DEFAULT_KEY
The default for \key.
index_config(index_type type=DEFAULT_TYPE)
Creates an index configuration of the given type.
Definition config.cpp:814
index_type type
Type of the index.