public Server Choose(ILoadBalancer loadBalancer) { var until = DateTime.Now.AddMilliseconds(MaxRetryMilliseconds); Server server = null; while ((server == null || !server.IsAlive) && DateTime.Now < until) { if (_cancellationToken.HasValue) { while (!_cancellationToken.Value.IsCancellationRequested) { server = _subRule.Choose(loadBalancer); if ((server == null || !server.IsAlive) && DateTime.Now < until) { Thread.Sleep(5 * 1000); continue; } break; } } else { var count = 0; while (count++ < MaxRetryCount) { server = _subRule.Choose(loadBalancer); if ((server == null || !server.IsAlive) && DateTime.Now < until) { Thread.Sleep(5 * 1000); continue; } break; } } } return((server == null || !server.IsAlive) ? null : server); }
public Server Choose() { while (true) { if (_pingInProgress == 1) { Thread.Sleep(5 * 1000); } else { _counter.Increment(); try { return(_rule.Choose(this)); } catch (Exception exception) { _logger.LogError($"LoadBalancer [{_name}]: Error choosing server for rule {_rule}", exception); return(null); } } } }