Skip to content

Commit 26a7467

Browse files
authored
List Proxy for Asyncio Client (#782)
Straightforward port of `List` to asyncio.
1 parent 9464505 commit 26a7467

6 files changed

Lines changed: 805 additions & 1 deletion

File tree

hazelcast/asyncio/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
warnings.warn("Asyncio API for Hazelcast Python Client is BETA. DO NOT use it in production.")
44
del warnings
55

6-
__all__ = ["EntryEventCallable", "HazelcastClient", "Map", "VectorCollection"]
6+
__all__ = ["EntryEventCallable", "HazelcastClient", "List", "Map", "VectorCollection"]
77

88
from hazelcast.internal.asyncio_client import HazelcastClient
9+
from hazelcast.internal.asyncio_proxy.list import List
910
from hazelcast.internal.asyncio_proxy.map import Map, EntryEventCallable
1011
from hazelcast.internal.asyncio_proxy.vector_collection import VectorCollection

hazelcast/internal/asyncio_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
dynamic_config_add_vector_collection_config_codec,
2424
)
2525
from hazelcast.internal.asyncio_proxy.manager import (
26+
LIST_SERVICE,
2627
MAP_SERVICE,
2728
ProxyManager,
2829
VECTOR_SERVICE,
2930
)
3031
from hazelcast.internal.asyncio_proxy.base import Proxy
32+
from hazelcast.internal.asyncio_proxy.list import List
3133
from hazelcast.internal.asyncio_proxy.map import Map
3234
from hazelcast.internal.asyncio_reactor import AsyncioReactor
3335
from hazelcast.serialization import SerializationServiceV1
@@ -248,6 +250,17 @@ async def _start(self):
248250
raise
249251
_logger.info("Client started")
250252

253+
async def get_list(self, name: str) -> List[KeyType]:
254+
"""Returns the distributed list instance with the specified name.
255+
256+
Args:
257+
name: Name of the distributed list.
258+
259+
Returns:
260+
Distributed list instance with the specified name.
261+
"""
262+
return await self._proxy_manager.get_or_create(LIST_SERVICE, name)
263+
251264
async def get_map(self, name: str) -> Map[KeyType, ValueType]:
252265
"""Returns the distributed map instance with the specified name.
253266

hazelcast/internal/asyncio_proxy/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from hazelcast.core import MemberInfo
77
from hazelcast.types import KeyType, ValueType, ItemType, MessageType, BlockingProxyType
88
from hazelcast.internal.asyncio_invocation import Invocation
9+
from hazelcast.internal.asyncio_partition import string_partition_strategy
910
from hazelcast.util import get_attr_name
1011

1112
MAX_SIZE = float("inf")
@@ -91,6 +92,18 @@ async def _ainvoke_on_partition(
9192
return await fut
9293

9394

95+
class PartitionSpecificProxy(Proxy, abc.ABC):
96+
"""Provides basic functionality for Partition Specific Proxies."""
97+
98+
def __init__(self, service_name, name, context):
99+
super(PartitionSpecificProxy, self).__init__(service_name, name, context)
100+
partition_key = context.serialization_service.to_data(string_partition_strategy(name))
101+
self._partition_id = context.partition_service.get_partition_id(partition_key)
102+
103+
def _invoke(self, request, response_handler=_no_op_response_handler) -> asyncio.Future:
104+
return self._invoke_on_partition(request, self._partition_id, response_handler)
105+
106+
94107
class ItemEventType:
95108
"""Type of item events."""
96109

0 commit comments

Comments
 (0)