/// <summary> /// This method is called by the node to post build /// requests into a queue in the parent engine /// </summary> public void PostBuildRequestsToHost(BuildRequest[] buildRequests) { LocalCallDescriptorForPostBuildRequests callDescriptor = new LocalCallDescriptorForPostBuildRequests(buildRequests); nodeCommandQueue.Enqueue(callDescriptor); }
public void PostBuildRequestToNode(int nodeIndex, BuildRequest buildRequest) { ErrorUtilities.VerifyThrow(nodeIndex < nodeData.Length && nodeIndex >= 0, "Node index must be within array boundaries"); if (nodeData[nodeIndex].NodeState != NodeState.Launched) { // Note that we have to check the node status again inside the mutex. This // ensures that that after flipping the status to launched inside the mutex // there will be no more writes to the queue of targets waiting to be sent lock (nodeStateLock) { // Check if we didn't initialize this node if (nodeData[nodeIndex].NodeState != NodeState.Launched && !shuttingDown) { // Check if launch is in progress if (nodeData[nodeIndex].NodeState == NodeState.NotLaunched) { nodeData[nodeIndex].NodeState = NodeState.LaunchInProgress; lock (nodesToLaunch) { nodesToLaunch.Enqueue(nodeIndex); } ThreadStart threadState = new ThreadStart(this.LaunchNodeAndPostBuildRequest); Thread taskThread = new Thread(threadState); taskThread.Name = "MSBuild Node Launcher"; taskThread.Start(); } nodeData[nodeIndex].TargetList.AddFirst(new LinkedListNode <BuildRequest>(buildRequest)); } else { LocalCallDescriptorForPostBuildRequests callDescriptor = new LocalCallDescriptorForPostBuildRequests(buildRequest); nodeData[nodeIndex].NodeCommandQueue.Enqueue(callDescriptor); } } } else { LocalCallDescriptorForPostBuildRequests callDescriptor = new LocalCallDescriptorForPostBuildRequests(buildRequest); nodeData[nodeIndex].NodeCommandQueue.Enqueue(callDescriptor); } }
/// <summary> /// This method first reads the objectId as an int from the stream, /// this int should be found in the "ObjectType" enumeration. This /// objectId informs the method what kind of object should be /// deserialized and returned from the method. The objectId is an /// output parameter. This parameter is also returned so it can be /// used in the read and write methods to determine if /// a frame or end marker was found. /// </summary> private object DeserializeFromStream(out int objectId) { object objectRead = null; objectId = readStream.ReadByte(); switch ((ObjectType)objectId) { case ObjectType.NetSerialization: objectRead = binaryFormatter.Deserialize(readStream); break; case ObjectType.FrameMarker: objectRead = binaryReader.ReadInt32(); break; case ObjectType.PostBuildResult: objectRead = new LocalCallDescriptorForPostBuildResult(); ((LocalCallDescriptorForPostBuildResult)objectRead).CreateFromStream(binaryReader); break; case ObjectType.PostBuildRequests: objectRead = new LocalCallDescriptorForPostBuildRequests(); ((LocalCallDescriptorForPostBuildRequests)objectRead).CreateFromStream(binaryReader); break; case ObjectType.PostLoggingMessagesToHost: objectRead = new LocalCallDescriptorForPostLoggingMessagesToHost(); ((LocalCallDescriptorForPostLoggingMessagesToHost)objectRead).CreateFromStream(binaryReader, loggingTypeCache); break; case ObjectType.InitializeNode: objectRead = new LocalCallDescriptorForInitializeNode(); ((LocalCallDescriptorForInitializeNode)objectRead).CreateFromStream(binaryReader); break; case ObjectType.InitializationComplete: objectRead = new LocalCallDescriptorForInitializationComplete(); ((LocalCallDescriptorForInitializationComplete)objectRead).CreateFromStream(binaryReader); break; case ObjectType.UpdateNodeSettings: objectRead = new LocalCallDescriptorForUpdateNodeSettings(); ((LocalCallDescriptorForUpdateNodeSettings)objectRead).CreateFromStream(binaryReader); break; case ObjectType.RequestStatus: objectRead = new LocalCallDescriptorForRequestStatus(); ((LocalCallDescriptorForRequestStatus)objectRead).CreateFromStream(binaryReader); break; case ObjectType.PostCacheEntriesToHost: objectRead = new LocalCallDescriptorForPostingCacheEntriesToHost(); ((LocalCallDescriptorForPostingCacheEntriesToHost)objectRead).CreateFromStream(binaryReader); break; case ObjectType.GetCacheEntriesFromHost: objectRead = new LocalCallDescriptorForGettingCacheEntriesFromHost(); ((LocalCallDescriptorForGettingCacheEntriesFromHost)objectRead).CreateFromStream(binaryReader); break; case ObjectType.ShutdownComplete: objectRead = new LocalCallDescriptorForShutdownComplete(); ((LocalCallDescriptorForShutdownComplete)objectRead).CreateFromStream(binaryReader); break; case ObjectType.ShutdownNode: objectRead = new LocalCallDescriptorForShutdownNode(); ((LocalCallDescriptorForShutdownNode)objectRead).CreateFromStream(binaryReader); break; case ObjectType.PostIntrospectorCommand: objectRead = new LocalCallDescriptorForPostIntrospectorCommand(null, null); ((LocalCallDescriptorForPostIntrospectorCommand)objectRead).CreateFromStream(binaryReader); break; case ObjectType.GenericSingleObjectReply: objectRead = new LocalReplyCallDescriptor(); ((LocalReplyCallDescriptor)objectRead).CreateFromStream(binaryReader); break; case ObjectType.PostStatus: objectRead = new LocalCallDescriptorForPostStatus(); ((LocalCallDescriptorForPostStatus)objectRead).CreateFromStream(binaryReader); break; case ObjectType.EndMarker: return(null); default: ErrorUtilities.VerifyThrow(false, "Should not be here, ObjectId:" + objectId + "Next:" + readStream.ReadByte()); break; } return(objectRead); }
/// <summary> /// This function will start a node and send requests to it /// </summary> private void LaunchNodeAndPostBuildRequest() { int nodeIndex = 0; // Find out what node to launch lock (nodesToLaunch) { nodeIndex = nodesToLaunch.Dequeue(); } // If the provider is shutting down - don't launch the node if (shuttingDown) { nodeData[nodeIndex].NodeState = NodeState.NotLaunched; return; } try { // Either launch node or connect to an already running node InitializeNode(nodeIndex); if (!nodeData[nodeIndex].CommunicationFailed) { // Change the state of the node to launched lock (nodeStateLock) { nodeData[nodeIndex].NodeState = NodeState.Launched; } // Send all the requests to the node. Note that the requests may end up in // mixed order with the request currently being posted. LinkedListNode <BuildRequest> current = nodeData[nodeIndex].TargetList.First; BuildRequest[] buildRequests = new BuildRequest[nodeData[nodeIndex].TargetList.Count]; int i = 0; while (current != null) { buildRequests[i] = current.Value; i++; current = current.Next; } LocalCallDescriptorForPostBuildRequests callDescriptor = new LocalCallDescriptorForPostBuildRequests(buildRequests); nodeData[nodeIndex].NodeCommandQueue.Enqueue(callDescriptor); nodeData[nodeIndex].TargetList = null; } else { // Allow the engine to decide how to proceed since the node failed to launch string message = ResourceUtilities.FormatResourceString("NodeProviderFailure"); ReportNodeCommunicationFailure(nodeIndex, new Exception(message), false); } } catch (Exception e) { // Allow the engine to deal with the exception ReportNodeCommunicationFailure(nodeIndex, e, false); } }