21 #include <boost/format.hpp>
23 #include "hazelcast/util/Util.h"
24 #include "hazelcast/util/IOUtil.h"
25 #include "hazelcast/client/hazelcast_client.h"
26 #include "hazelcast/client/transaction_context.h"
27 #include "hazelcast/client/cluster.h"
28 #include "hazelcast/client/spi/lifecycle_service.h"
29 #include "hazelcast/client/lifecycle_listener.h"
30 #include "hazelcast/client/exception/protocol_exceptions.h"
31 #include "hazelcast/client/aws/aws_client.h"
32 #include "hazelcast/client/spi/impl/discovery/cloud_discovery.h"
33 #include "hazelcast/client/impl/hazelcast_client_instance_impl.h"
34 #include "hazelcast/client/impl/ClientLockReferenceIdGenerator.h"
35 #include "hazelcast/client/spi/impl/ClientInvocationServiceImpl.h"
36 #include "hazelcast/client/spi/impl/ClientPartitionServiceImpl.h"
37 #include "hazelcast/client/spi/impl/ClientExecutionServiceImpl.h"
38 #include "hazelcast/client/spi/impl/sequence/CallIdFactory.h"
39 #include "hazelcast/client/spi/impl/DefaultAddressProvider.h"
40 #include "hazelcast/client/spi/impl/discovery/remote_address_provider.h"
41 #include "hazelcast/client/spi/impl/listener/listener_service_impl.h"
42 #include "hazelcast/client/load_balancer.h"
43 #include "hazelcast/client/connection/ClientConnectionManagerImpl.h"
44 #include "hazelcast/client/proxy/flake_id_generator_impl.h"
45 #include "hazelcast/logger.h"
46 #include "hazelcast/client/member_selectors.h"
47 #include "hazelcast/client/client_properties.h"
48 #include "hazelcast/client/big_decimal.h"
49 #include "hazelcast/client/local_time.h"
50 #include "hazelcast/client/local_date.h"
51 #include "hazelcast/client/local_date_time.h"
52 #include "hazelcast/client/offset_date_time.h"
53 #ifndef HAZELCAST_VERSION
54 #define HAZELCAST_VERSION "NOT_FOUND"
59 hazelcast_client::hazelcast_client()
61 new impl::hazelcast_client_instance_impl(*this, client_config()))
63 client_impl_->start();
66 hazelcast_client::hazelcast_client(client_config config)
68 new impl::hazelcast_client_instance_impl(*this, std::move(config)))
70 client_impl_->start();
74 hazelcast_client::get_name()
const
76 return client_impl_->get_name();
80 hazelcast_client::get_client_config()
82 return client_impl_->get_client_config();
86 hazelcast_client::new_transaction_context()
88 return client_impl_->new_transaction_context();
94 return client_impl_->new_transaction_context(options);
98 hazelcast_client::get_cluster()
100 return client_impl_->get_cluster();
104 hazelcast_client::add_lifecycle_listener(
111 hazelcast_client::remove_lifecycle_listener(
112 const boost::uuids::uuid& registration_id)
114 return client_impl_->remove_lifecycle_listener(registration_id);
118 hazelcast_client::shutdown()
120 return boost::async([=]() { client_impl_->shutdown(); });
123 spi::lifecycle_service&
124 hazelcast_client::get_lifecycle_service()
126 return client_impl_->get_lifecycle_service();
130 hazelcast_client::get_local_endpoint()
const
132 return client_impl_->get_local_endpoint();
135 hazelcast_client::~hazelcast_client() =
default;
138 hazelcast_client::get_cp_subsystem()
140 return client_impl_->get_cp_subsystem();
144 hazelcast_client::get_sql()
146 return client_impl_->get_sql();
149 const boost::string_view
152 return HAZELCAST_VERSION;
156 std::atomic<int32_t> hazelcast_client_instance_impl::CLIENT_ID(0);
158 hazelcast_client_instance_impl::hazelcast_client_instance_impl(
160 client_config config)
161 : client_config_(std::move(config))
162 , client_properties_(client_config_.get_properties())
163 , client_context_(*this)
164 , serialization_service_(client_config_.get_serialization_config())
165 , cluster_service_(client_context_)
166 , transaction_manager_(client_context_)
167 , cluster_(cluster_service_)
168 , lifecycle_service_(client_context_,
169 client_config_.get_lifecycle_listeners())
170 , proxy_manager_(client_context_)
172 , random_generator_(std::random_device{}())
173 , uuid_generator_{ random_generator_ }
174 , cp_subsystem_(client_context_)
175 , sql_service_(client_context_)
176 , proxy_session_manager_(client_context_)
178 auto& name = client_config_.get_instance_name();
180 instance_name_ = *name;
182 std::ostringstream out;
183 out <<
"hz.client_" << id_;
184 instance_name_ = out.str();
187 auto logger_config = client_config_.get_logger_config();
188 logger_ = std::make_shared<logger>(instance_name_,
189 client_config_.get_cluster_name(),
190 logger_config.level(),
191 logger_config.handler());
193 execution_service_ = init_execution_service();
195 initalize_near_cache_manager();
197 int32_t maxAllowedConcurrentInvocations = client_properties_.get_integer(
198 client_properties_.get_max_concurrent_invocations());
199 int64_t backofftimeoutMs = client_properties_.get_long(
200 client_properties_.get_backpressure_backoff_timeout_millis());
201 bool isBackPressureEnabled = maxAllowedConcurrentInvocations != INT32_MAX;
203 spi::impl::sequence::CallIdFactory::new_call_id_sequence(
204 isBackPressureEnabled,
205 maxAllowedConcurrentInvocations,
208 auto address_provider = create_address_provider();
210 connection_manager_ =
211 std::make_shared<connection::ClientConnectionManagerImpl>(
212 client_context_, std::move(address_provider));
214 cluster_listener_.reset(
215 new spi::impl::listener::cluster_view_listener(client_context_));
217 partition_service_.reset(
218 new spi::impl::ClientPartitionServiceImpl(client_context_));
220 invocation_service_.reset(
221 new spi::impl::ClientInvocationServiceImpl(client_context_));
223 listener_service_ = init_listener_service();
225 proxy_manager_.init();
227 lock_reference_id_generator_.reset(
228 new impl::ClientLockReferenceIdGenerator());
230 statistics_.reset(
new statistics::Statistics(client_context_));
233 hazelcast_client_instance_impl::~hazelcast_client_instance_impl()
239 hazelcast_client_instance_impl::start()
241 lifecycle_service_.fire_lifecycle_event(lifecycle_event::STARTING);
244 if (!lifecycle_service_.start()) {
245 lifecycle_service_.shutdown();
246 BOOST_THROW_EXCEPTION(exception::illegal_state(
247 "hazelcast_client",
"hazelcast_client could not be started!"));
249 }
catch (std::exception&) {
250 lifecycle_service_.shutdown();
256 hazelcast_client_instance_impl::get_client_config()
258 return client_config_;
262 hazelcast_client_instance_impl::get_cluster()
268 hazelcast_client_instance_impl::add_lifecycle_listener(
269 lifecycle_listener&& lifecycle_listener)
271 return lifecycle_service_.add_listener(std::move(lifecycle_listener));
275 hazelcast_client_instance_impl::remove_lifecycle_listener(
276 const boost::uuids::uuid& registration_id)
278 return lifecycle_service_.remove_listener(registration_id);
282 hazelcast_client_instance_impl::shutdown()
284 lifecycle_service_.shutdown();
288 hazelcast_client_instance_impl::new_transaction_context()
290 transaction_options defaultOptions;
291 return new_transaction_context(defaultOptions);
295 hazelcast_client_instance_impl::new_transaction_context(
296 const transaction_options& options)
298 return transaction_context(transaction_manager_, options);
301 internal::nearcache::NearCacheManager&
302 hazelcast_client_instance_impl::get_near_cache_manager()
304 return *near_cache_manager_;
307 serialization::pimpl::SerializationService&
308 hazelcast_client_instance_impl::get_serialization_service()
310 return serialization_service_;
313 const protocol::ClientExceptionFactory&
314 hazelcast_client_instance_impl::get_exception_factory()
const
316 return exception_factory_;
319 std::shared_ptr<spi::impl::listener::listener_service_impl>
320 hazelcast_client_instance_impl::init_listener_service()
322 auto eventThreadCount = client_properties_.get_integer(
323 client_properties_.get_event_thread_count());
324 return std::make_shared<spi::impl::listener::listener_service_impl>(
325 client_context_, eventThreadCount);
328 std::shared_ptr<spi::impl::ClientExecutionServiceImpl>
329 hazelcast_client_instance_impl::init_execution_service()
331 return std::make_shared<spi::impl::ClientExecutionServiceImpl>(
334 client_config_.get_executor_pool_size(),
339 hazelcast_client_instance_impl::on_cluster_restart()
343 "Clearing local state of the client, because of a cluster restart");
345 near_cache_manager_->clear_all_near_caches();
347 cluster_service_.clear_member_list();
350 std::unique_ptr<connection::AddressProvider>
351 hazelcast_client_instance_impl::create_address_provider()
353 config::client_network_config& networkConfig =
354 get_client_config().get_network_config();
355 config::client_aws_config& awsConfig = networkConfig.get_aws_config();
356 config::cloud_config& cloudConfig = networkConfig.get_cloud_config();
358 auto addresses = networkConfig.get_addresses();
359 bool addressListProvided = !addresses.empty();
360 bool awsDiscoveryEnabled = awsConfig.is_enabled();
361 bool cloud_enabled = cloudConfig.enabled;
363 check_discovery_configuration_consistency(
364 addressListProvided, awsDiscoveryEnabled, cloud_enabled);
366 auto connect_timeout = networkConfig.get_connection_timeout();
368 auto cloud_provider =
369 std::make_shared<spi::impl::discovery::cloud_discovery>(
371 client_properties_.get_string(client_properties_.cloud_base_url()),
373 return std::unique_ptr<connection::AddressProvider>(
374 new spi::impl::discovery::remote_address_provider(
375 [=]() {
return cloud_provider->get_addresses(); },
true));
378 if (awsDiscoveryEnabled) {
379 auto aws_addr_provider = std::make_shared<aws::aws_client>(
380 connect_timeout, awsConfig, client_properties_, *logger_);
381 return std::unique_ptr<connection::AddressProvider>(
382 new spi::impl::discovery::remote_address_provider(
383 [=]() {
return aws_addr_provider->get_addresses(); },
384 !awsConfig.is_inside_aws()));
387 return std::unique_ptr<connection::AddressProvider>(
388 new spi::impl::DefaultAddressProvider(networkConfig));
392 hazelcast_client_instance_impl::get_name()
const
394 return instance_name_;
397 spi::lifecycle_service&
398 hazelcast_client_instance_impl::get_lifecycle_service()
400 return lifecycle_service_;
403 const std::shared_ptr<ClientLockReferenceIdGenerator>&
404 hazelcast_client_instance_impl::get_lock_reference_id_generator()
const
406 return lock_reference_id_generator_;
410 hazelcast_client_instance_impl::get_proxy_manager()
412 return proxy_manager_;
416 hazelcast_client_instance_impl::initalize_near_cache_manager()
418 near_cache_manager_.reset(
new internal::nearcache::NearCacheManager(
419 execution_service_, serialization_service_, *logger_));
423 hazelcast_client_instance_impl::get_local_endpoint()
const
425 return cluster_service_.get_local_client();
429 boost::shared_future<std::shared_ptr<imap>>
430 hazelcast_client_instance_impl::get_distributed_object(
const std::string& name)
432 auto nearCacheConfig = client_config_.get_near_cache_config(name);
433 if (nearCacheConfig) {
434 return proxy_manager_
435 .get_or_create_proxy<
436 map::NearCachedClientMapProxy<serialization::pimpl::data,
437 serialization::pimpl::data>>(
438 imap::SERVICE_NAME, name)
442 boost::shared_future<std::shared_ptr<
443 map::NearCachedClientMapProxy<serialization::pimpl::data,
444 serialization::pimpl::data>>> f) {
445 return std::static_pointer_cast<imap>(f.get());
448 return proxy_manager_.get_or_create_proxy<imap>(imap::SERVICE_NAME,
453 const std::shared_ptr<logger>&
454 hazelcast_client_instance_impl::get_logger()
const
460 hazelcast_client_instance_impl::random_uuid()
462 std::lock_guard<std::mutex> g(uuid_generator_lock_);
463 return uuid_generator_();
467 hazelcast_client_instance_impl::get_cp_subsystem()
469 return cp_subsystem_;
473 hazelcast_client_instance_impl::get_sql()
479 hazelcast_client_instance_impl::check_discovery_configuration_consistency(
480 bool address_list_provided,
485 if (address_list_provided)
492 throw exception::illegal_state(
493 "hazelcast_client_instance_impl::check_discovery_configuration_"
496 "Only one discovery method can be enabled at a time. cluster "
497 "members given explicitly : %1%, aws discovery: %2%, "
498 "hazelcast.cloud enabled : %3%") %
499 address_list_provided % aws_enabled % cloud_enabled)
504 BaseEventHandler::~BaseEventHandler() =
default;
506 BaseEventHandler::BaseEventHandler()
511 BaseEventHandler::set_logger(logger* lg)
513 BaseEventHandler::logger_ = lg;
517 BaseEventHandler::get_logger()
const
523 constexpr
int address::ID;
532 : host_(std::move(url))
539 : host_(std::move(hostname))
542 , scope_id_(scope_id)
548 return rhs.port_ == port_ && rhs.type_ == type_ &&
549 0 == rhs.host_.compare(host_);
555 return !(*
this == rhs);
571 address::operator<(
const address& rhs)
const
573 if (host_ < rhs.host_) {
576 if (rhs.host_ < host_) {
579 if (port_ < rhs.port_) {
582 if (rhs.port_ < port_) {
585 return type_ < rhs.type_;
591 return type_ == IPV4;
595 address::get_scope_id()
const
601 address::to_string()
const
603 std::ostringstream out;
609 operator<<(std::ostream& stream,
const address& address)
611 return stream << address.to_string();
615 operator==(
const big_decimal& lhs,
const big_decimal& rhs)
617 return lhs.unscaled == rhs.unscaled && lhs.scale == rhs.scale;
621 operator<(
const big_decimal& lhs,
const big_decimal& rhs)
623 if (lhs.scale != rhs.scale) {
624 return lhs.scale < rhs.scale;
626 return lhs.unscaled < rhs.unscaled;
630 operator==(
const local_time& lhs,
const local_time& rhs)
632 return lhs.hours == rhs.hours && lhs.minutes == rhs.minutes &&
633 lhs.seconds == rhs.seconds && lhs.nanos == rhs.nanos;
642 hash_value(
const T& v)
644 return std::hash<T>()(v);
648 operator<(
const local_time& lhs,
const local_time& rhs)
650 if (lhs.hours < rhs.hours) {
653 if (rhs.hours < lhs.hours) {
656 if (lhs.minutes < rhs.minutes) {
659 if (rhs.minutes < lhs.minutes) {
662 if (lhs.seconds < rhs.seconds) {
665 if (rhs.seconds < lhs.seconds) {
668 return lhs.nanos < rhs.nanos;
672 operator==(
const local_date& lhs,
const local_date& rhs)
674 return lhs.year == rhs.year && lhs.month == rhs.month &&
675 lhs.day_of_month == rhs.day_of_month;
679 operator<(
const local_date& lhs,
const local_date& rhs)
681 if (lhs.year < rhs.year) {
684 if (rhs.year < lhs.year) {
687 if (lhs.month < rhs.month) {
690 if (rhs.month < lhs.month) {
693 return lhs.day_of_month < rhs.day_of_month;
697 operator==(
const local_date_time& lhs,
const local_date_time& rhs)
699 return lhs.date == rhs.date && lhs.time == rhs.time;
703 operator<(
const local_date_time& lhs,
const local_date_time& rhs)
705 if (lhs.date < rhs.date) {
708 if (rhs.date < lhs.date) {
711 return lhs.time < rhs.time;
715 operator==(
const offset_date_time& lhs,
const offset_date_time& rhs)
717 return lhs.date_time == rhs.date_time &&
718 lhs.zone_offset_in_seconds == rhs.zone_offset_in_seconds;
722 operator<(
const offset_date_time& lhs,
const offset_date_time& rhs)
724 if (lhs.date_time < rhs.date_time) {
727 if (rhs.date_time < lhs.date_time) {
730 return lhs.zone_offset_in_seconds < rhs.zone_offset_in_seconds;
736 twos_complement(std::vector<int8_t>& a)
740 for (
auto& item : a) {
745 for (
int i = a.size() - 1; i >= 0; i--) {
755 boost::multiprecision::cpp_int
756 from_bytes(std::vector<int8_t> v)
758 boost::multiprecision::cpp_int i;
759 bool is_negative = v[0] < 0;
763 import_bits(i, v.begin(), v.end(), 8);
771 to_bytes(
const boost::multiprecision::cpp_int& i)
773 std::vector<int8_t> v;
774 export_bits(i, std::back_inserter(v), 8);
779 v.insert(v.begin(), -1);
784 v.insert(v.begin(), 0);
791 namespace serialization {
793 hz_serializer<address>::get_factory_id()
799 hz_serializer<address>::get_class_id()
805 hz_serializer<address>::write_data(
const address&
object,
806 object_data_output& out)
808 out.write<int32_t>(
object.port_);
809 out.write<
byte>(
object.type_);
810 out.write(
object.host_);
814 hz_serializer<address>::read_data(object_data_input& in)
817 object.port_ = in.read<int32_t>();
818 object.type_ = in.read<
byte>();
819 object.host_ = in.read<std::string>();
824 iexecutor_service::iexecutor_service(
const std::string& name,
825 spi::ClientContext* context)
826 : ProxyImpl(SERVICE_NAME, name, context)
827 , consecutive_submits_(0)
828 , last_submit_time_(0)
832 iexecutor_service::select_members(
const member_selector& member_selector)
834 std::vector<member> selected;
835 std::vector<member> members =
836 get_context().get_client_cluster_service().get_member_list();
837 for (
const member& member : members) {
838 if (member_selector.select(member)) {
839 selected.push_back(member);
842 if (selected.empty()) {
843 BOOST_THROW_EXCEPTION(exception::rejected_execution(
844 "IExecutorService::selectMembers",
845 "No member could be selected with member selector"));
850 std::pair<boost::future<protocol::ClientMessage>,
851 std::shared_ptr<spi::impl::ClientInvocation>>
852 iexecutor_service::invoke_on_target(protocol::ClientMessage&& request,
853 boost::uuids::uuid target)
856 std::shared_ptr<spi::impl::ClientInvocation> clientInvocation =
857 spi::impl::ClientInvocation::create(
858 get_context(), request, get_name(), target);
859 return std::make_pair(clientInvocation->invoke(), clientInvocation);
860 }
catch (exception::iexception&) {
861 util::exception_util::rethrow(std::current_exception());
863 return std::pair<boost::future<protocol::ClientMessage>,
864 std::shared_ptr<spi::impl::ClientInvocation>>();
867 std::pair<boost::future<protocol::ClientMessage>,
868 std::shared_ptr<spi::impl::ClientInvocation>>
869 iexecutor_service::invoke_on_partition_owner(protocol::ClientMessage&& request,
873 std::shared_ptr<spi::impl::ClientInvocation> clientInvocation =
874 spi::impl::ClientInvocation::create(
875 get_context(), request, get_name(), partition_id);
876 return std::make_pair(clientInvocation->invoke(), clientInvocation);
877 }
catch (exception::iexception&) {
878 util::exception_util::rethrow(std::current_exception());
880 return std::pair<boost::future<protocol::ClientMessage>,
881 std::shared_ptr<spi::impl::ClientInvocation>>();
885 iexecutor_service::is_sync_computation(
bool prevent_sync)
887 int64_t now = util::current_time_millis();
889 int64_t last = last_submit_time_;
890 last_submit_time_ = now;
892 if (last + MIN_TIME_RESOLUTION_OF_CONSECUTIVE_SUBMITS < now) {
893 consecutive_submits_ = 0;
897 return !prevent_sync &&
898 (consecutive_submits_++ % MAX_CONSECUTIVE_SUBMITS == 0);
902 iexecutor_service::get_member_address(
const member& member)
905 get_context().get_client_cluster_service().get_member(member.get_uuid());
907 throw(exception::exception_builder<exception::hazelcast_>(
908 "IExecutorService::getMemberAddress(Member)")
909 << member <<
" is not available!")
912 return m->get_address();
916 iexecutor_service::random_partition_id()
918 auto& partitionService = get_context().get_partition_service();
919 return rand() % partitionService.get_partition_count();
925 auto request = protocol::codec::executorservice_shutdown_encode(get_name());
933 protocol::codec::executorservice_isshutdown_encode(get_name());
934 return invoke_and_get_future<bool>(request);
944 "hazelcast_client_heartbeat_timeout";
945 const std::string client_properties::PROP_HEARTBEAT_TIMEOUT_DEFAULT =
"60000";
947 "hazelcast_client_heartbeat_interval";
948 const std::string client_properties::PROP_HEARTBEAT_INTERVAL_DEFAULT =
"5000";
950 "hazelcast_client_request_retry_count";
951 const std::string client_properties::PROP_REQUEST_RETRY_COUNT_DEFAULT =
"20";
953 "hazelcast_client_request_retry_wait_time";
954 const std::string client_properties::PROP_REQUEST_RETRY_WAIT_TIME_DEFAULT =
"1";
957 const std::string client_properties::PROP_AWS_MEMBER_PORT_DEFAULT =
"5701";
960 "hazelcast.client.invocation.retry.pause.millis";
961 const std::string client_properties::INVOCATION_RETRY_PAUSE_MILLIS_DEFAULT =
965 "hazelcast.client.invocation.timeout.seconds";
966 const std::string client_properties::INVOCATION_TIMEOUT_SECONDS_DEFAULT =
"120";
969 "hazelcast.client.event.thread.count";
970 const std::string client_properties::EVENT_THREAD_COUNT_DEFAULT =
"5";
972 const std::string client_properties::INTERNAL_EXECUTOR_POOL_SIZE =
973 "hazelcast.client.internal.executor.pool.size";
974 const std::string client_properties::INTERNAL_EXECUTOR_POOL_SIZE_DEFAULT =
"3";
977 "hazelcast.client.shuffle.member.list";
978 const std::string client_properties::SHUFFLE_MEMBER_LIST_DEFAULT =
"true";
981 "hazelcast.client.max.concurrent.invocations";
982 const std::string client_properties::MAX_CONCURRENT_INVOCATIONS_DEFAULT =
983 util::IOUtil::to_string<int32_t>(INT32_MAX);
986 "hazelcast.client.invocation.backoff.timeout.millis";
988 client_properties::BACKPRESSURE_BACKOFF_TIMEOUT_MILLIS_DEFAULT =
"-1";
991 "hazelcast.client.statistics.enabled";
992 const std::string client_properties::STATISTICS_ENABLED_DEFAULT =
"false";
995 "hazelcast.client.statistics.period.seconds";
996 const std::string client_properties::STATISTICS_PERIOD_SECONDS_DEFAULT =
"3";
998 client_property::client_property(
const std::string& name,
999 const std::string& default_value)
1001 , default_value_(default_value)
1005 client_property::get_name()
const
1011 client_property::get_default_value()
const
1013 return default_value_;
1019 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
1020 #pragma warning(push)
1024 return std::getenv(name_.c_str());
1025 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
1026 #pragma warning(pop)
1030 client_properties::client_properties(
1031 const std::unordered_map<std::string, std::string>& properties)
1032 : heartbeat_timeout_(PROP_HEARTBEAT_TIMEOUT, PROP_HEARTBEAT_TIMEOUT_DEFAULT)
1033 , heartbeat_interval_(PROP_HEARTBEAT_INTERVAL,
1034 PROP_HEARTBEAT_INTERVAL_DEFAULT)
1035 , retry_count_(PROP_REQUEST_RETRY_COUNT, PROP_REQUEST_RETRY_COUNT_DEFAULT)
1036 , retry_wait_time_(PROP_REQUEST_RETRY_WAIT_TIME,
1037 PROP_REQUEST_RETRY_WAIT_TIME_DEFAULT)
1038 , aws_member_port_(PROP_AWS_MEMBER_PORT, PROP_AWS_MEMBER_PORT_DEFAULT)
1039 , invocation_retry_pause_millis_(INVOCATION_RETRY_PAUSE_MILLIS,
1040 INVOCATION_RETRY_PAUSE_MILLIS_DEFAULT)
1041 , invocation_timeout_seconds_(INVOCATION_TIMEOUT_SECONDS,
1042 INVOCATION_TIMEOUT_SECONDS_DEFAULT)
1043 , event_thread_count_(EVENT_THREAD_COUNT, EVENT_THREAD_COUNT_DEFAULT)
1044 , internal_executor_pool_size_(INTERNAL_EXECUTOR_POOL_SIZE,
1045 INTERNAL_EXECUTOR_POOL_SIZE_DEFAULT)
1046 , shuffle_member_list_(SHUFFLE_MEMBER_LIST, SHUFFLE_MEMBER_LIST_DEFAULT)
1047 , max_concurrent_invocations_(MAX_CONCURRENT_INVOCATIONS,
1048 MAX_CONCURRENT_INVOCATIONS_DEFAULT)
1049 , backpressure_backoff_timeout_millis_(
1050 BACKPRESSURE_BACKOFF_TIMEOUT_MILLIS,
1051 BACKPRESSURE_BACKOFF_TIMEOUT_MILLIS_DEFAULT)
1052 , statistics_enabled_(STATISTICS_ENABLED, STATISTICS_ENABLED_DEFAULT)
1053 , statistics_period_seconds_(STATISTICS_PERIOD_SECONDS,
1054 STATISTICS_PERIOD_SECONDS_DEFAULT)
1055 , backup_timeout_millis_(OPERATION_BACKUP_TIMEOUT_MILLIS,
1056 OPERATION_BACKUP_TIMEOUT_MILLIS_DEFAULT)
1057 , fail_on_indeterminate_state_(FAIL_ON_INDETERMINATE_OPERATION_STATE,
1058 FAIL_ON_INDETERMINATE_OPERATION_STATE_DEFAULT)
1059 , cloud_base_url_(CLOUD_URL_BASE, CLOUD_URL_BASE_DEFAULT)
1060 , properties_map_(properties)
1063 const client_property&
1064 client_properties::get_heartbeat_timeout()
const
1066 return heartbeat_timeout_;
1069 const client_property&
1070 client_properties::get_heartbeat_interval()
const
1072 return heartbeat_interval_;
1075 const client_property&
1076 client_properties::get_aws_member_port()
const
1078 return aws_member_port_;
1081 const client_property&
1082 client_properties::get_invocation_retry_pause_millis()
const
1084 return invocation_retry_pause_millis_;
1087 const client_property&
1088 client_properties::get_invocation_timeout_seconds()
const
1090 return invocation_timeout_seconds_;
1093 const client_property&
1094 client_properties::get_event_thread_count()
const
1096 return event_thread_count_;
1099 const client_property&
1100 client_properties::get_internal_executor_pool_size()
const
1102 return internal_executor_pool_size_;
1105 const client_property&
1106 client_properties::get_shuffle_member_list()
const
1108 return shuffle_member_list_;
1111 const client_property&
1112 client_properties::get_max_concurrent_invocations()
const
1114 return max_concurrent_invocations_;
1117 const client_property&
1118 client_properties::get_backpressure_backoff_timeout_millis()
const
1120 return backpressure_backoff_timeout_millis_;
1123 const client_property&
1124 client_properties::get_statistics_enabled()
const
1126 return statistics_enabled_;
1129 const client_property&
1130 client_properties::get_statistics_period_seconds()
const
1132 return statistics_period_seconds_;
1138 std::unordered_map<std::string, std::string>::const_iterator valueIt =
1139 properties_map_.find(property.get_name());
1140 if (valueIt != properties_map_.end()) {
1141 return valueIt->second;
1144 const char* value =
property.get_system_property();
1145 if (value != NULL) {
1149 return property.get_default_value();
1155 return util::IOUtil::to_value<bool>(
get_string(property));
1161 return util::IOUtil::to_value<int32_t>(
get_string(property));
1167 return util::IOUtil::to_value<int64_t>(
get_string(property));
1171 client_properties::backup_timeout_millis()
const
1173 return backup_timeout_millis_;
1176 const client_property&
1177 client_properties::fail_on_indeterminate_state()
const
1179 return fail_on_indeterminate_state_;
1182 const client_property&
1183 client_properties::cloud_base_url()
const
1185 return cloud_base_url_;
1188 namespace exception {
1189 iexception::iexception(std::string exception_name,
1191 std::string message,
1192 std::string details,
1194 std::exception_ptr cause,
1197 : src_(std::move(source))
1198 , msg_(std::move(message))
1199 , details_(std::move(details))
1200 , error_code_(error_no)
1201 , cause_(std::move(cause))
1202 , runtime_exception_(is_runtime)
1203 , retryable_(retryable)
1204 , report_((boost::format(
"%1% {%2%. Error code:%3%, Details:%4%.} at %5%.") %
1205 exception_name % msg_ % error_code_ % details_ % src_)
1209 iexception::~iexception() noexcept = default;
1214 return report_.c_str();
1218 iexception::get_source()
const
1224 iexception::get_message()
const
1230 operator<<(std::ostream& os,
const iexception& exception)
1232 os << exception.what();
1237 iexception::get_details()
const
1243 iexception::get_error_code()
const
1249 iexception::is_runtime()
const
1251 return runtime_exception_;
1255 iexception::is_retryable()
const
1260 iexception::iexception() =
default;
1262 retryable_hazelcast::retryable_hazelcast(std::string source,
1263 std::string message,
1264 std::string details,
1265 std::exception_ptr cause)
1266 : retryable_hazelcast(
"retryable_hazelcast",
1267 protocol::RETRYABLE_HAZELCAST,
1276 retryable_hazelcast::retryable_hazelcast(std::string error_name,
1279 std::string message,
1280 std::string details,
1281 std::exception_ptr cause,
1284 : hazelcast_(std::move(error_name),
1294 member_left::member_left(std::string source,
1295 std::string message,
1296 std::string details,
1297 std::exception_ptr cause)
1298 : execution(
"member_left",
1299 protocol::MEMBER_LEFT,
1308 consistency_lost::consistency_lost(std::string source,
1309 std::string message,
1310 std::string details,
1311 std::exception_ptr cause)
1312 : hazelcast_(
"consistency_lost",
1313 protocol::CONSISTENCY_LOST_EXCEPTION,
1322 query::query(std::string source,
1323 std::string message,
1324 std::string details,
1325 std::exception_ptr cause)
1326 : hazelcast_(std::move(source),
1334 query::query(int32_t code,
1335 std::string message,
1336 std::exception_ptr cause,
1337 boost::uuids::uuid originating_member_id,
1338 std::string suggestion)
1339 : hazelcast_(
"", std::move(message),
"", std::move(cause))
1341 , suggestion_(std::move(suggestion))
1342 , originating_member_uuid_(originating_member_id)
1353 query::suggestion()
const
1358 const boost::uuids::uuid&
1359 query::originating_member_uuid()
const
1361 return originating_member_uuid_;
1367 boost::future<client::hazelcast_client>
1370 return boost::async([]() {
return client::hazelcast_client(); });
1373 boost::future<client::hazelcast_client>
1374 new_client(client::client_config config)
1376 return boost::async(
1377 [](client::client_config&& c) {
1378 return client::hazelcast_client(std::move(c));
1386 hash<hazelcast::client::address>::operator()(
1389 std::size_t seed = 0;
1390 boost::hash_combine(seed, address.get_host());
1391 boost::hash_combine(seed, address.get_port());
1392 boost::hash_combine(seed, address.type_);
1397 hash<hazelcast::client::big_decimal>::operator()(
1400 std::size_t seed = 0;
1401 boost::hash_combine(seed, dec.unscaled);
1402 boost::hash_combine(seed, dec.scale);
1407 hash<hazelcast::client::local_time>::operator()(
1410 std::size_t seed = 0;
1411 boost::hash_combine(seed, v.
hours);
1412 boost::hash_combine(seed, v.
minutes);
1413 boost::hash_combine(seed, v.
seconds);
1414 boost::hash_combine(seed, v.
nanos);
1419 hash<hazelcast::client::local_date>::operator()(
1422 std::size_t seed = 0;
1423 boost::hash_combine(seed, v.
year);
1424 boost::hash_combine(seed, v.
month);
1430 hash<hazelcast::client::local_date_time>::operator()(
1433 std::size_t seed = 0;
1434 boost::hash_combine<hazelcast::client::local_date>(seed, v.date);
1435 boost::hash_combine<hazelcast::client::local_time>(seed, v.time);
1440 hash<hazelcast::client::offset_date_time>::operator()(
1443 std::size_t seed = 0;
1444 boost::hash_combine<hazelcast::client::local_date_time>(seed, v.
date_time);
Represents an address of a client or member in the cluster.
const std::string & get_host() const
bool operator==(const address &address) const
bool operator!=(const address &address) const
hazelcast_client configuration class.
static const std::string PROP_HEARTBEAT_INTERVAL
Time interval in milliseconds between the heartbeats sent by the client to the nodes.
static const std::string PROP_REQUEST_RETRY_COUNT
Client will retry requests which either inherently retryable(idempotent client) or client_network_con...
static const std::string PROP_REQUEST_RETRY_WAIT_TIME
Client will retry requests which either inherently retryable(idempotent client) or client_network_con...
static const std::string MAX_CONCURRENT_INVOCATIONS
The maximum number of concurrent invocations allowed.
static const std::string SHUFFLE_MEMBER_LIST
Client shuffles the given member list to prevent all clients to connect to the same node when this pr...
static const std::string STATISTICS_PERIOD_SECONDS
The period in seconds the statistics sent to the cluster.
static const std::string EVENT_THREAD_COUNT
Number of the threads to handle the incoming event packets.
static const std::string STATISTICS_ENABLED
Use to enable the client statistics collection.
static const std::string INVOCATION_RETRY_PAUSE_MILLIS
Pause time between each retry cycle of an invocation in milliseconds.
std::string get_string(const client_property &property) const
Returns the configured value of a ClientProperty as std::string.
int32_t get_integer(const client_property &property) const
Returns the configured int32_t value of a ClientProperty.
static const std::string PROP_AWS_MEMBER_PORT
The discovery mechanism will discover only IP addresses.
static const std::string PROP_HEARTBEAT_TIMEOUT
Client will be sending heartbeat messages to members and this is the timeout.
static const std::string INVOCATION_TIMEOUT_SECONDS
When an invocation gets an exception because :
bool get_boolean(const client_property &property) const
Returns the configured boolean value of a ClientProperty.
int64_t get_long(const client_property &property) const
Returns the configured int64_t value of a ClientProperty.
static const std::string BACKPRESSURE_BACKOFF_TIMEOUT_MILLIS
Control the maximum timeout in millis to wait for an invocation space to be available.
A client property is a configuration for hazelcast client.
const char * get_system_property() const
Gets the system environment property value of the property.
Hazelcast cluster interface.
Base class for all exception originated from Hazelcast methods.
boost::future< bool > is_shutdown()
Returns.
boost::future< bool > is_terminated()
Returns.
void shutdown()
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will...
Listener object for listening lifecycle events of hazelcast instance.
The Client interface allows to get information about a connected client's socket address,...
A service to execute SQL statements.
Provides a context to do transactional operations; so beginning/committing transactions,...
Contains the configuration for a Hazelcast transaction.
CP Subsystem is a component of Hazelcast that builds a strongly consistent layer for a set of distrib...
An arbitrary precision and scale floating point number.
A date-time without a time-zone in the ISO-8601 calendar system, such as.
A date without a time-zone in the ISO-8601 calendar system, such as.
uint8_t day_of_month
minimum value is 1 maximum value is 31
int32_t year
minimum value is -999999999 maximum value is 999999999
uint8_t month
minimum value is 1 maximum value is 12
A time without a time-zone in the ISO-8601 calendar system, such as.
uint8_t hours
the hour-of-day to represent, from 0 to 23
uint8_t seconds
the second-of-minute to represent, from 0 to 59
int32_t nanos
the nanosecond-of-second to represent, from 0 to 999,999,999
uint8_t minutes
the minute-of-hour to represent, from 0 to 59
A date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as.
int32_t zone_offset_in_seconds
The offset from UTC/Greenwich.
local_date_time date_time
The local date-time.