|
65 | 65 | _LOGGER = std_logging.getLogger(__name__) |
66 | 66 |
|
67 | 67 |
|
| 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 | + |
68 | 103 | class BigtableAsyncClient: |
69 | 104 | """Service for reading from and writing to existing Bigtable |
70 | 105 | tables. |
@@ -264,9 +299,10 @@ def __init__( |
264 | 299 | google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport |
265 | 300 | creation failed for any reason. |
266 | 301 | """ |
| 302 | + transport_cls = BigtableAsyncClient.get_transport_class(transport) |
267 | 303 | self._client = BigtableClient( |
268 | 304 | credentials=credentials, |
269 | | - transport=transport, |
| 305 | + transport=transport_cls, |
270 | 306 | client_options=client_options, |
271 | 307 | client_info=client_info, |
272 | 308 | ) |
|
0 commit comments