Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to create a node on the specified machine using the specified provider.
        /// </summary>
        /// <param name="nodeProvider">The provider used to create the node.</param>
        /// <param name="nodeConfiguration">The <see cref="NodeConfiguration"/> to use.</param>
        /// <param name="numberOfNodesToCreate">Number of nodes to be reused ot created.</param>
        /// <returns>List of created nodes.</returns>
        private IList <NodeInfo> AttemptCreateNode(INodeProvider nodeProvider, NodeConfiguration nodeConfiguration, int numberOfNodesToCreate)
        {
            // If no provider was passed in, we obviously can't create a node.
            if (nodeProvider == null)
            {
                ErrorUtilities.ThrowInternalError("No node provider provided.");
                return(new List <NodeInfo>());
            }

            // Are there any free slots on this provider?
            if (nodeProvider.AvailableNodes == 0)
            {
                return(new List <NodeInfo>());
            }

            // Assign a global ID to the node we are about to create.
            int fromNodeId;

            if (nodeProvider is NodeProviderInProc)
            {
                fromNodeId = _inprocNodeId;
            }
            else
            {
                // Reserve node numbers for all needed nodes.
                fromNodeId = Interlocked.Add(ref _nextNodeId, numberOfNodesToCreate) - numberOfNodesToCreate;
            }


            // Create the node and add it to our mapping.
            IList <NodeInfo> nodes = nodeProvider.CreateNodes(fromNodeId, this, AcquiredNodeConfigurationFactory, numberOfNodesToCreate);

            foreach (NodeInfo node in nodes)
            {
                _nodeIdToProvider.Add(node.NodeId, nodeProvider);
            }

            return(nodes);

            NodeConfiguration AcquiredNodeConfigurationFactory(NodeInfo nodeInfo)
            {
                var config = nodeConfiguration.Clone();

                config.NodeId = nodeInfo.NodeId;
                return(config);
            }
        }