This repository was archived by the owner on Apr 1, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
google/cloud/bigtable/data Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,11 +95,21 @@ def unsubscribe(self, callback):
9595 replace_symbols = {"_AsyncWrappedChannel" : "_WrappedChannel" },
9696)
9797class AsyncSwappableChannel (_AsyncWrappedChannel ):
98+ """
99+ Provides a grpc channel wrapper, that allows the internal channel to be swapped out
100+
101+ Args:
102+ - channel_fn: a nullary function that returns a new channel instance.
103+ It should be a partial with all channel configuration arguments built-in
104+ """
98105 def __init__ (self , channel_fn : Callable [[], Channel ]):
99106 self ._channel_fn = channel_fn
100107 self ._channel = channel_fn ()
101108
102109 def create_channel (self ) -> Channel :
110+ """
111+ Create a fresh channel using the stored `channel_fn` partial
112+ """
103113 new_channel = self ._channel_fn ()
104114 if CrossSync .is_async :
105115 # copy over interceptors
@@ -120,6 +130,9 @@ def create_channel(self) -> Channel:
120130 return new_channel
121131
122132 def swap_channel (self , new_channel : Channel ) -> Channel :
133+ """
134+ Replace the wrapped channel with a new instance. Typically created using `create_channel`
135+ """
123136 old_channel = self ._channel
124137 self ._channel = new_channel
125138 return old_channel
Original file line number Diff line number Diff line change @@ -245,6 +245,20 @@ def __init__(
245245
246246 @CrossSync .convert (replace_symbols = {"AsyncSwappableChannel" : "SwappableChannel" })
247247 def _build_grpc_channel (self , * args , ** kwargs ) -> AsyncSwappableChannel :
248+ """
249+ This method is called by the gapic transport to create a grpc channel.
250+
251+ The init arguments passed down are captured in a partial used by AsyncSwappableChannel
252+ to create new channel instances in the future, as part of the channel refresh logic
253+
254+ Emulators always use an inseucre channel
255+
256+ Args:
257+ - *args: positional arguments passed by the gapic layer to create a new channel with
258+ - **kwargs: keyword arguments passed by the gapic layer to create a new channel with
259+ Returns:
260+ a custom wrapped swappable channel
261+ """
248262 if self ._emulator_host is not None :
249263 # emulators use insecure channel
250264 create_channel_fn = partial (insecure_channel , self ._emulator_host )
Original file line number Diff line number Diff line change @@ -72,15 +72,25 @@ def unsubscribe(self, callback):
7272
7373
7474class SwappableChannel (_WrappedChannel ):
75+ """
76+ Provides a grpc channel wrapper, that allows the internal channel to be swapped out
77+
78+ Args:
79+ - channel_fn: a nullary function that returns a new channel instance.
80+ It should be a partial with all channel configuration arguments built-in
81+ """
82+
7583 def __init__ (self , channel_fn : Callable [[], Channel ]):
7684 self ._channel_fn = channel_fn
7785 self ._channel = channel_fn ()
7886
7987 def create_channel (self ) -> Channel :
88+ """Create a fresh channel using the stored `channel_fn` partial"""
8089 new_channel = self ._channel_fn ()
8190 return new_channel
8291
8392 def swap_channel (self , new_channel : Channel ) -> Channel :
93+ """Replace the wrapped channel with a new instance. Typically created using `create_channel`"""
8494 old_channel = self ._channel
8595 self ._channel = new_channel
8696 return old_channel
Original file line number Diff line number Diff line change @@ -179,6 +179,18 @@ def __init__(
179179 )
180180
181181 def _build_grpc_channel (self , * args , ** kwargs ) -> SwappableChannel :
182+ """This method is called by the gapic transport to create a grpc channel.
183+
184+ The init arguments passed down are captured in a partial used by SwappableChannel
185+ to create new channel instances in the future, as part of the channel refresh logic
186+
187+ Emulators always use an inseucre channel
188+
189+ Args:
190+ - *args: positional arguments passed by the gapic layer to create a new channel with
191+ - **kwargs: keyword arguments passed by the gapic layer to create a new channel with
192+ Returns:
193+ a custom wrapped swappable channel"""
182194 if self ._emulator_host is not None :
183195 create_channel_fn = partial (insecure_channel , self ._emulator_host )
184196 else :
You can’t perform that action at this time.
0 commit comments