Hazelcast C++ Client
Hazelcast C++ Client Library
hazelcast::client::client_config Class Reference

hazelcast_client configuration class. More...

#include <client_config.h>

Public Member Functions

 client_config ()
 Constructor with default values. More...
 
 client_config (const client_config &rhs)=delete
 
client_configoperator= (const client_config &rhs)=delete
 
 client_config (client_config &&rhs)
 
client_configoperator= (client_config &&rhs)
 
const std::string & get_cluster_name () const
 Returns the configured cluster name. More...
 
client_configset_cluster_name (const std::string &cluster_name)
 
client_configset_credentials (const std::shared_ptr< security::credentials > &credential)
 There are two types of credentials you can provide, \username_password_credentials and \token_credentials. More...
 
const std::shared_ptr< security::credentials > & get_credentials () const
 
client_configset_redo_operation (bool redo_operation)
 If true, client will redo the operations that were executing on the server and client lost the connection. More...
 
bool is_redo_operation () const
 see setRedoOperation returns redoOperation
 
client_configset_socket_interceptor (socket_interceptor &&interceptor)
 Will be called with the Socket, each time client creates a connection to any Member. More...
 
const socket_interceptorget_socket_interceptor () const
 Will be called with the Socket, each time client creates a connection to any Member.
 
client_configadd_listener (lifecycle_listener &&listener)
 Adds a listener to configuration to be registered when hazelcast_client starts. More...
 
const std::vector< lifecycle_listener > & get_lifecycle_listeners () const
 
client_configadd_listener (membership_listener &&listener)
 Adds a listener to configuration to be registered when hazelcast_client starts. More...
 
const std::vector< membership_listener > & get_membership_listeners () const
 Returns registered membershipListeners. More...
 
load_balancerget_load_balancer ()
 Used to distribute the operations to multiple Endpoints. More...
 
client_configset_load_balancer (load_balancer &&load_balancer)
 Used to distribute the operations to multiple connections. More...
 
serialization_configget_serialization_config ()
 
client_configset_serialization_config (serialization_config const &serialization_config)
 SerializationConfig is used to. More...
 
const std::unordered_map< std::string, std::string > & get_properties () const
 Gets a reference to properties map. More...
 
client_configset_property (const std::string &name, const std::string &value)
 Sets the value of a named property. More...
 
client_configadd_reliable_topic_config (const config::reliable_topic_config &reliable_topic_config)
 Adds a ClientReliableTopicConfig. More...
 
const config::reliable_topic_configget_reliable_topic_config (const std::string &name)
 Gets the ClientReliableTopicConfig for a given reliable topic name. More...
 
client_configadd_near_cache_config (const config::near_cache_config &near_cache_config)
 Helper method to add a new NearCacheConfig. More...
 
const config::near_cache_configget_near_cache_config (const std::string &name) const
 Gets the NearCacheConfig configured for the map / cache with name. More...
 
config::client_network_configget_network_config ()
 Gets {}. More...
 
client_configset_network_config (const config::client_network_config &network_config)
 Sets {}. More...
 
const boost::optional< std::string > & get_instance_name () const
 
client_configset_instance_name (const std::string &instance_name)
 
int32_t get_executor_pool_size () const
 Pool size for internal ExecutorService which handles responses etc. More...
 
void set_executor_pool_size (int32_t executor_pool_size)
 Sets Client side Executor pool size. More...
 
config::client_connection_strategy_configget_connection_strategy_config ()
 
client_configset_connection_strategy_config (const config::client_connection_strategy_config &connection_strategy_config)
 
const config::client_flake_id_generator_configfind_flake_id_generator_config (const std::string &name)
 Returns a {} configuration for the given flake ID generator name. More...
 
const config::client_flake_id_generator_configget_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 configurations. More...
 
client_configadd_flake_id_generator_config (const config::client_flake_id_generator_config &config)
 Adds a flake ID generator configuration. More...
 
