示例#1
0
        /// <summary>
        /// Attempts to get NodeSelectionPolicyFactory value from ConnectionParameters of clients.
        /// If some clients have NodeSelectionPolicyFactory in their connection strings and its values are the same, then method returns that value. Otherwise it returns 'null'
        /// </summary>
        /// <param name="clients">Clients collection</param>
        /// <returns>NodeSelectionPolicyFactory value</returns>
        private static BobNodeSelectionPolicyFactory TryGetNodeSelectionPolicyFactoryFromNodesConnectionParameters(BobNodeClient[] clients)
        {
            if (clients == null)
            {
                throw new ArgumentNullException(nameof(clients));
            }

            KnownBobNodeSelectionPolicies?result = BobConnectionParameters.TryExtractValueFromMultipleParameters(clients.Select(o => o.ConnectionParameters), p => p.NodeSelectionPolicy);

            return(result != null?BobNodeSelectionPolicyFactory.FromKnownNodeSelectionPolicy(result.Value) : null);
        }
示例#2
0
 /// <summary>
 /// <see cref="BobClusterBuilder{TKey}"/> constructor
 /// </summary>
 public BobClusterBuilder()
 {
     _nodeConnectionParameters   = new List <BobConnectionParameters>();
     _operationTimeout           = null;
     _connectionTimeout          = null;
     _nodeSelectionPolicyFactory = null;
     _operationRetryCount        = null;
     _keySerializer            = null;
     _keySerializationPoolSize = null;
     _user     = null;
     _password = null;
 }
示例#3
0
        /// <summary>
        /// <see cref="BobClusterClient"/> constructor
        /// </summary>
        /// <param name="clients">List of clients for every bob node</param>
        /// <param name="nodeSelectionPolicyFactory">Factory to create node selection policy (null for <see cref="SequentialNodeSelectionPolicy"/>)</param>
        /// <param name="operationRetryCount">The number of times the operation retries in case of failure (null - default value (no retries), 0 - no retries, >= 1 - number of retries after failure, -1 - number of retries is equal to number of nodes)</param>
        public BobClusterClient(IEnumerable <BobNodeClient> clients, BobNodeSelectionPolicyFactory nodeSelectionPolicyFactory, int?operationRetryCount)
        {
            if (clients == null)
            {
                throw new ArgumentNullException(nameof(clients));
            }

            _clients = clients.ToArray();

            if (_clients.Length == 0)
            {
                throw new ArgumentException("Clients list cannot be empty", nameof(clients));
            }
            for (int i = 0; i < _clients.Length; i++)
            {
                if (_clients[i] == null)
                {
                    throw new ArgumentNullException($"{nameof(clients)}[{i}]", "Client inside clients array cannot be null");
                }
            }

            nodeSelectionPolicyFactory = nodeSelectionPolicyFactory ?? TryGetNodeSelectionPolicyFactoryFromNodesConnectionParameters(_clients);
            if (nodeSelectionPolicyFactory == null)
            {
                if (_clients.Length == 1)
                {
                    _selectionPolicy = new FirstNodeSelectionPolicy(_clients);
                }
                else
                {
                    _selectionPolicy = new SequentialNodeSelectionPolicy(_clients);
                }
            }
            else
            {
                _selectionPolicy = nodeSelectionPolicyFactory.Create(_clients);
            }

            operationRetryCount = operationRetryCount ?? TryGetOperationRetryCountFromNodesConnectionParameters(_clients);
            if (operationRetryCount == null)
            {
                _operationRetryCount = 0;
            }
            else if (operationRetryCount.Value < 0)
            {
                _operationRetryCount = _clients.Length - 1;
            }
            else
            {
                _operationRetryCount = operationRetryCount.Value;
            }
        }
示例#4
0
 /// <summary>
 /// <see cref="BobClusterClient"/> constructor
 /// </summary>
 /// <param name="nodeConnectionStrings">List of connection strings to nodes</param>
 /// <param name="nodeSelectionPolicyFactory">Factory to create node selection policy (null for <see cref="SequentialNodeSelectionPolicy"/>)</param>
 /// <param name="operationRetryCount">The number of times the operation retries in case of failure (null - default value (no retries), 0 - no retries, >= 1 - number of retries after failure, -1 - number of retries is equal to number of nodes)</param>
 public BobClusterClient(IEnumerable <string> nodeConnectionStrings, BobNodeSelectionPolicyFactory nodeSelectionPolicyFactory, int?operationRetryCount)
     : this(nodeConnectionStrings.Select(o => new BobNodeClient(o)).ToList(), nodeSelectionPolicyFactory, operationRetryCount)
 {
 }
示例#5
0
 /// <summary>
 /// <see cref="BobClusterClient"/> constructor
 /// </summary>
 /// <param name="clients">List of clients for every bob node</param>
 /// <param name="nodeSelectionPolicyFactory">Factory to create node selection policy (null for <see cref="SequentialNodeSelectionPolicy"/>)</param>
 /// <param name="operationRetryCount">The number of times the operation retries in case of failure (null - default value (no retries), 0 - no retries, >= 1 - number of retries after failure, -1 - number of retries is equal to number of nodes)</param>
 /// <param name="keySerializer">Serializer for <typeparamref name="TKey"/> (null for default serializer)</param>
 /// <param name="keySerializationPoolSize">Size of the Key serialization pool (null - shared pool, 0 or less - pool is disabled, 1 or greater - custom pool with specified size)</param>
 public BobClusterClient(IEnumerable <BobNodeClient> clients, BobNodeSelectionPolicyFactory nodeSelectionPolicyFactory, int?operationRetryCount, BobKeySerializer <TKey> keySerializer, int?keySerializationPoolSize)
     : this(new BobClusterClient(clients, nodeSelectionPolicyFactory, operationRetryCount), keySerializer, keySerializationPoolSize)
 {
 }
示例#6
0
 /// <summary>
 /// <see cref="BobClusterClient"/> constructor
 /// </summary>
 /// <param name="nodeConnectionStrings">List of connection strings to nodes</param>
 /// <param name="nodeSelectionPolicyFactory">Factory to create node selection policy (null for <see cref="SequentialNodeSelectionPolicy"/>)</param>
 /// <param name="operationRetryCount">The number of times the operation retries in case of failure (null - default value (no retries), 0 - no retries, >= 1 - number of retries after failure, -1 - number of retries is equal to number of nodes)</param>
 /// <param name="keySerializer">Serializer for <typeparamref name="TKey"/> (null for default serializer)</param>
 /// <param name="keySerializationPoolSize">Size of the Key serialization pool (null - shared pool, 0 or less - pool is disabled, 1 or greater - custom pool with specified size)</param>
 public BobClusterClient(IEnumerable <string> nodeConnectionStrings, BobNodeSelectionPolicyFactory nodeSelectionPolicyFactory, int?operationRetryCount, BobKeySerializer <TKey> keySerializer, int?keySerializationPoolSize)
     : this(nodeConnectionStrings.Select(o => new BobNodeClient(o)).ToList(), nodeSelectionPolicyFactory, operationRetryCount, keySerializer, keySerializationPoolSize)
 {
 }
示例#7
0
 /// <summary>
 /// Specifies a node selection policy for opertions on cluster
 /// </summary>
 /// <param name="policyFactory">Factory to create node selection policy</param>
 /// <returns>The reference to the current builder instatnce</returns>
 public BobClusterBuilder <TKey> WithNodeSelectionPolicy(BobNodeSelectionPolicyFactory policyFactory)
 {
     _nodeSelectionPolicyFactory = policyFactory;
     return(this);
 }