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; } } }