config::logger_configget_logger_config ()
 
const std::unordered_set< std::string > & get_labels () const
 
client_configset_labels (const std::unordered_set< std::string > &labels)
 
client_configadd_label (const std::string &label)
 
client_configbackup_acks_enabled (bool enabled)
 This feature reduces number of hops and increase performance for smart clients. More...
 
bool backup_acks_enabled ()
 Note that backup acks to client can be enabled only for smart client. More...
 

Friends

class connection::ClientConnectionManagerImpl
 
class reliable_topic
 

Detailed Description

hazelcast_client configuration class.

Definition at line 107 of file client_config.h.

Constructor & Destructor Documentation

◆ client_config()

hazelcast::client::client_config::client_config ( )

Constructor with default values.

smart(true) redoOperation(false) connectionAttemptLimit(2) attemptPeriod(3000) defaultLoadBalancer: round robin load balancer

Definition at line 1060 of file config.cpp.

1061  : cluster_name_("dev")
1062  , redo_operation_(false)
1063  , socket_interceptor_()
1064  , executor_pool_size_(-1)
1065 {}

Member Function Documentation

◆ add_flake_id_generator_config()

client_config & hazelcast::client::client_config::add_flake_id_generator_config ( const config::client_flake_id_generator_config config)

Adds a flake ID generator configuration.

The configuration is saved under the config name, which may be a pattern with which the configuration will be obtained in the future.

Parameters
configthe flake ID configuration
Returns
this config instance

Definition at line 1335 of file config.cpp.

1337 {
1338  flake_id_generator_config_map_.emplace(config.get_name(), config);
1339  return *this;
1340 }

◆ add_listener() [1/2]

client_config & hazelcast::client::client_config::add_listener ( lifecycle_listener &&  listener)

Adds a listener to configuration to be registered when hazelcast_client starts.

Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. otherwise it will slow down the system.

Warning 2: Do not make a call to hazelcast. It can cause deadlock.

Parameters
listenerlifecycle_listener
Returns
itself ClientConfig

Definition at line 1116 of file config.cpp.

1117 {
1118  lifecycle_listeners_.emplace_back(std::move(listener));
1119  return *this;
1120 }

◆ add_listener() [2/2]

client_config & hazelcast::client::client_config::add_listener ( membership_listener &&  listener)

Adds a listener to configuration to be registered when hazelcast_client starts.

Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. otherwise it will slow down the system.

Warning 2: Do not make a call to hazelcast. It can cause deadlock.

Parameters
listenerMembershipListener
Returns
itself ClientConfig

Definition at line 1123 of file config.cpp.

1124 {
1125  membership_listeners_.emplace_back(std::move(listener));
1126  return *this;
1127 }

◆ add_near_cache_config()

client_config & hazelcast::client::client_config::add_near_cache_config ( const config::near_cache_config near_cache_config)

Helper method to add a new NearCacheConfig.

Parameters
nearCacheConfigNearCacheConfig to be added
Returns
configured client_config for chaining
See also
NearCacheConfig

Memory ownership of the config is passed to the client config

Definition at line 1221 of file config.cpp.

1223 {
1224  near_cache_config_map_.emplace(near_cache_config.get_name(),
1225  near_cache_config);
1226  return *this;
1227 }

◆ add_reliable_topic_config()

client_config & hazelcast::client::client_config::add_reliable_topic_config ( const config::reliable_topic_config reliable_topic_config)

Adds a ClientReliableTopicConfig.

Parameters
reliableTopicConfigthe ReliableTopicConfig to add
Returns
configured {} for chaining

Definition at line 1182 of file config.cpp.

1184 {
1185  reliable_topic_config_map_[reliable_topic_config.get_name()] =
1186  reliable_topic_config;
1187  return *this;
1188 }

◆ backup_acks_enabled() [1/2]

bool hazelcast::client::client_config::backup_acks_enabled ( )

