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.HubClient _hub;
|
||||||
final grpc_hub.HubAdminClient _admin;
|
final grpc_hub.HubAdminClient _admin;
|
||||||
|
|
||||||
HubClient({this.endpoint = const HubEndpoint()})
|
HubClient._(this.endpoint, this._channel)
|
||||||
: _channel = ClientChannel(
|
: _hub = grpc_hub.HubClient(_channel),
|
||||||
endpoint.host,
|
_admin = grpc_hub.HubAdminClient(_channel);
|
||||||
port: endpoint.port,
|
|
||||||
options: ChannelOptions(
|
factory HubClient({HubEndpoint endpoint = const HubEndpoint()}) {
|
||||||
credentials: endpoint.secure
|
final channel = ClientChannel(
|
||||||
? const ChannelCredentials.secure()
|
endpoint.host,
|
||||||
: const ChannelCredentials.insecure(),
|
port: endpoint.port,
|
||||||
),
|
options: ChannelOptions(
|
||||||
),
|
credentials: endpoint.secure
|
||||||
_hub = grpc_hub.HubClient(
|
? const ChannelCredentials.secure()
|
||||||
ClientChannel(
|
: const ChannelCredentials.insecure(),
|
||||||
endpoint.host,
|
idleTimeout: const Duration(minutes: 5),
|
||||||
port: endpoint.port,
|
),
|
||||||
options: ChannelOptions(
|
);
|
||||||
credentials: endpoint.secure
|
return HubClient._(endpoint, channel);
|
||||||
? 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(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Liveness probe. Returns true when the hub responds with
|
/// Liveness probe. Returns true when the hub responds with
|
||||||
/// SERVING. False on any failure (includes connection refused).
|
/// SERVING. False on any failure (includes connection refused).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue