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 102 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 757 of file config.cpp.

757  : cluster_name_("dev"), redo_operation_(false),
758  socket_interceptor_(), executor_pool_size_(-1) {}

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 955 of file config.cpp.

955  {
956  flake_id_generator_config_map_.emplace(config.get_name(), config);
957  return *this;
958  }

◆ 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 797 of file config.cpp.

797  {
798  lifecycle_listeners_.emplace_back(std::move(listener));
799  return *this;
800  }

◆ 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 802 of file config.cpp.

802  {
803  membership_listeners_.emplace_back(std::move(listener));
804  return *this;
805  }

◆ 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 869 of file config.cpp.

869  {
870  near_cache_config_map_.emplace(near_cache_config.get_name(), near_cache_config);
871  return *this;
872  }

◆ 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 842 of file config.cpp.

842  {
843  reliable_topic_config_map_[reliable_topic_config.get_name()] = reliable_topic_config;
844  return *this;
845  }

◆ 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 988 of file config.cpp.

988  {
989  return backup_acks_enabled_;
990  }

◆ 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 983 of file config.cpp.

983  {
984  backup_acks_enabled_ = enabled;
985  return *this;
986  }

◆ 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 924 of file config.cpp.

924  {
925  std::string baseName = internal::partition::strategy::StringPartitioningStrategy::get_base_name(name);
926  auto config = internal::config::ConfigUtils::lookup_by_pattern<config::client_flake_id_generator_config>(
927  config_pattern_matcher_, flake_id_generator_config_map_, baseName);
928  if (config) {
929  return config;
930  }
931  return get_flake_id_generator_config("default");
932  }
const config::client_flake_id_generator_config * get_flake_id_generator_config(const std::string &name)
Returns the {} for the given name, creating one if necessary and adding it to the collection of known...
Definition: config.cpp:936

◆ 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 960 of file config.cpp.

960  {
961  return cluster_name_;
962  }

◆ 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 905 of file config.cpp.

905  {
906  return executor_pool_size_;
907  }

◆ 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 936 of file config.cpp.

936  {
937  std::string baseName = internal::partition::strategy::StringPartitioningStrategy::get_base_name(name);
938  auto config = internal::config::ConfigUtils::lookup_by_pattern<config::client_flake_id_generator_config>(
939  config_pattern_matcher_, flake_id_generator_config_map_, baseName);
940  if (config) {
941  return config;
942  }
943  auto defConfig = flake_id_generator_config_map_.find("default");
944  if (defConfig == flake_id_generator_config_map_.end()) {
945  flake_id_generator_config_map_.emplace("default", config::client_flake_id_generator_config("default"));
946  }
947  defConfig = flake_id_generator_config_map_.find("default");
948  config::client_flake_id_generator_config new_config = defConfig->second;
949  new_config.set_name(name);
950  flake_id_generator_config_map_.emplace(name, std::move(new_config));
951  return &flake_id_generator_config_map_.find(name)->second;
952  }

◆ get_lifecycle_listeners()

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

Definition at line 807 of file config.cpp.

807  {
808  return lifecycle_listeners_;
809  }

◆ 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 773 of file config.cpp.

773  {
774  if (!load_balancer_) {
775  auto index = std::make_shared<std::atomic<size_t>>(0);
776  load_balancer_ = load_balancer().next([=](cluster &c) {
777  auto members = c.get_members();
778  if (members.empty()) {
779  return boost::optional<member>();
780  }
781  auto i = index->fetch_add(1);
782  return boost::make_optional(std::move(members[i % members.size()]));
783  });
784  }
785  return *load_balancer_;
786  }

◆ get_logger_config()

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

Definition at line 793 of file config.cpp.

793  {
794  return logger_config_;
795  }

◆ 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 811 of file config.cpp.

811  {
812  return membership_listeners_;
813  }

◆ 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 874 of file config.cpp.

874  {
875  auto nearCacheConfig = internal::config::ConfigUtils::lookup_by_pattern(
876  config_pattern_matcher_, near_cache_config_map_, name);
877  if (nearCacheConfig) {
878  return nearCacheConfig;
879  }
880 
881  auto config_it = near_cache_config_map_.find("default");
882  if (config_it != near_cache_config_map_.end()) {
883  return &near_cache_config_map_.find("default")->second;
884  }
885 
886  // not needed for c++ client since it is always native memory
887  //initDefaultMaxSizeForOnHeapMaps(nearCacheConfig);
888  return nullptr;
889  }

◆ 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 865 of file config.cpp.

865  {
866  return network_config_;
867  }

◆ 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 833 of file config.cpp.

833  {
834  return properties_;
835  }

◆ 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 847 of file config.cpp.

847  {
848  auto it = reliable_topic_config_map_.find(name);
849  if (it != reliable_topic_config_map_.end()) {
850  return it->second;
851  }
852 
853  return reliable_topic_config_map_.emplace(name, config::reliable_topic_config{name}).first->second;
854  }

◆ get_serialization_config()

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

Definition at line 824 of file config.cpp.

824  {
825  return serialization_config_;
826  }

◆ 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 996 of file config.cpp.

996  {
997  credentials_ = credential;
998  return *this;
999  }

◆ 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 909 of file config.cpp.

909  {
910  client_config::executor_pool_size_ = executor_pool_size;
911  }

◆ 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 788 of file config.cpp.

788  {
789  this->load_balancer_ = std::move(load_balancer);
790  return *this;
791  }

◆ 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 891 of file config.cpp.

891  {
892  this->network_config_ = network_config;
893  return *this;
894  }

◆ 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 837 of file config.cpp.

837  {
838  properties_[name] = value;
839  return *this;
840  }

◆ 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 764 of file config.cpp.

764  {
765  this->redo_operation_ = redo_operation;
766  return *this;
767  }

◆ 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 828 of file config.cpp.

828  {
829  this->serialization_config_ = serialization_config;
830  return *this;
831  }

◆ 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 815 of file config.cpp.

815  {
816  this->socket_interceptor_ = std::move(interceptor);
817  return *this;
818  }

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