Note that backup acks to client can be enabled only for smart client.

This config has no effect for unisocket clients.

Returns
true if backup acknowledgements comes to client

Definition at line 1383 of file config.cpp.

1384 {
1385  return backup_acks_enabled_;
1386 }

◆ backup_acks_enabled() [2/2]

client_config & hazelcast::client::client_config::backup_acks_enabled ( bool  enabled)

This feature reduces number of hops and increase performance for smart clients.

It is enabled by default for smart clients. This config has no effect for unisocket clients.

Parameters
enabledenables client to get backup acknowledgements directly from the member that backups are applied
Returns
configured \ClientConfig for chaining

Definition at line 1376 of file config.cpp.

1377 {
1378  backup_acks_enabled_ = enabled;
1379  return *this;
1380 }

◆ find_flake_id_generator_config()

const config::client_flake_id_generator_config * hazelcast::client::client_config::find_flake_id_generator_config ( const std::string &  name)

Returns a {} configuration for the given flake ID generator name.

The name is matched by pattern to the configuration and by stripping the partition ID qualifier from the given

name

. If there is no config found by the name, it will return the configuration with the name

"default"

.

Parameters
namename of the flake ID generator config
Returns
the flake ID generator configuration
Exceptions
ConfigurationExceptionif ambiguous configurations are found
See also
StringPartitioningStrategy::getBaseName(std::string)
#setConfigPatternMatcher(ConfigPatternMatcher)
#getConfigPatternMatcher()

Definition at line 1296 of file config.cpp.

1297 {
1298  std::string baseName =
1299  internal::partition::strategy::StringPartitioningStrategy::get_base_name(
1300  name);
1301  auto config = internal::config::ConfigUtils::lookup_by_pattern<
1302  config::client_flake_id_generator_config>(
1303  config_pattern_matcher_, flake_id_generator_config_map_, baseName);
1304  if (config) {
1305  return config;
1306  }
1307  return get_flake_id_generator_config("default");
1308 }
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:1311

◆ get_cluster_name()

const std::string & hazelcast::client::client_config::get_cluster_name ( ) const

Returns the configured cluster name.

The name is sent as part of client authentication message and may be verified on the member.

Returns
the configured cluster name

Definition at line 1343 of file config.cpp.

1344 {
1345  return cluster_name_;
1346 }

◆ get_executor_pool_size()

int32_t hazelcast::client::client_config::get_executor_pool_size ( ) const

Pool size for internal ExecutorService which handles responses etc.

Returns
int Executor pool size.

Definition at line 1270 of file config.cpp.

1271 {
1272  return executor_pool_size_;
1273 }

◆ get_flake_id_generator_config()

const config::client_flake_id_generator_config * hazelcast::client::client_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 configurations.

The configuration is found by matching the the configuration name pattern to the provided

name

without the partition qualifier (the part of the name after

'@'

). If no configuration matches, it will create one by cloning the

"default"

configuration and add it to the configuration collection.

This method is intended to easily and fluently create and add configurations more specific than the default configuration without explicitly adding it by invoking {}. Because it adds new configurations if they are not already present, this method is intended to be used before this config is used to create a hazelcast instance. Afterwards, newly added configurations may be ignored.

Parameters
namename of the flake ID generator config
Returns
the cache configuration
Exceptions
ConfigurationExceptionif ambiguous configurations are found
See also
StringPartitioningStrategy::getBaseName(std::string)

Definition at line 1311 of file config.cpp.

