Skip to content

Commit 822f9f2

Browse files
committed
Convert Config classes to public API
These were converted into private classes during the 4.0 migration, as we were only supporting keyword arguments for the client configuration. However, that led to a poor user experience, as we had to use `**kwargs`, instead of listing all the configuration elements in the client constructor. (IDEs become painfully slow once we list all keyword arguments, as there are too many of them) The solution to this problem is to make the Config classes public API and make the client able to use it directly. ```python config = Config() config.cluster_name = "dev2" client = HazelcastClient(config) ``` We provide full type hints for config elements.
1 parent 3974ac6 commit 822f9f2

27 files changed

+1929
-1206
lines changed

docs/api/modules.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ API Documentation
55

66
aggregator
77
cluster
8-
config
98
core
109
cp
1110
errors

docs/api/config.rst renamed to docs/config.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
Config
2-
======
1+
Configuration API Documentation
2+
===============================
33

44
.. py:currentmodule:: hazelcast.config
55
6+
.. autoclass:: Config
7+
.. autoclass:: NearCacheConfig
8+
.. autoclass:: FlakeIdGeneratorConfig
9+
.. autoclass:: ReliableTopicConfig
610
.. autoclass:: IntType
711
.. autoclass:: EvictionPolicy
812
.. autoclass:: InMemoryFormat

docs/configuration_overview.rst

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
11
Configuration Overview
22
======================
33

4-
For configuration of the Hazelcast Python client, just pass the keyword
5-
arguments to the client to configure the desired aspects. An example is
6-
shown below.
4+
The client can be configured either by keyword arguments or by a configuration
5+
object.
6+
7+
Keyword Arguments Configuration
8+
-------------------------------
9+
10+
It is possible to pass keyword arguments directly to the client's constructor
11+
to configure desired aspects of the client.
12+
13+
The keyword argument names must be valid property names of the
14+
:class:`hazelcast.config.Config` class with valid values.
715

816
.. code:: python
917
10-
client = hazelcast.HazelcastClient(
11-
cluster_members=["127.0.0.1:5701"]
18+
from hazelcast import HazelcastClient
19+
20+
client = HazelcastClient(
21+
cluster_name="a-cluster",
22+
cluster_members=["127.0.0.1:5701"],
1223
)
1324
14-
See the API documentation of :class:`hazelcast.client.HazelcastClient`
15-
for details.
25+
26+
Using a Configuration Object
27+
----------------------------
28+
29+
Alternatively, you can create a configuration object, and pass it to the client
30+
as its only argument.
31+
32+
This way might provide better user experience as it provides hints for the
33+
configuration option names and their types.
34+
35+
.. code:: python
36+
37+
from hazelcast import HazelcastClient
38+
from hazelcast.config import Config
39+
40+
config = Config()
41+
config.cluster_name = "a-cluster"
42+
config.cluster_members = ["127.0.0.1:5701"]
43+
client = HazelcastClient(config)

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Features
117117
:hidden:
118118

119119
client
120+
config
120121
api/modules
121122
getting_started
122123
features
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from hazelcast import HazelcastClient
2+
3+
client = HazelcastClient(
4+
cluster_name="a-cluster",
5+
cluster_members=["10.212.1.132:5701"],
6+
ssl_enabled=True,
7+
near_caches={
8+
"a-map": {
9+
"time_to_live": 120,
10+
"max_idle": 60,
11+
}
12+
},
13+
)
14+
15+
# Do something with the client
16+
17+
client.shutdown()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from hazelcast import HazelcastClient
2+
from hazelcast.config import Config, NearCacheConfig
3+
4+
config = Config()
5+
config.cluster_name = "a-cluster"
6+
config.cluster_members = ["10.212.1.132:5701"]
7+
config.ssl_enabled = True
8+
9+
near_cache_config = NearCacheConfig()
10+
near_cache_config.time_to_live = 120
11+
near_cache_config.max_idle = 60
12+
13+
config.near_caches = {
14+
"a-map": near_cache_config,
15+
}
16+
17+
client = HazelcastClient(config)
18+
19+
# Do something with the client
20+
21+
client.shutdown()

0 commit comments

Comments
 (0)