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"
49 #ifndef HAZELCAST_VERSION
50 #define HAZELCAST_VERSION "NOT_FOUND"
55 hazelcast_client::hazelcast_client() : client_impl_(new impl::hazelcast_client_instance_impl(client_config())) {
56 client_impl_->start();
59 hazelcast_client::hazelcast_client(client_config config) : client_impl_(
60 new impl::hazelcast_client_instance_impl(std::move(config))) {
61 client_impl_->start();
64 const std::string &hazelcast_client::get_name()
const {
65 return client_impl_->get_name();
69 return client_impl_->get_client_config();
73 return client_impl_->new_transaction_context();
77 return client_impl_->new_transaction_context(options);
80 cluster &hazelcast_client::get_cluster() {
81 return client_impl_->get_cluster();
88 bool hazelcast_client::remove_lifecycle_listener(
const boost::uuids::uuid ®istration_id) {
89 return client_impl_->remove_lifecycle_listener(registration_id);
92 boost::future<void> hazelcast_client::shutdown() {
93 return boost::async([=]() { client_impl_->shutdown(); });
96 spi::lifecycle_service &hazelcast_client::get_lifecycle_service() {
97 return client_impl_->get_lifecycle_service();
101 return client_impl_->get_local_endpoint();
104 hazelcast_client::~hazelcast_client() =
default;
107 return client_impl_->get_cp_subsystem();
110 const boost::string_view version() {
111 return HAZELCAST_VERSION;
115 std::atomic<int32_t> hazelcast_client_instance_impl::CLIENT_ID(0);
117 hazelcast_client_instance_impl::hazelcast_client_instance_impl(client_config config)
118 : client_config_(std::move(config)), client_properties_(client_config_.get_properties()),
119 client_context_(*this),
120 serialization_service_(client_config_.get_serialization_config()),
121 cluster_service_(client_context_),
122 transaction_manager_(client_context_), cluster_(cluster_service_),
123 lifecycle_service_(client_context_, client_config_.get_lifecycle_listeners()),
124 proxy_manager_(client_context_),
125 id_(++CLIENT_ID), random_generator_(std::random_device{}()),
126 uuid_generator_{random_generator_},
127 cp_subsystem_(client_context_), proxy_session_manager_(client_context_) {
128 auto &name = client_config_.get_instance_name();
130 instance_name_ = *name;
132 std::ostringstream out;
133 out <<
"hz.client_" << id_;
134 instance_name_ = out.str();
137 auto logger_config = client_config_.get_logger_config();
138 logger_ = std::make_shared<logger>(instance_name_, client_config_.get_cluster_name(),
139 logger_config.level(), logger_config.handler());
141 execution_service_ = init_execution_service();
143 initalize_near_cache_manager();
145 int32_t maxAllowedConcurrentInvocations = client_properties_.get_integer(
146 client_properties_.get_max_concurrent_invocations());
147 int64_t backofftimeoutMs = client_properties_.get_long(
148 client_properties_.get_backpressure_backoff_timeout_millis());
149 bool isBackPressureEnabled = maxAllowedConcurrentInvocations != INT32_MAX;
150 call_id_sequence_ = spi::impl::sequence::CallIdFactory::new_call_id_sequence(isBackPressureEnabled,
151 maxAllowedConcurrentInvocations,
154 auto address_provider = create_address_provider();
156 connection_manager_ = std::make_shared<connection::ClientConnectionManagerImpl>(
157 client_context_, std::move(address_provider));
159 cluster_listener_.reset(
new spi::impl::listener::cluster_view_listener(client_context_));
161 partition_service_.reset(
new spi::impl::ClientPartitionServiceImpl(client_context_));
163 invocation_service_.reset(
new spi::impl::ClientInvocationServiceImpl(client_context_));
165 listener_service_ = init_listener_service();
167 proxy_manager_.init();
169 lock_reference_id_generator_.reset(
new impl::ClientLockReferenceIdGenerator());
171 statistics_.reset(
new statistics::Statistics(client_context_));
174 hazelcast_client_instance_impl::~hazelcast_client_instance_impl() {
178 void hazelcast_client_instance_impl::start() {
179 lifecycle_service_.fire_lifecycle_event(lifecycle_event::STARTING);
182 if (!lifecycle_service_.start()) {
183 lifecycle_service_.shutdown();
184 BOOST_THROW_EXCEPTION(exception::illegal_state(
"hazelcast_client",
185 "hazelcast_client could not be started!"));
187 }
catch (std::exception &) {
188 lifecycle_service_.shutdown();
193 client_config &hazelcast_client_instance_impl::get_client_config() {
194 return client_config_;
197 cluster &hazelcast_client_instance_impl::get_cluster() {
202 hazelcast_client_instance_impl::add_lifecycle_listener(lifecycle_listener &&lifecycle_listener) {
203 return lifecycle_service_.add_listener(std::move(lifecycle_listener));
206 bool hazelcast_client_instance_impl::remove_lifecycle_listener(
const boost::uuids::uuid ®istration_id) {
207 return lifecycle_service_.remove_listener(registration_id);
210 void hazelcast_client_instance_impl::shutdown() {
211 lifecycle_service_.shutdown();
214 transaction_context hazelcast_client_instance_impl::new_transaction_context() {
215 transaction_options defaultOptions;
216 return new_transaction_context(defaultOptions);
220 hazelcast_client_instance_impl::new_transaction_context(
const transaction_options &options) {
221 return transaction_context(transaction_manager_, options);
224 internal::nearcache::NearCacheManager &hazelcast_client_instance_impl::get_near_cache_manager() {
225 return *near_cache_manager_;
228 serialization::pimpl::SerializationService &hazelcast_client_instance_impl::get_serialization_service() {
229 return serialization_service_;
232 const protocol::ClientExceptionFactory &hazelcast_client_instance_impl::get_exception_factory()
const {
233 return exception_factory_;
236 std::shared_ptr<spi::impl::listener::listener_service_impl>
237 hazelcast_client_instance_impl::init_listener_service() {
238 auto eventThreadCount = client_properties_.get_integer(client_properties_.get_event_thread_count());
239 return std::make_shared<spi::impl::listener::listener_service_impl>(client_context_, eventThreadCount);
242 std::shared_ptr<spi::impl::ClientExecutionServiceImpl>
243 hazelcast_client_instance_impl::init_execution_service() {
244 return std::make_shared<spi::impl::ClientExecutionServiceImpl>(instance_name_, client_properties_,
245 client_config_.get_executor_pool_size(),
249 void hazelcast_client_instance_impl::on_cluster_restart() {
250 HZ_LOG(*logger_, info,
251 "Clearing local state of the client, because of a cluster restart");
253 near_cache_manager_->clear_all_near_caches();
255 cluster_service_.clear_member_list();
258 std::unique_ptr<connection::AddressProvider> hazelcast_client_instance_impl::create_address_provider() {
259 config::client_network_config &networkConfig = get_client_config().get_network_config();
260 config::client_aws_config &awsConfig = networkConfig.get_aws_config();
261 config::cloud_config &cloudConfig = networkConfig.get_cloud_config();
263 auto addresses = networkConfig.get_addresses();
264 bool addressListProvided = !addresses.empty();
265 bool awsDiscoveryEnabled = awsConfig.is_enabled();
266 bool cloud_enabled = cloudConfig.enabled;
268 check_discovery_configuration_consistency(addressListProvided, awsDiscoveryEnabled, cloud_enabled);
270 auto connect_timeout = networkConfig.get_connection_timeout();
272 auto cloud_provider = std::make_shared<spi::impl::discovery::cloud_discovery>(cloudConfig,
273 client_properties_.get_string(client_properties_.cloud_base_url()),
275 return std::unique_ptr<connection::AddressProvider>(
276 new spi::impl::discovery::remote_address_provider([=]() {
277 return cloud_provider->get_addresses();
281 if (awsDiscoveryEnabled) {
282 auto aws_addr_provider = std::make_shared<aws::aws_client>(connect_timeout, awsConfig,
283 client_properties_, *logger_);
284 return std::unique_ptr<connection::AddressProvider>(
285 new spi::impl::discovery::remote_address_provider([=]() {
286 return aws_addr_provider->get_addresses();
287 }, !awsConfig.is_inside_aws()));
290 return std::unique_ptr<connection::AddressProvider>(
291 new spi::impl::DefaultAddressProvider(networkConfig));
294 const std::string &hazelcast_client_instance_impl::get_name()
const {
295 return instance_name_;
298 spi::lifecycle_service &hazelcast_client_instance_impl::get_lifecycle_service() {
299 return lifecycle_service_;
302 const std::shared_ptr<ClientLockReferenceIdGenerator> &
303 hazelcast_client_instance_impl::get_lock_reference_id_generator()
const {
304 return lock_reference_id_generator_;
307 spi::ProxyManager &hazelcast_client_instance_impl::get_proxy_manager() {
308 return proxy_manager_;
311 void hazelcast_client_instance_impl::initalize_near_cache_manager() {
312 near_cache_manager_.reset(
313 new internal::nearcache::NearCacheManager(execution_service_, serialization_service_,
317 local_endpoint hazelcast_client_instance_impl::get_local_endpoint()
const {
318 return cluster_service_.get_local_client();
322 boost::shared_future<std::shared_ptr<imap>>
323 hazelcast_client_instance_impl::get_distributed_object(
const std::string &name) {
324 auto nearCacheConfig = client_config_.get_near_cache_config(name);
325 if (nearCacheConfig) {
326 return proxy_manager_.get_or_create_proxy<map::NearCachedClientMapProxy<
327 serialization::pimpl::data, serialization::pimpl::data >>(
328 imap::SERVICE_NAME, name).then(boost::launch::sync,
329 [=](boost::shared_future<std::shared_ptr<
330 map::NearCachedClientMapProxy<
331 serialization::pimpl::data, serialization::pimpl::data>>>
333 return std::static_pointer_cast<imap>(f.get());
336 return proxy_manager_.get_or_create_proxy<imap>(imap::SERVICE_NAME, name);
340 const std::shared_ptr<logger> &hazelcast_client_instance_impl::get_logger()
const {
344 boost::uuids::uuid hazelcast_client_instance_impl::random_uuid() {
345 std::lock_guard<std::mutex> g(uuid_generator_lock_);
346 return uuid_generator_();
349 cp::cp_subsystem &hazelcast_client_instance_impl::get_cp_subsystem() {
350 return cp_subsystem_;
353 void hazelcast_client_instance_impl::check_discovery_configuration_consistency(
bool address_list_provided,
355 bool cloud_enabled) {
357 if (address_list_provided) count++;
358 if (aws_enabled) count++;
359 if (cloud_enabled) count++;
361 throw exception::illegal_state(
362 "hazelcast_client_instance_impl::check_discovery_configuration_consistency",
363 (boost::format(
"Only one discovery method can be enabled at a time. cluster "
364 "members given explicitly : %1%, aws discovery: %2%, hazelcast.cloud enabled : %3%")
365 % address_list_provided % aws_enabled % cloud_enabled).str());
369 BaseEventHandler::~BaseEventHandler() =
default;
371 BaseEventHandler::BaseEventHandler() : logger_(nullptr) {
374 void BaseEventHandler::set_logger(logger *lg) {
375 BaseEventHandler::logger_ = lg;
378 logger *BaseEventHandler::get_logger()
const {
383 constexpr
int address::ID;
385 address::address() : host_(
"localhost"), type_(IPV4), scope_id_(0) {
389 : host_(std::move(url)), port_(port), type_(IPV4), scope_id_(0) {
392 address::address(std::string hostname,
int port,
unsigned long scope_id) : host_(std::move(hostname)),
394 type_(IPV6), scope_id_(scope_id) {
398 return rhs.port_ == port_ && rhs.type_ == type_ && 0 == rhs.host_.compare(host_);
402 return !(*
this == rhs);
413 bool address::operator<(
const address &rhs)
const {
414 if (host_ < rhs.host_) {
417 if (rhs.host_ < host_) {
420 if (port_ < rhs.port_) {
423 if (rhs.port_ < port_) {
426 return type_ < rhs.type_;
430 return type_ == IPV4;
433 unsigned long address::get_scope_id()
const {
437 std::string address::to_string()
const {
438 std::ostringstream out;
443 std::ostream &operator<<(std::ostream &stream,
const address &address) {
444 return stream << address.to_string();
447 namespace serialization {
448 int32_t hz_serializer<address>::get_factory_id() {
452 int32_t hz_serializer<address>::get_class_id() {
456 void hz_serializer<address>::write_data(
const address &
object, object_data_output &out) {
457 out.write<int32_t>(
object.port_);
458 out.write<
byte>(
object.type_);
459 out.write(
object.host_);
462 address hz_serializer<address>::read_data(object_data_input &in) {
464 object.port_ = in.read<int32_t>();
465 object.type_ = in.read<
byte>();
466 object.host_ = in.read<std::string>();
471 iexecutor_service::iexecutor_service(
const std::string &name, spi::ClientContext *context) : ProxyImpl(
472 SERVICE_NAME, name, context), consecutive_submits_(0), last_submit_time_(0) {
476 iexecutor_service::select_members(
const member_selector &member_selector) {
477 std::vector<member> selected;
478 std::vector<member> members = get_context().get_client_cluster_service().get_member_list();
479 for (
const member &member : members) {
480 if (member_selector.select(member)) {
481 selected.push_back(member);
484 if (selected.empty()) {
485 BOOST_THROW_EXCEPTION(exception::rejected_execution(
"IExecutorService::selectMembers",
486 "No member could be selected with member selector"));
491 std::pair<boost::future<protocol::ClientMessage>, std::shared_ptr<spi::impl::ClientInvocation>>
492 iexecutor_service::invoke_on_target(protocol::ClientMessage &&request, boost::uuids::uuid target) {
494 std::shared_ptr<spi::impl::ClientInvocation> clientInvocation = spi::impl::ClientInvocation::create(
495 get_context(), request, get_name(), target);
496 return std::make_pair(clientInvocation->invoke(), clientInvocation);
497 }
catch (exception::iexception &) {
498 util::exception_util::rethrow(std::current_exception());
500 return std::pair<boost::future<protocol::ClientMessage>, std::shared_ptr<spi::impl::ClientInvocation>>();
503 std::pair<boost::future<protocol::ClientMessage>, std::shared_ptr<spi::impl::ClientInvocation>>
504 iexecutor_service::invoke_on_partition_owner(protocol::ClientMessage &&request,
int partition_id) {
506 std::shared_ptr<spi::impl::ClientInvocation> clientInvocation = spi::impl::ClientInvocation::create(
507 get_context(), request, get_name(), partition_id);
508 return std::make_pair(clientInvocation->invoke(), clientInvocation);
509 }
catch (exception::iexception &) {
510 util::exception_util::rethrow(std::current_exception());
512 return std::pair<boost::future<protocol::ClientMessage>, std::shared_ptr<spi::impl::ClientInvocation>>();
515 bool iexecutor_service::is_sync_computation(
bool prevent_sync) {
516 int64_t now = util::current_time_millis();
518 int64_t last = last_submit_time_;
519 last_submit_time_ = now;
521 if (last + MIN_TIME_RESOLUTION_OF_CONSECUTIVE_SUBMITS < now) {
522 consecutive_submits_ = 0;
526 return !prevent_sync && (consecutive_submits_++ % MAX_CONSECUTIVE_SUBMITS == 0);
529 address iexecutor_service::get_member_address(
const member &member) {
530 auto m = get_context().get_client_cluster_service().get_member(member.get_uuid());
532 throw (exception::exception_builder<exception::hazelcast_>(
533 "IExecutorService::getMemberAddress(Member)") << member <<
" is not available!").build();
535 return m->get_address();
538 int iexecutor_service::random_partition_id() {
539 auto &partitionService = get_context().get_partition_service();
540 return rand() % partitionService.get_partition_count();
544 auto request = protocol::codec::executorservice_shutdown_encode(
550 auto request = protocol::codec::executorservice_isshutdown_encode(
552 return invoke_and_get_future<bool>(
561 const std::string client_properties::PROP_HEARTBEAT_TIMEOUT_DEFAULT =
"60000";
563 const std::string client_properties::PROP_HEARTBEAT_INTERVAL_DEFAULT =
"5000";
565 const std::string client_properties::PROP_REQUEST_RETRY_COUNT_DEFAULT =
"20";
567 const std::string client_properties::PROP_REQUEST_RETRY_WAIT_TIME_DEFAULT =
"1";
570 const std::string client_properties::PROP_AWS_MEMBER_PORT_DEFAULT =
"5701";
573 const std::string client_properties::INVOCATION_RETRY_PAUSE_MILLIS_DEFAULT =
"1000";
576 const std::string client_properties::INVOCATION_TIMEOUT_SECONDS_DEFAULT =
"120";
579 const std::string client_properties::EVENT_THREAD_COUNT_DEFAULT =
"5";
581 const std::string client_properties::INTERNAL_EXECUTOR_POOL_SIZE =
"hazelcast.client.internal.executor.pool.size";
582 const std::string client_properties::INTERNAL_EXECUTOR_POOL_SIZE_DEFAULT =
"3";
585 const std::string client_properties::SHUFFLE_MEMBER_LIST_DEFAULT =
"true";
588 const std::string client_properties::MAX_CONCURRENT_INVOCATIONS_DEFAULT = util::IOUtil::to_string<int32_t>(
592 const std::string client_properties::BACKPRESSURE_BACKOFF_TIMEOUT_MILLIS_DEFAULT =
"-1";
595 const std::string client_properties::STATISTICS_ENABLED_DEFAULT =
"false";
598 const std::string client_properties::STATISTICS_PERIOD_SECONDS_DEFAULT =
"3";
600 client_property::client_property(
const std::string &name,
const std::string &default_value)
601 : name_(name), default_value_(default_value) {
604 const std::string &client_property::get_name()
const {
608 const std::string &client_property::get_default_value()
const {
609 return default_value_;
613 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
614 #pragma warning(push)
615 #pragma warning(disable: 4996)
617 return std::getenv(name_.c_str());
618 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
623 client_properties::client_properties(
const std::unordered_map<std::string, std::string> &properties)
624 : heartbeat_timeout_(PROP_HEARTBEAT_TIMEOUT, PROP_HEARTBEAT_TIMEOUT_DEFAULT),
625 heartbeat_interval_(PROP_HEARTBEAT_INTERVAL, PROP_HEARTBEAT_INTERVAL_DEFAULT),
626 retry_count_(PROP_REQUEST_RETRY_COUNT, PROP_REQUEST_RETRY_COUNT_DEFAULT),
627 retry_wait_time_(PROP_REQUEST_RETRY_WAIT_TIME, PROP_REQUEST_RETRY_WAIT_TIME_DEFAULT),
628 aws_member_port_(PROP_AWS_MEMBER_PORT, PROP_AWS_MEMBER_PORT_DEFAULT),
629 invocation_retry_pause_millis_(INVOCATION_RETRY_PAUSE_MILLIS,
630 INVOCATION_RETRY_PAUSE_MILLIS_DEFAULT),
631 invocation_timeout_seconds_(INVOCATION_TIMEOUT_SECONDS,
632 INVOCATION_TIMEOUT_SECONDS_DEFAULT),
633 event_thread_count_(EVENT_THREAD_COUNT, EVENT_THREAD_COUNT_DEFAULT),
634 internal_executor_pool_size_(INTERNAL_EXECUTOR_POOL_SIZE,
635 INTERNAL_EXECUTOR_POOL_SIZE_DEFAULT),
636 shuffle_member_list_(SHUFFLE_MEMBER_LIST, SHUFFLE_MEMBER_LIST_DEFAULT),
637 max_concurrent_invocations_(MAX_CONCURRENT_INVOCATIONS,
638 MAX_CONCURRENT_INVOCATIONS_DEFAULT),
639 backpressure_backoff_timeout_millis_(BACKPRESSURE_BACKOFF_TIMEOUT_MILLIS,
640 BACKPRESSURE_BACKOFF_TIMEOUT_MILLIS_DEFAULT),
641 statistics_enabled_(STATISTICS_ENABLED, STATISTICS_ENABLED_DEFAULT),
642 statistics_period_seconds_(STATISTICS_PERIOD_SECONDS, STATISTICS_PERIOD_SECONDS_DEFAULT),
643 backup_timeout_millis_(OPERATION_BACKUP_TIMEOUT_MILLIS, OPERATION_BACKUP_TIMEOUT_MILLIS_DEFAULT),
644 fail_on_indeterminate_state_(FAIL_ON_INDETERMINATE_OPERATION_STATE,
645 FAIL_ON_INDETERMINATE_OPERATION_STATE_DEFAULT),
646 cloud_base_url_(CLOUD_URL_BASE, CLOUD_URL_BASE_DEFAULT),
647 properties_map_(properties) {
650 const client_property &client_properties::get_heartbeat_timeout()
const {
651 return heartbeat_timeout_;
654 const client_property &client_properties::get_heartbeat_interval()
const {
655 return heartbeat_interval_;
658 const client_property &client_properties::get_aws_member_port()
const {
659 return aws_member_port_;
662 const client_property &client_properties::get_invocation_retry_pause_millis()
const {
663 return invocation_retry_pause_millis_;
666 const client_property &client_properties::get_invocation_timeout_seconds()
const {
667 return invocation_timeout_seconds_;
670 const client_property &client_properties::get_event_thread_count()
const {
671 return event_thread_count_;
674 const client_property &client_properties::get_internal_executor_pool_size()
const {
675 return internal_executor_pool_size_;
678 const client_property &client_properties::get_shuffle_member_list()
const {
679 return shuffle_member_list_;
682 const client_property &client_properties::get_max_concurrent_invocations()
const {
683 return max_concurrent_invocations_;
686 const client_property &client_properties::get_backpressure_backoff_timeout_millis()
const {
687 return backpressure_backoff_timeout_millis_;
690 const client_property &client_properties::get_statistics_enabled()
const {
691 return statistics_enabled_;
694 const client_property &client_properties::get_statistics_period_seconds()
const {
695 return statistics_period_seconds_;
699 std::unordered_map<std::string, std::string>::const_iterator valueIt = properties_map_.find(
700 property.get_name());
701 if (valueIt != properties_map_.end()) {
702 return valueIt->second;
705 const char *value =
property.get_system_property();
710 return property.get_default_value();
714 return util::IOUtil::to_value<bool>(
get_string(property));
718 return util::IOUtil::to_value<int32_t>(
get_string(property));
722 return util::IOUtil::to_value<int64_t>(
get_string(property));
725 const client_property &client_properties::backup_timeout_millis()
const {
726 return backup_timeout_millis_;
729 const client_property &client_properties::fail_on_indeterminate_state()
const {
730 return fail_on_indeterminate_state_;
733 const client_property &client_properties::cloud_base_url()
const {
734 return cloud_base_url_;
737 namespace exception {
738 iexception::iexception(
const std::string &exception_name,
const std::string &source,
739 const std::string &message,
const std::string &details, int32_t error_no,
740 std::exception_ptr cause,
bool is_runtime,
bool retryable)
741 : src_(source), msg_(message), details_(details), error_code_(error_no), cause_(cause),
742 runtime_exception_(is_runtime), retryable_(retryable), report_((boost::format(
743 "%1% {%2%. Error code:%3%, Details:%4%.} at %5%.") % exception_name % message % error_no %
744 details % source).str()) {
747 iexception::~iexception() noexcept = default;
750 return report_.c_str();
753 const std::string &iexception::get_source()
const {
757 const std::string &iexception::get_message()
const {
761 std::ostream &operator<<(std::ostream &os,
const iexception &exception) {
762 os << exception.what();
766 const std::string &iexception::get_details()
const {
770 int32_t iexception::get_error_code()
const {
774 bool iexception::is_runtime()
const {
775 return runtime_exception_;
778 bool iexception::is_retryable()
const {
782 iexception::iexception() =
default;
784 retryable_hazelcast::retryable_hazelcast(
const std::string &source,
785 const std::string &message,
786 const std::string &details,
787 std::exception_ptr cause)
788 : retryable_hazelcast(
789 "retryable_hazelcast", protocol::RETRYABLE_HAZELCAST, source, message, details, cause, true,
792 retryable_hazelcast::retryable_hazelcast(
const std::string &error_name, int32_t error_code,
793 const std::string &source,
794 const std::string &message,
795 const std::string &details, std::exception_ptr cause,
796 bool runtime,
bool retryable) : hazelcast_(error_name,
805 member_left::member_left(
const std::string &source,
const std::string &message,
806 const std::string &details, std::exception_ptr cause)
807 : execution(
"member_left", protocol::MEMBER_LEFT, source, message, details,
808 cause, false, true) {}
810 consistency_lost::consistency_lost(
const std::string &source,
const std::string &message,
811 const std::string &details, std::exception_ptr cause)
812 : hazelcast_(
"consistency_lost", protocol::CONSISTENCY_LOST_EXCEPTION, source, message,
813 details, cause, true, false) {}
817 boost::future<client::hazelcast_client> new_client() {
818 return boost::async([]() {
return client::hazelcast_client(); });
821 boost::future<client::hazelcast_client> new_client(client::client_config config) {
823 [](client::client_config &&c) {
824 return client::hazelcast_client(std::move(c));
833 std::size_t seed = 0;
834 boost::hash_combine(seed, address.get_host());
835 boost::hash_combine(seed, address.get_port());
836 boost::hash_combine(seed, address.type_);
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,...
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...