1312 {
1313  std::string baseName =
1314  internal::partition::strategy::StringPartitioningStrategy::get_base_name(
1315  name);
1316  auto config = internal::config::ConfigUtils::lookup_by_pattern<
1317  config::client_flake_id_generator_config>(
1318  config_pattern_matcher_, flake_id_generator_config_map_, baseName);
1319  if (config) {
1320  return config;
1321  }
1322  auto defConfig = flake_id_generator_config_map_.find("default");
1323  if (defConfig == flake_id_generator_config_map_.end()) {
1324  flake_id_generator_config_map_.emplace(
1325  "default", config::client_flake_id_generator_config("default"));
1326  }
1327  defConfig = flake_id_generator_config_map_.find("default");
1328  config::client_flake_id_generator_config new_config = defConfig->second;
1329  new_config.set_name(name);
1330  flake_id_generator_config_map_.emplace(name, std::move(new_config));
1331  return &flake_id_generator_config_map_.find(name)->second;
1332 }

◆ get_lifecycle_listeners()

const std::vector< lifecycle_listener > & hazelcast::client::client_config::get_lifecycle_listeners ( ) const
Returns
registered lifecycleListeners

Definition at line 1130 of file config.cpp.

1131 {
1132  return lifecycle_listeners_;
1133 }

◆ get_load_balancer()

load_balancer & hazelcast::client::client_config::get_load_balancer ( )

Used to distribute the operations to multiple Endpoints.

Returns
load_balancer

Definition at line 1086 of file config.cpp.

1087 {
1088  if (!load_balancer_) {
1089  auto index = std::make_shared<std::atomic<size_t>>(0);
1090  load_balancer_ = load_balancer().next([=](cluster& c) {
1091  auto members = c.get_members();
1092  if (members.empty()) {
1093  return boost::optional<member>();
1094  }
1095  auto i = index->fetch_add(1);
1096  return boost::make_optional(std::move(members[i % members.size()]));
1097  });
1098  }
1099  return *load_balancer_;
1100 }

◆ get_logger_config()

config::logger_config & hazelcast::client::client_config::get_logger_config ( )
Returns
The logger configuration.

Definition at line 1110 of file config.cpp.

1111 {
1112  return logger_config_;
1113 }

◆ get_membership_listeners()

const std::vector< membership_listener > & hazelcast::client::client_config::get_membership_listeners ( ) const

Returns registered membershipListeners.

Returns
registered membershipListeners

Definition at line 1136 of file config.cpp.

1137 {
1138  return membership_listeners_;
1139 }

◆ get_near_cache_config()

const config::near_cache_config * hazelcast::client::client_config::get_near_cache_config ( const std::string &  name) const

Gets the NearCacheConfig configured for the map / cache with name.

Parameters
namename of the map / cache
Returns
Configured NearCacheConfig
See also
NearCacheConfig

Definition at line 1230 of file config.cpp.

1231 {
1232  auto nearCacheConfig = internal::config::ConfigUtils::lookup_by_pattern(
1233  config_pattern_matcher_, near_cache_config_map_, name);
1234  if (nearCacheConfig) {
1235  return nearCacheConfig;
1236  }
1237 
1238  auto config_it = near_cache_config_map_.find("default");
1239  if (config_it != near_cache_config_map_.end()) {
1240  return &near_cache_config_map_.find("default")->second;
1241  }
1242 
1243  // not needed for c++ client since it is always native memory
1244  // initDefaultMaxSizeForOnHeapMaps(nearCacheConfig);
1245  return nullptr;
1246 }

◆ get_network_config()

config::client_network_config & hazelcast::client::client_config::get_network_config ( )

Gets {}.

Returns
{} com.hazelcast.client.config.client_network_config

Definition at line 1215 of file config.cpp.

1216 {
1217  return network_config_;
1218 }

◆ get_properties()

const std::unordered_map< std::string, std::string > & hazelcast::client::client_config::get_properties ( ) const

Gets a reference to properties map.

Returns
properties map

Definition at line 1169 of file config.cpp.

1170 {
1171  return properties_;
1172 }

◆ get_reliable_topic_config()

const config::reliable_topic_config & hazelcast::client::client_config::get_reliable_topic_config ( const std::string &  name)

Gets the ClientReliableTopicConfig for a given reliable topic name.

