|
14 | 14 | SetValueRequest, |
15 | 15 | ) |
16 | 16 | from ni.pythonpanel.v1.python_panel_service_pb2_grpc import PythonPanelServiceStub |
17 | | -from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient, ServiceLocation |
| 17 | +from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient |
18 | 18 | from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool |
19 | 19 | from typing_extensions import ParamSpec |
20 | 20 |
|
@@ -45,14 +45,8 @@ def __init__( |
45 | 45 | self._discovery_client = discovery_client |
46 | 46 | self._grpc_channel_pool = grpc_channel_pool |
47 | 47 | self._grpc_channel = grpc_channel |
48 | | - self._proxy_location: ServiceLocation | None = None |
49 | 48 | self._stub: PythonPanelServiceStub | None = None |
50 | 49 |
|
51 | | - @property |
52 | | - def proxy_location(self) -> ServiceLocation: |
53 | | - """Return the ServiceLocation for the panel's proxy.""" |
54 | | - return self._get_proxy_location() |
55 | | - |
56 | 50 | def start_panel(self, panel_id: str, panel_script_path: str, python_path: str) -> str: |
57 | 51 | start_panel_request = StartPanelRequest( |
58 | 52 | panel_id=panel_id, panel_script_path=panel_script_path, python_path=python_path |
@@ -93,61 +87,29 @@ def try_get_value(self, panel_id: str, value_id: str) -> object | None: |
93 | 87 | else: |
94 | 88 | return None |
95 | 89 |
|
96 | | - def _get_proxy_location(self) -> ServiceLocation: |
97 | | - if self._proxy_location is None: |
98 | | - self._proxy_location = self._resolve_discovery_service() |
99 | | - return self._proxy_location |
100 | | - |
101 | 90 | def _get_stub(self) -> PythonPanelServiceStub: |
102 | 91 | if self._stub is None: |
103 | 92 | if self._grpc_channel is not None: |
104 | 93 | self._stub = PythonPanelServiceStub(self._grpc_channel) |
105 | 94 | else: |
106 | | - channel = self._get_panel_service_channel() |
107 | | - self._stub = PythonPanelServiceStub(channel) |
| 95 | + with self._initialization_lock: |
| 96 | + if self._grpc_channel_pool is None: |
| 97 | + _logger.debug("Creating unshared GrpcChannelPool.") |
| 98 | + self._grpc_channel_pool = GrpcChannelPool() |
| 99 | + if self._discovery_client is None: |
| 100 | + _logger.debug("Creating unshared DiscoveryClient.") |
| 101 | + self._discovery_client = DiscoveryClient( |
| 102 | + grpc_channel_pool=self._grpc_channel_pool |
| 103 | + ) |
| 104 | + |
| 105 | + service_location = self._discovery_client.resolve_service( |
| 106 | + provided_interface=self._provided_interface, |
| 107 | + service_class=self._service_class, |
| 108 | + ) |
| 109 | + channel = self._grpc_channel_pool.get_channel(service_location.insecure_address) |
| 110 | + self._stub = PythonPanelServiceStub(channel) |
108 | 111 | return self._stub |
109 | 112 |
|
110 | | - def _get_grpc_channel_pool(self) -> GrpcChannelPool: |
111 | | - if self._grpc_channel_pool is None: |
112 | | - _logger.debug("Creating unshared GrpcChannelPool.") |
113 | | - self._grpc_channel_pool = GrpcChannelPool() |
114 | | - return self._grpc_channel_pool |
115 | | - |
116 | | - def _get_discovery_client(self, channel_pool: GrpcChannelPool) -> DiscoveryClient: |
117 | | - if self._discovery_client is None: |
118 | | - _logger.debug("Creating unshared DiscoveryClient.") |
119 | | - self._discovery_client = DiscoveryClient(grpc_channel_pool=channel_pool) |
120 | | - return self._discovery_client |
121 | | - |
122 | | - def _resolve_service( |
123 | | - self, discovery_client: DiscoveryClient, provided_interface: str, service_class: str = "" |
124 | | - ) -> ServiceLocation: |
125 | | - _logger.debug("Resolving '%s'.", provided_interface) |
126 | | - service_location = discovery_client.resolve_service( |
127 | | - provided_interface=provided_interface, |
128 | | - service_class=service_class, |
129 | | - ) |
130 | | - return service_location |
131 | | - |
132 | | - def _get_panel_service_channel(self) -> grpc.Channel: |
133 | | - with self._initialization_lock: |
134 | | - grpc_channel_pool = self._get_grpc_channel_pool() |
135 | | - discovery_client = self._get_discovery_client(grpc_channel_pool) |
136 | | - panel_location = self._resolve_service( |
137 | | - discovery_client, self._provided_interface, self._service_class |
138 | | - ) |
139 | | - channel = grpc_channel_pool.get_channel(panel_location.insecure_address) |
140 | | - return channel |
141 | | - |
142 | | - def _resolve_discovery_service(self) -> ServiceLocation: |
143 | | - with self._initialization_lock: |
144 | | - grpc_channel_pool = self._get_grpc_channel_pool() |
145 | | - discovery_client = self._get_discovery_client(grpc_channel_pool) |
146 | | - discovery_location = self._resolve_service( |
147 | | - discovery_client, provided_interface="ni.http1.proxy" |
148 | | - ) |
149 | | - return discovery_location |
150 | | - |
151 | 113 | def _invoke_with_retry( |
152 | 114 | self, method: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs |
153 | 115 | ) -> _T: |
|
0 commit comments