public IEnumerable<Host> NewQueryPlan(Query query) { var schedule = _reconnectionPolicy.NewSchedule(); while (true) { List<Host> copyOfHosts = new List<Host>(_cluster.Metadata.AllHosts()); for (int i = 0; i < copyOfHosts.Count; i++) { if (_startidx == -1 || _startidx >= copyOfHosts.Count - 1) _startidx = StaticRandom.Instance.Next(copyOfHosts.Count); var h = copyOfHosts[_startidx]; if (h.IsConsiderablyUp) yield return h; _startidx++; _startidx = _startidx % copyOfHosts.Count; } if (ReconnectionEvent != null) { var ea = new RoundRobinPolicyWithReconnectionRetriesEventArgs(schedule.NextDelayMs()); ReconnectionEvent(this, ea); if (ea.Cancel) break; } else Thread.Sleep((int)schedule.NextDelayMs()); } }
public IEnumerable <Host> NewQueryPlan(Query query) { var schedule = _reconnectionPolicy.NewSchedule(); while (true) { List <Host> copyOfHosts = new List <Host>(_cluster.Metadata.AllHosts()); for (int i = 0; i < copyOfHosts.Count; i++) { if (_startidx == -1) { _startidx = StaticRandom.Instance.Next(copyOfHosts.Count); } _startidx %= copyOfHosts.Count; var h = copyOfHosts[_startidx]; _startidx++; if (h.IsConsiderablyUp) { yield return(h); } } if (ReconnectionEvent != null) { var ea = new RoundRobinPolicyWithReconnectionRetriesEventArgs(schedule.NextDelayMs()); ReconnectionEvent(this, ea); if (ea.Cancel) { break; } } else { Thread.Sleep((int)schedule.NextDelayMs()); } } }