Parameters
namethe name of the reliable topic
Returns
the found config. If none is found, a default configured one is returned.

Definition at line 1191 of file config.cpp.

1192 {
1193  auto it = reliable_topic_config_map_.find(name);
1194  if (it != reliable_topic_config_map_.end()) {
1195  return it->second;
1196  }
1197 
1198  return reliable_topic_config_map_
1199  .emplace(name, config::reliable_topic_config{ name })
1200  .first->second;
1201 }

◆ get_serialization_config()

serialization_config & hazelcast::client::client_config::get_serialization_config ( )
Returns
serializationConfig

Definition at line 1155 of file config.cpp.

1156 {
1157  return serialization_config_;
1158 }

◆ set_credentials()

client_config & hazelcast::client::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_credentials.

Returns
itself ClientConfig

Definition at line 1395 of file config.cpp.

1397 {
1398  credentials_ = credential;
1399  return *this;
1400 }

◆ set_executor_pool_size()

void hazelcast::client::client_config::set_executor_pool_size ( int32_t  executor_pool_size)

Sets Client side Executor pool size.

Parameters
executorPoolSizepool size
Returns
configured client_config for chaining

Definition at line 1276 of file config.cpp.

1277 {
1278  client_config::executor_pool_size_ = executor_pool_size;
1279 }

◆ set_load_balancer()

client_config & hazelcast::client::client_config::set_load_balancer ( load_balancer &&  load_balancer)

Used to distribute the operations to multiple connections.

If not set, round robin based load balancer is used

Parameters
load_balancer
Returns
itself ClientConfig

Definition at line 1103 of file config.cpp.

1104 {
1105  this->load_balancer_ = std::move(load_balancer);
1106  return *this;
1107 }

◆ set_network_config()

client_config & hazelcast::client::client_config::set_network_config ( const config::client_network_config network_config)

Sets {}.

Parameters
networkConfig{} to be set configured client_config for chaining com.hazelcast.client.config.client_network_config

Definition at line 1249 of file config.cpp.

1251 {
1252  this->network_config_ = network_config;
1253  return *this;
1254 }

◆ set_property()

client_config & hazelcast::client::client_config::set_property ( const std::string &  name,
const std::string &  value 
)

Sets the value of a named property.

See also
client_properties for properties that is used to configure client
Parameters
nameproperty name
valuevalue of the property
Returns
itself ClientConfig

Definition at line 1175 of file config.cpp.

1176 {
1177  properties_[name] = value;
1178  return *this;
1179 }

◆ set_redo_operation()

client_config & hazelcast::client::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 connection.

This can be because of network, or simply because the member died. However it is not clear whether the application is performed or not. For idempotent operations this is harmless, but for non idempotent ones retrying can cause to undesirable effects. Note that the redo can perform on any member.

If false, the operation will throw io_exception.

Parameters
redoOperationreturn itself ClientConfig

Definition at line 1073 of file config.cpp.

1074 {
1075  this->redo_operation_ = redo_operation;
1076  return *this;
1077 }

◆ set_serialization_config()

client_config & hazelcast::client::client_config::set_serialization_config ( serialization_config const &  serialization_config)

SerializationConfig is used to.

  • set version of portable classes in this client (
    See also
    versioned_portable_serializer)
    Parameters
    serializationConfig
    Returns
    itself ClientConfig

Definition at line 1161 of file config.cpp.

1163 {
1164  this->serialization_config_ = serialization_config;
1165  return *this;
1166 }

◆ set_socket_interceptor()

client_config & hazelcast::client::client_config::set_socket_interceptor ( socket_interceptor &&  interceptor)

Will be called with the Socket, each time client creates a connection to any Member.

Returns
itself ClientConfig

Definition at line 1142 of file config.cpp.

1143 {
1144  this->socket_interceptor_ = std::move(interceptor);
1145  return *this;
1146 }

The documentation for this class was generated from the following files: