[#24] Client: Implement pool part1
first iteration - base classes and methods Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
d1271df207
commit
c9a75ea025
72 changed files with 2786 additions and 468 deletions
47
src/FrostFS.SDK.ClientV2/Poll/InnerPool.cs
Normal file
47
src/FrostFS.SDK.ClientV2/Poll/InnerPool.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using FrostFS.SDK.ClientV2;
|
||||
|
||||
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.StatusMonitor.IsHealthy())
|
||||
{
|
||||
return client;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var attempts = 3 * Clients.Length;
|
||||
|
||||
for (int i = 0; i < attempts; i++)
|
||||
{
|
||||
int index = Sampler.Next();
|
||||
|
||||
if (Clients[index].StatusMonitor.IsHealthy())
|
||||
{
|
||||
return Clients[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue