frostfs-sdk-csharp/src/FrostFS.SDK.Client/Tools/ClientContext.cs
Pavel Gross 749000a090 [#28] Client: Apply code optimizations
Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-11-18 17:00:19 +03:00

62 lines
1.4 KiB
C#

using System;
using System.Collections.ObjectModel;
using Grpc.Core.Interceptors;
using Grpc.Net.Client;
namespace FrostFS.SDK.Client;
public class ClientContext(FrostFSClient client, ClientKey key, FrostFsOwner owner, GrpcChannel channel, FrostFsVersion version) : IDisposable
{
private string? sessionKey;
internal FrostFsOwner Owner { get; } = owner;
internal string? Address { get; } = channel.Target;
internal GrpcChannel Channel { get; private set; } = channel;
internal FrostFsVersion Version { get; } = version;
internal NetworkSettings? NetworkSettings { get; set; }
internal FrostFSClient Client { get; } = client;
internal ClientKey Key { get; } = key;
internal SessionCache? SessionCache { get; set; }
internal Action<CallStatistics>? Callback { get; set; }
internal Collection<Interceptor>? Interceptors { get; set; }
internal Action<Exception>? PoolErrorHandler { get; set; }
internal string? SessionCacheKey
{
get
{
if (sessionKey == null && Key != null && Address != null)
{
sessionKey = Pool.FormCacheKey(Address, Key.PublicKey);
}
return sessionKey;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
Channel?.Dispose();
}
}
}