Config

Hazelcast Client Configuration module contains configuration classes and various constants required to create a ClientConfig.

DEFAULT_GROUP_NAME = 'dev'

Default group name of the connected Hazelcast cluster

DEFAULT_GROUP_PASSWORD = 'dev-pass'

Default password of connected Hazelcast cluster

INTEGER_TYPE

alias of hazelcast.util.Enum

EVICTION_POLICY

alias of hazelcast.util.Enum

IN_MEMORY_FORMAT

alias of hazelcast.util.Enum

PROTOCOL

alias of hazelcast.util.Enum

class ClientConfig

Bases: object

The root configuration for hazelcast python client.

>>> client_config = ClientConfig()
>>> client = HazelcastClient(client_config)
group_config = None

The group configuration

network_config = None

The network configuration for addresses to connect, smart-routing, socket-options…

load_balancer = None

Custom load balancer used to distribute the operations to multiple Endpoints.

membership_listeners = None

Membership listeners, an array of tuple (member_added, member_removed, fire_for_existing)

lifecycle_listeners = None

Lifecycle Listeners, an array of Functions of f(state)

near_cache_configs = None

Near Cache configuration which maps “map-name : NearCacheConfig

flake_id_generator_configs = None

Flake ID generator configuration which maps “config-name” : FlakeIdGeneratorConfig

serialization_config = None

Hazelcast serialization configuration

logger_config = None

Logger configuration.

client_name = None

Name of the client

add_membership_listener(member_added=None, member_removed=None, fire_for_existing=False)

Helper method for adding membership listeners

Parameters:member_added – (Function), Function to be called when a member is added, in the form of f(member)

(optional). :param member_removed: (Function), Function to be called when a member is removed, in the form of f(member) (optional). :param fire_for_existing: if True, already existing members will fire member_added event (optional). :return: self for cascading configuration

add_lifecycle_listener(lifecycle_state_changed=None)

Helper method for adding lifecycle listeners.

Parameters:lifecycle_state_changed – (Function), Function to be called when lifecycle state is changed (optional).

In the form of f(state). :return: self for cascading configuration

add_near_cache_config(near_cache_config)

Helper method to add a new NearCacheConfig.

Parameters:near_cache_config – (NearCacheConfig), the near_cache config to add.
Returns:self for cascading configuration.
add_flake_id_generator_config(flake_id_generator_config)

Helper method to add a new FlakeIdGeneratorConfig.

Parameters:flake_id_generator_config – (FlakeIdGeneratorConfig), the configuration to add
Returns:self for cascading configuration
get_property_or_default(key, default)

Client property accessor with fallback to default value.

Parameters:
  • key – (Object), property key to access.
  • default – (Object), the default value for fallback.
Returns:

(Object), property value if it exist or the default value otherwise.

get_properties()

Gets the configuration properties.

Returns:(dict), Client configuration properties.
set_property(key, value)

Sets the value of a named property.

Parameters:
  • key – Property name
  • value – Value of the property
Returns:

self for cascading configuration.

class GroupConfig

Bases: object

The Group Configuration is the container class for name and password of the cluster.

name = None

The group name of the cluster

password = None

The password of the cluster

class ClientNetworkConfig

Bases: object

Network related configuration parameters.

addresses = None

The candidate address list that client will use to establish initial connection

connection_attempt_limit = None

While client is trying to connect initially to one of the members in the addressList, all might be not available. Instead of giving up, throwing Error and stopping client, it will attempt to retry as much as defined by this parameter.

connection_attempt_period = None

Period for the next attempt to find a member to connect

connection_timeout = None

Socket connection timeout is a float, giving in seconds, or None. Setting a timeout of None disables the timeout feature and is equivalent to block the socket until it connects. Setting a timeout of zero is the same as disables blocking on connect.

socket_options = None

Array of Unix socket options.

Example usage:

>>> import socket
>>> client_network_config.socket_options.append(SocketOption(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1))
>>> client_network_config.socket_options.append(SocketOption(socket.SOL_SOCKET, socket.SO_SNDBUF, 32768))
>>> client_network_config.socket_options.append(SocketOption(socket.SOL_SOCKET, socket.SO_RCVBUF, 32768))

Please see the Unix manual for level and option. Level and option constant are in python std lib socket module

redo_operation = None

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.

smart_routing = None

If true, client will route the key based operations to owner of the key at the best effort. Note that it uses a cached value of partition count and doesn’t guarantee that the operation will always be executed on the owner. The cached table is updated every 10 seconds.

ssl_config = None

SSL configurations for the client.

cloud_config = None

Hazelcast Cloud configuration to let the client connect the cluster via Hazelcast.cloud

class SocketOption(level, option, value)

Bases: object

