Skip to content

Commit 182adb5

Browse files
Impl FixedGrpcChannelTransport (#89)
* Make ClientBase abstract class * Impl FixedGrpcChannelTransport.cs
1 parent f69e827 commit 182adb5

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Grpc.Core;
2+
using Grpc.Net.Client;
3+
using Microsoft.Extensions.Logging;
4+
5+
namespace Ydb.Sdk.Transport;
6+
7+
internal class FixedGrpcChannelTransport : GrpcTransport
8+
{
9+
private readonly GrpcChannel _channel;
10+
11+
public FixedGrpcChannelTransport(
12+
DriverConfig driverConfig,
13+
ILogger logger
14+
) : base(
15+
new DriverConfig(
16+
endpoint: driverConfig.Endpoint,
17+
database: driverConfig.Database,
18+
customServerCertificate: driverConfig.CustomServerCertificate
19+
), logger
20+
)
21+
{
22+
_channel = ChannelsCache.CreateChannel(Config.Endpoint, Config);
23+
}
24+
25+
protected override void Dispose(bool disposing)
26+
{
27+
if (disposing)
28+
{
29+
_channel.Dispose();
30+
}
31+
}
32+
33+
protected override (string, GrpcChannel) GetChannel()
34+
{
35+
return (Config.Endpoint, _channel);
36+
}
37+
38+
protected override void OnRpcError(string endpoint, RpcException e)
39+
{
40+
var status = e.Status;
41+
if (e.Status.StatusCode != Grpc.Core.StatusCode.OK)
42+
{
43+
Logger.LogWarning("gRPC error {StatusCode}[{Detail}] on fixed channel {Endpoint}",
44+
status.StatusCode, status.Detail, endpoint);
45+
}
46+
}
47+
}

src/Ydb.Sdk/src/GrpcTransport.cs renamed to src/Ydb.Sdk/src/Transport/GrpcTransport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
using Grpc.Net.Client;
33
using Microsoft.Extensions.Logging;
44

5-
namespace Ydb.Sdk;
5+
namespace Ydb.Sdk.Transport;
66

77
// TODO Experimental [for Driver with fix call options]
88
public abstract class GrpcTransport : IDisposable, IAsyncDisposable
99
{
10-
protected readonly ILogger Logger;
1110
protected readonly DriverConfig Config;
11+
protected readonly ILogger Logger;
1212

1313
internal GrpcTransport(DriverConfig driverConfig, ILogger logger)
1414
{

0 commit comments

Comments
 (0)