Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit bcac8a2

Browse files
committed
create separate transport registry for async class
1 parent 9dee4ff commit bcac8a2

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

google/cloud/bigtable_v2/services/bigtable/async_client.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,41 @@
6565
_LOGGER = std_logging.getLogger(__name__)
6666

6767

68+
class BigtableAsyncClientMeta(type):
69+
"""Metaclass for the Bigtable async client.
70+
71+
This provides class-level methods for building and retrieving
72+
support objects (e.g. transport) without polluting the client instance
73+
objects.
74+
"""
75+
76+
_transport_registry = OrderedDict() # type: Dict[str, Type[BigtableTransport]]
77+
_transport_registry["grpc_asyncio"] = BigtableGrpcAsyncIOTransport
78+
79+
def get_transport_class(
80+
cls,
81+
label: Optional[str] = None,
82+
) -> Type[BigtableTransport]:
83+
"""Returns an appropriate transport class.
84+
85+
Args:
86+
label: The name of the desired transport. If none is
87+
provided, then the first transport in the registry is used.
88+
89+
Returns:
90+
The transport class to use.
91+
"""
92+
# If a specific transport is requested, return that one.
93+
if label:
94+
return cls._transport_registry[label]
95+
96+
# No transport is requested; return the default (that is, the first one
97+
# in the dictionary).
98+
return next(iter(cls._transport_registry.values()))
99+
100+
101+
102+
68103
class BigtableAsyncClient:
69104
"""Service for reading from and writing to existing Bigtable
70105
tables.
@@ -264,9 +299,10 @@ def __init__(
264299
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
265300
creation failed for any reason.
266301
"""
302+
transport_cls = BigtableAsyncClient.get_transport_class(transport)
267303
self._client = BigtableClient(
268304
credentials=credentials,
269-
transport=transport,
305+
transport=transport_cls,
270306
client_options=client_options,
271307
client_info=client_info,
272308
)

google/cloud/bigtable_v2/services/bigtable/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class BigtableClientMeta(type):
8282

8383
_transport_registry = OrderedDict() # type: Dict[str, Type[BigtableTransport]]
8484
_transport_registry["grpc"] = BigtableGrpcTransport
85-
_transport_registry["grpc_asyncio"] = BigtableGrpcAsyncIOTransport
8685
_transport_registry["rest"] = BigtableRestTransport
8786

8887
def get_transport_class(

0 commit comments

Comments
 (0)