/// <summary>
        ///   Gets or creates connection to the cluster.
        /// </summary>
        /// <param name="partitionKey"> </param>
        /// <returns> </returns>
        /// <exception cref="CqlException">Can not connect to any node of the cluster! All connectivity to the cluster seems to be lost</exception>
        public Connection GetOrCreateConnection(PartitionKey partitionKey)
        {
            //try based on partition first
            if (partitionKey != null && partitionKey.IsSet)
            {
                var nodes = _nodes.GetResponsibleNodes(partitionKey).Where(n => n.IsUp).OrderBy(n => n.Load);

                foreach (Node node in nodes)
                {
                    Connection connection = node.GetOrCreateConnection(partitionKey);
                    if (connection != null)
                    {
                        return(connection);
                    }
                }
            }

            return(_baseStrategy.GetOrCreateConnection(partitionKey));
        }
Пример #2
0
 /// <summary>
 ///   Gets a connection to a reference in the cluster
 /// </summary>
 /// <param name="partitionKey"> </param>
 /// <returns> </returns>
 public Connection GetOrCreateConnection(PartitionKey partitionKey)
 {
     return(_connectionSelector.GetOrCreateConnection(partitionKey));
 }