refactor: share single ClientChannel between Hub and HubAdmin
Initial scaffold accidentally created three separate gRPC channels (one for each of `_channel`, `_hub`, `_admin`). Refactor to a single shared channel — cleaner, fewer file descriptors, and `close()` actually closes everything now. Idle timeout raised to 5 minutes so polling-style page loops don't keep reconnecting. No public-API change. Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
parent
a2e3f4514a
commit
4b67055fc7
1 changed files with 17 additions and 32 deletions
|
|
@ -50,38 +50,23 @@ class HubClient {
|
|||
final grpc_hub.HubClient _hub;
|
||||
final grpc_hub.HubAdminClient _admin;
|
||||
|
||||
HubClient({this.endpoint = const HubEndpoint()})
|
||||
: _channel = ClientChannel(
|
||||
HubClient._(this.endpoint, this._channel)
|
||||
: _hub = grpc_hub.HubClient(_channel),
|
||||
_admin = grpc_hub.HubAdminClient(_channel);
|
||||
|
||||
factory HubClient({HubEndpoint endpoint = const HubEndpoint()}) {
|
||||
final channel = ClientChannel(
|
||||
endpoint.host,
|
||||
port: endpoint.port,
|
||||
options: ChannelOptions(
|
||||
credentials: endpoint.secure
|
||||
? const ChannelCredentials.secure()
|
||||
: const ChannelCredentials.insecure(),
|
||||
),
|
||||
),
|
||||
_hub = grpc_hub.HubClient(
|
||||
ClientChannel(
|
||||
endpoint.host,
|
||||
port: endpoint.port,
|
||||
options: ChannelOptions(
|
||||
credentials: endpoint.secure
|
||||
? const ChannelCredentials.secure()
|
||||
: const ChannelCredentials.insecure(),
|
||||
),
|
||||
),
|
||||
),
|
||||
_admin = grpc_hub.HubAdminClient(
|
||||
ClientChannel(
|
||||
endpoint.host,
|
||||
port: endpoint.port,
|
||||
options: ChannelOptions(
|
||||
credentials: endpoint.secure
|
||||
? const ChannelCredentials.secure()
|
||||
: const ChannelCredentials.insecure(),
|
||||
),
|
||||
idleTimeout: const Duration(minutes: 5),
|
||||
),
|
||||
);
|
||||
return HubClient._(endpoint, channel);
|
||||
}
|
||||
|
||||
/// Liveness probe. Returns true when the hub responds with
|
||||
/// SERVING. False on any failure (includes connection refused).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue