Пример #1
0
        private void HandleNodeCommunication(NodeManagerComm data)
        {
            switch (data.Protocol)
            {
            case NodeManagerComm.MessageType.SubmitJob:
                SendMessage(new [] { "submit" });
                break;

            // sent by a job file
            case NodeManagerComm.MessageType.NewJob:
                Manager.Logger.Log("Received Job File: " + data.Args[1]);
                // add it to the list of jobs for later
                var jobRef = JsonConvert.DeserializeObject <JobRef>(data.Args[1]);
                Manager.Scheduler.AddJob(jobRef, Proxy.Id);
                Manager.Logger.Log("Proxy id is:" + Proxy.Id);
                break;

            case NodeManagerComm.MessageType.File:
                Manager.Logger.Log("Node Manager: sending file info");
                SendMessage(data.Args);
                break;

            // the machine that submitted the job file
            // needs to be on the same computer that the
            // manager is running on as of now.
            case NodeManagerComm.MessageType.Send:

                var jobId = int.Parse(data.Args[1]);
                //var job = JsonConvert.DeserializeObject<JobRef>(data.args[1]);
                var j = Manager.Scheduler.GetJob(jobId);
                if (j != null)
                {
                    Manager.Logger.Log("Sending file: " + Path.GetFileName(j.PathToDll));
                    //bool found = manager.Scheduler.GetJob(Path.GetFileName(data.args[1]), out d);
                    Manager.Logger.Log("Writing file: " + j.PathToDll);
                    FileWrite.WriteOut(Proxy.IOStream, j.PathToDll);
                    Proxy.IOStream.Flush();
                    Manager.Logger.Log("Sent file");
                }
                else
                {
                    Manager.Logger.Log("No jobs... bad");
                }
                break;

            case NodeManagerComm.MessageType.FileRead:
                Manager.Logger.Log("Node Manageer: Node has read file");
                SendMessage(new [] { "execute" });
                break;

            case NodeManagerComm.MessageType.NodeFinished:
                Manager.ConnectedNodes[Proxy.Id].Busy = false;
                Manager.SendJobResults(data);
                break;

            case NodeManagerComm.MessageType.Results:
                // forward along the results to the user
                SendMessage(data.Args);
                break;

            case NodeManagerComm.MessageType.NodeQuit:
                // remove the entry associated with
                // this proxy's id
                Manager.ConnectedNodes.Remove(Proxy.Id);
                // goto case is not harmful (like a regular 'goto' in other languages)
                goto case NodeManagerComm.MessageType.ConnectionQuit;

            case NodeManagerComm.MessageType.ConnectionQuit:
                // remove the connection
                Manager.Connections.Remove(Proxy);
                DoneSending = true;
                break;

            case NodeManagerComm.MessageType.Shutdown:
                SendMessage(new [] { "shutdown" });
                // shutdown after we have sent the message
                DoneSending = true;
                break;

            case NodeManagerComm.MessageType.Unknown:
                break;

            default:
                // should never get here, unknown handles it
                throw new ArgumentOutOfRangeException();
            }
        }