Advanced configuration for fine-tune the TCP options. A Socket option represent the unix socket option, that will be passed to python socket.setoption(level,`option, value)` See the Unix manual for level and option.

level = None

Option level. See the Unix manual for detail.

option = None

The actual socket option. The actual socket option.

value = None

Socket option value. The value argument can either be an integer or a string

class SerializationConfig

Bases: object

Hazelcast Serialization Service configuration options can be set from this class.

portable_version = None

Portable version will be used to differentiate two versions of the same class that have changes on the class, like adding/removing a field or changing a type of a field.

data_serializable_factories = None

Dictionary of factory-id and corresponding IdentifiedDataserializable factories. A Factory is a simple dictionary with entries of class-id : class-constructor-function pairs.

Example:

>>> my_factory = {MyPersonClass.CLASS_ID : MyPersonClass, MyAddressClass.CLASS_ID : MyAddressClass}
>>> serialization_config.data_serializable_factories[FACTORY_ID] = my_factory
portable_factories = None

Dictionary of factory-id and corresponding portable factories. A Factory is a simple dictionary with entries of class-id : class-constructor-function pairs.

Example:

>>> portable_factory = {PortableClass_0.CLASS_ID : PortableClass_0, PortableClass_1.CLASS_ID : PortableClass_1}
>>> serialization_config.portable_factories[FACTORY_ID] = portable_factory
class_definitions = None

Set of all Portable class definitions.

check_class_def_errors = None

Configured Portable Class definitions should be validated for errors or not.

is_big_endian = None

Hazelcast Serialization is big endian or not.

default_integer_type = None

Python has variable length int/long type. In order to match this with static fixed length Java server, this option defines the length of the int/long. One of the values of INTEGER_TYPE can be assigned. Please see INTEGER_TYPE documentation for details of the options.

add_data_serializable_factory(factory_id, factory)

Helper method for adding IdentifiedDataSerializable factory. example:

>>> my_factory = {MyPersonClass.CLASS_ID : MyPersonClass, MyAddressClass.CLASS_ID : MyAddressClass}
>>> serialization_config.add_data_serializable_factory(factory_id, my_factory)
Parameters:
  • factory_id – (int), factory-id to register.
  • factory – (Dictionary), the factory dictionary of class-id:class-constructor-function pairs.
add_portable_factory(factory_id, factory)

Helper method for adding Portable factory. example:

>>> portable_factory = {PortableClass_0.CLASS_ID : PortableClass_0, PortableClass_1.CLASS_ID : PortableClass_1}
>>> serialization_config.portable_factories[FACTORY_ID] = portable_factory
Parameters:
  • factory_id – (int), factory-id to register.
  • factory – (Dictionary), the factory dictionary of class-id:class-constructor-function pairs.
set_custom_serializer(_type, serializer)

Assign a serializer for the type.

Parameters:
  • _type – (Type), the target type of the serializer
  • serializer – (Serializer), Custom Serializer constructor function
custom_serializers

All custom serializers.

Returns:(Dictionary), dictionary of type-custom serializer pairs.
global_serializer

The Global serializer property for serialization service. The assigned value should be a class constructor function. It handles every object if no other serializer found.

Global serializers should extend hazelcast.serializer.api.StreamSerializer

class NearCacheConfig(name='default')

Bases: object

Map Near cache configuration for a specific map by name.

invalidate_on_change = None

Should a value is invalidated and removed in case of any map data updating operations such as replace, remove etc.

name

Name of the map that this near cache belong. Cannot be None.

in_memory_format

Internal representation of the stored data in near cache.

time_to_live_seconds

The maximum number of seconds for each entry to stay in the near cache.

max_idle_seconds

Maximum number of seconds each entry can stay in the near cache as untouched (not-read).

eviction_policy

The eviction policy for the near cache

eviction_max_size

The limit for number of entries until the eviction start.

eviction_sampling_count

The entry count of the samples for the internal eviction sampling algorithm taking samples in each operation.

eviction_sampling_pool_size

The size of the internal eviction sampling algorithm has a pool of best candidates for eviction.

class SSLConfig

Bases: object

SSL configuration.

enabled = None

Enables/disables SSL.

cafile = None

Absolute path of concatenated CA certificates used to validate server’s certificates in PEM format. When SSL is enabled and cafile is not set, a set of default CA certificates from default locations will be used.

certfile = None

Absolute path of the client certificate in PEM format.

keyfile = None

Absolute path of the private key file for the client certificate in the PEM format. If this parameter is None, private key will be taken from certfile.

password = None

Password for decrypting the keyfile if it is encrypted. The password may be a function to call to get the password. It will be called with no arguments, and it should return a string, bytes, or bytearray. If the return value is a string it will be encoded as UTF-8 before using it to decrypt the key. Alternatively a string, bytes, or bytearray value may be supplied directly as the password.

protocol = None

Protocol version used in SSL communication. Default value is TLSv1.2

ciphers = None

String in the OpenSSL cipher list format to set the available ciphers for sockets. More than one cipher can be set by separating them with a colon.

class FlakeIdGeneratorConfig(name='default')

Bases: object

FlakeIdGeneratorConfig contains the configuration for the client regarding FlakeIdGenerator

name

Name of the flake ID generator configuration.

Getter:Returns the configuration name. This can be actual object name or pattern.
Setter:Sets the name or name pattern for this config. Must not be modified after this instance is added to configuration.
Type:str
prefetch_count

Prefetch value count.

Getter:Returns the prefetch count. Prefetch count is in the range 1..100,000.
Setter:Sets how many IDs are pre-fetched on the background when a new flake ID is requested from members. Default is 100. Prefetch count should be in the range 1..100,000.
Type:int
prefetch_validity_in_millis

Prefetch validity in milliseconds.

Getter:Returns the prefetch validity in milliseconds.
Setter:Sets for how long the pre-fetched IDs can be used. If this time elapses, a new batch of IDs will be fetched. Time unit is milliseconds, default is 600,000 (10 minutes). The IDs contain timestamp component, which ensures rough global ordering of IDs. If an ID is assigned to an object that was created much later, it will be much out of order. If you don’t care about ordering, set this value to 0.
Type:int
class ClientCloudConfig

Bases: object

Hazelcast Cloud configuration to let the client connect the cluster via Hazelcast.cloud

enabled = None

Enables/disables cloud config.

discovery_token = None

Hazelcast Cloud Discovery token of your cluster.

class LoggerConfig

Bases: object

Custom configuration for logging or a logging level for the default Hazelcast client logger can be set using this class.

config_file = None

If the configuration file is set, given configuration file will be used instead of the default logger configuration with the given log level. This should be the absolute path of a JSON file that follows the Configuration dictionary schema described in the logging module of the standard library.

level = None

Sets the logging level for the default logging configuration. To turn off the logging, level can be set to a high integer value. If custom logging levels are not used, a value greater than 50 is enough to turn off the default logger.

class ClientProperty(name, default_value=None, time_unit=None)

Bases: object

Client property holds the name, default value and time unit of Hazelcast client properties. Client properties can be set by

  • Programmatic Configuration
  • Environment variables
class ClientProperties(properties)

Bases: object

HEARTBEAT_INTERVAL = <hazelcast.config.ClientProperty object>

Time interval between the heartbeats sent by the client to the nodes.

HEARTBEAT_TIMEOUT = <hazelcast.config.ClientProperty object>

Client sends heartbeat messages to the members and this is the timeout for this sending operations. If there is not any message passing between the client and member within the given time via this property in milliseconds, the connection will be closed.

INVOCATION_TIMEOUT_SECONDS = <hazelcast.config.ClientProperty object>

When an invocation gets an exception because

  • Member throws an exception.
  • Connection between the client and member is closed.
  • Client’s heartbeat requests are timed out.

Time passed since invocation started is compared with this property. If the time is already passed, then the exception is delegated to the user. If not, the invocation is retried. Note that, if invocation gets no exception and it is a long running one, then it will not get any exception, no matter how small this timeout is set.

INVOCATION_RETRY_PAUSE_MILLIS = <hazelcast.config.ClientProperty object>

Pause time between each retry cycle of an invocation in milliseconds.

HAZELCAST_CLOUD_DISCOVERY_TOKEN = <hazelcast.config.ClientProperty object>

Token to use when discovering cluster via Hazelcast.cloud.

STATISTICS_ENABLED = <hazelcast.config.ClientProperty object>

Used to enable the client statistics collection.

STATISTICS_PERIOD_SECONDS = <hazelcast.config.ClientProperty object>

Period in seconds to collect statistics.

SERIALIZATION_INPUT_RETURNS_BYTEARRAY = <hazelcast.config.ClientProperty object>

Input#read_byte_array returns a List if property is False, otherwise it will return a byte-array. Changing this to True, gives a considerable performance benefit.

get(property)

Gets the value of the given property. First checks client config properties, then environment variables and lastly fall backs to the default value of the property.

Parameters:property – (ClientProperty), Property to get value from
Returns:Value of the given property
get_bool(property)

Gets the value of the given property as boolean.

Parameters:property – (ClientProperty), Property to get value from
Returns:(bool), Value of the given property
get_seconds(property)

Gets the value of the given property in seconds. If the value of the given property is not a number, throws TypeError.

Parameters:property – (ClientProperty), Property to get seconds from
Returns:(float), Value of the given property in seconds
get_seconds_positive_or_default(property)

Gets the value of the given property in seconds. If the value of the given property is not a number, throws TypeError. If the value of the given property in seconds is not positive, tries to return the default value in seconds.

Parameters:property – (ClientProperty), Property to get seconds from
Returns:(float), Value of the given property in seconds if it is positive. Else, value of the default value of given property in seconds.