Esempio n. 1
0
        /// <exception cref="System.Net.Sockets.SocketException">Throws a SocketException when the connection could not be established with the host</exception>
        /// <exception cref="AuthenticationException" />
        /// <exception cref="UnsupportedProtocolVersionException"></exception>
        private Connection CreateConnection()
        {
            _logger.Info("Creating a new connection to the host " + Host.Address.ToString());
            var c = new Connection(ProtocolVersion, Host.Address, Configuration);

            c.Init();
            if (Configuration.PoolingOptions.GetHeartBeatInterval() != null)
            {
                //Heartbeat is enabled, subscribe for possible exceptions
                c.OnIdleRequestException += OnIdleRequestException;
            }
            return(c);
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to create the a connection to the cluster
        /// </summary>
        /// <exception cref="NoHostAvailableException" />
        /// <exception cref="DriverInternalError" />
        private void Connect(bool firstTime)
        {
            var triedHosts = new Dictionary <IPEndPoint, Exception>();
            IEnumerable <Host> hostIterator = Metadata.Hosts;

            if (!firstTime)
            {
                _logger.Info("Trying to reconnect the ControlConnection");
                //Use the load balancing policy to determine which host to use
                hostIterator = _config.Policies.LoadBalancingPolicy.NewQueryPlan(null, null);
            }
            foreach (var host in hostIterator)
            {
                var address = host.Address;
                var c       = new Connection((byte)_controlConnectionProtocolVersion, address, _config);
                try
                {
                    c.Init();
                    _connection = c;
                    _host       = host;
                    return;
                }
                catch (UnsupportedProtocolVersionException)
                {
                    _logger.Info(String.Format("Unsupported protocol version {0}, trying with a lower version", _controlConnectionProtocolVersion));
                    _controlConnectionProtocolVersion--;
                    c.Dispose();
                    if (_controlConnectionProtocolVersion < 1)
                    {
                        throw new DriverInternalError("Invalid protocol version");
                    }
                    //Retry using the new protocol version
                    Connect(firstTime);
                    return;
                }
                catch (Exception ex)
                {
                    //There was a socket exception or an authentication exception
                    triedHosts.Add(host.Address, ex);
                    c.Dispose();
                }
            }
            throw new NoHostAvailableException(triedHosts);
        }
 /// <summary>
 /// Tries to create the a connection to the cluster
 /// </summary>
 /// <exception cref="NoHostAvailableException" />
 /// <exception cref="DriverInternalError" />
 private void Connect(bool firstTime)
 {
     var triedHosts = new Dictionary<IPEndPoint, Exception>();
     IEnumerable<Host> hostIterator = Metadata.Hosts;
     if (!firstTime)
     {
         _logger.Info("Trying to reconnect the ControlConnection");
         //Use the load balancing policy to determine which host to use
         hostIterator = _config.Policies.LoadBalancingPolicy.NewQueryPlan(null, null);
     }
     foreach (var host in hostIterator)
     {
         var address = host.Address;
         var c = new Connection(ProtocolVersion, address, _config);
         try
         {
             c.Init();
             _connection = c;
             _host = host;
             return;
         }
         catch (UnsupportedProtocolVersionException)
         {
             //Use the protocol version used to parse the response message
             var nextVersion = c.ProtocolVersion;
             if (nextVersion >= ProtocolVersion)
             {
                 //Processor could reorder instructions in such way that the connection protocol version is not up to date.
                 nextVersion = (byte)(ProtocolVersion - 1);
             }
             _logger.Info(String.Format("Unsupported protocol version {0}, trying with version {1}", ProtocolVersion, nextVersion));
             ProtocolVersion = nextVersion;
             c.Dispose();
             if (ProtocolVersion < 1)
             {
                 throw new DriverInternalError("Invalid protocol version");
             }
             //Retry using the new protocol version
             Connect(firstTime);
             return;
         }
         catch (Exception ex)
         {
             //There was a socket exception or an authentication exception
             triedHosts.Add(host.Address, ex);
             c.Dispose();
         }
     }
     throw new NoHostAvailableException(triedHosts);
 }
 /// <exception cref="System.Net.Sockets.SocketException">Throws a SocketException when the connection could not be established with the host</exception>
 /// <exception cref="AuthenticationException" />
 /// <exception cref="UnsupportedProtocolVersionException"></exception>
 private Connection CreateConnection()
 {
     _logger.Info("Creating a new connection to the host " + Host.Address.ToString());
     var c = new Connection(ProtocolVersion, Host.Address, Configuration);
     c.Init();
     if (Configuration.PoolingOptions.GetHeartBeatInterval() != null)
     {
         //Heartbeat is enabled, subscribe for possible exceptions
         c.OnIdleRequestException += OnIdleRequestException;   
     }
     return c;
 }
 private Connection CreateConnection()
 {
     _logger.Info("Creating a new connection to the host " + Host.Address.ToString());
     var endpoint = new IPEndPoint(Host.Address, Configuration.ProtocolOptions.Port);
     var c = new Connection(this.ProtocolVersion, endpoint, Configuration);
     c.Init();
     return c;
 }