/// <summary> /// Checks if the host is a valid candidate for the purpose of obtaining a connection. /// This method obtains the <see cref="HostDistance"/> from the load balancing policy. /// </summary> /// <param name="host">Host to check.</param> /// <param name="validHost">Output parameter that will contain the <see cref="ValidHost"/> instance.</param> /// <returns><code>true</code> if the host is valid and <code>false</code> if not valid /// (see documentation of <see cref="ValidHost.New"/>)</returns> private bool TryValidateHost(Host host, out ValidHost validHost) { var distance = _session.InternalCluster.RetrieveAndSetDistance(host); validHost = ValidHost.New(host, distance); return(validHost != null); }
/// <summary> /// Attempts to obtain a connection to the provided <paramref name="validHost"/> and send the request with it. /// If no connection could be obtained for the provided host, then attempts to obtain a connection /// for the next host, following the query plan. /// </summary> /// <param name="validHost">First host to which the method tries to obtain a connection.</param> /// <returns></returns> private async Task SendToNextHostAsync(ValidHost validHost) { try { IConnection connection = null; while (connection == null) { connection = await _parent.GetConnectionToValidHostAsync(validHost, _triedHosts).ConfigureAwait(false); if (connection == null) { validHost = _parent.GetNextValidHost(_triedHosts); } } _connection = connection; _host = validHost.Host; Send(_request, HandleResponse); } catch (Exception ex) { _host = validHost.Host; HandleResponse(ex, null); } }
/// <summary> /// Checks if the host is a valid candidate for the purpose of obtaining a connection. /// This method obtains the <see cref="HostDistance"/> from the load balancing policy. /// </summary> /// <param name="host">Host to check.</param> /// <param name="validHost">Output parameter that will contain the <see cref="ValidHost"/> instance.</param> /// <returns><code>true</code> if the host is valid and <code>false</code> if not valid /// (see documentation of <see cref="ValidHost.New"/>)</returns> private bool TryValidateHost(Host host, out ValidHost validHost) { var distance = Cluster.RetrieveDistance(host, RequestOptions.LoadBalancingPolicy); validHost = ValidHost.New(host, distance); return(validHost != null); }
/// <inheritdoc /> public Task <IConnection> GetConnectionToValidHostAsync(ValidHost validHost, IDictionary <IPEndPoint, Exception> triedHosts) { return(RequestHandler.GetConnectionFromHostAsync(validHost.Host, validHost.Distance, _session, triedHosts)); }