frostfs-sdk-csharp/src/FrostFS.SDK.Client/Pool/InnerPool.cs
Pavel Gross 766f61a5f7 [#26] All: Remove V2 from naming
Rename project, namespaces and class names

Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-11-18 11:33:50 +03:00

47 lines
1 KiB
C#

using FrostFS.SDK.Client;
internal sealed class InnerPool
{
private readonly object _lock = new();
internal InnerPool(Sampler sampler, ClientWrapper[] clients)
{
Clients = clients;
Sampler = sampler;
}
internal Sampler Sampler { get; set; }
internal ClientWrapper[] Clients { get; }
internal ClientWrapper? Connection()
{
lock (_lock)
{
if (Clients.Length == 1)
{
var client = Clients[0];
if (client.IsHealthy())
{
return client;
}
}
else
{
var attempts = 3 * Clients.Length;
for (int i = 0; i < attempts; i++)
{
int index = Sampler.Next();
if (Clients[index].IsHealthy())
{
return Clients[index];
}
}
}
return null;
}
}
}