public IPAddress Pick(QueryHint hint) { lock (_lock) { IPAddress endpoint = null; if (0 < _healthyEndpoints.Count) { endpoint = _healthyEndpoints[0]; } return endpoint; } }
public IPAddress Pick(QueryHint hint) { lock (_lock) { IPAddress endpoint = null; if (0 < _healthyEndpoints.Count) { int candidate = _rnd.Next(_healthyEndpoints.Count); endpoint = _healthyEndpoints[candidate]; } return endpoint; } }
private string BuildQuery(string Query) { if (Hints.Count != 0) { string sQHints = ""; sQHints = Hints.GenerateString <QueryHint>(); var tHints = GetTableHints(); if (sQHints != string.Empty) { Query = QueryHint.BuildQuery(Query, sQHints); } if (tHints.Count > 0) { Query = BuildTableQuery(tHints, Query); } } return(Query); }
public IConnection GetConnection(QueryHint hint = null) { lock (_globalLock) { IConnection connection = null; try { while (null == connection) { // pick and initialize a new endpoint connection IPAddress endpoint = _endpointStrategy.Pick(hint); if (null == endpoint) { throw new ArgumentException("Can't find any valid endpoint"); } if (!_ip2Connection.TryGetValue(endpoint, out connection)) { // try to create a new connection - if this fails, recover the endpoint connection = CreateTransportOrMarkEndpointForRecovery(endpoint); if (null != connection) { _ip2Connection.Add(endpoint, connection); } } } return connection; } catch { connection.SafeDispose(); throw; } } }
public void AddHint(QueryHint hint) { _hints.Add(hint); }