public void DeserializeDivideProblem()
 {
     DivideProblem d = new DivideProblem();
     string xml = d.SerializeToXML();
     d = (DivideProblem)xml.DeserializeXML();
     Assert.IsNotNull(d);
 }
Esempio n. 2
0
        protected override string ReceivedStatus(Status status)
        {
            Debug.Assert(this.serverQueues != null, "null server queue");
            Node node = this.RegisteredComponents.NodeWithID(status.Id);

            NoOperation noOperationResponse = this.GenerateNoOperation();
            if (!this.ensureNode(node)) {
                return noOperationResponse.SerializeToXML();
            }

            switch (node.NodeType) {
                case NodeType.TaskManager:
                    if (this.serverQueues.SolveRequests.Count > 0) {
                        SolveRequest solveRequest = this.serverQueues.SolveRequests.Dequeue();
                        DivideProblem divideProblem = new DivideProblem();
                        divideProblem.Data = solveRequest.Data;
                        divideProblem.Id = solveRequest.Id;
                        Console.WriteLine("Sending DivideProblem to TM");
                        return divideProblem.SerializeToXML();
                    }
                    //TM is not going to join the solutions
                    //if (this.serverQueues.Solutions.Count > 0) {
                    //    Solutions solutions = this.serverQueues.Solutions.Dequeue();
                    //    return solutions.SerializeToXML();
                    //}
                    break;
                case NodeType.ComputationalNode: //TODO: check!!
                    bool busy = false;
                    if (status.Threads != null) {
                        Console.WriteLine("Threads field not null");
                        foreach (StatusThreadsThread stt in status.Threads) {
                            if (stt.ProblemInstanceIdSpecified || stt.TaskIdSpecified) {
                                busy = true;
                                Console.WriteLine("Busy = true");
                            }
                        }
                    }
                    if (this.serverQueues.ProblemsToSolve.Count > 0 && !busy) {
                        Console.WriteLine("Busy = true");
                        SolvePartialProblems partialProblems = this.serverQueues.ProblemsToSolve.Dequeue();
                        Console.WriteLine("Sending PartialProblems to CN");
                        return partialProblems.SerializeToXML();
                    }
                    break;
                case NodeType.Server: {
                        foreach (BackupServerQueue bsq in this.backupServerQueues) {
                            if (bsq.backupServerId == status.Id) {
                                Console.WriteLine("Sending queued message to BackupCS");
                                if(bsq.messages.Count > 0)
                                    return bsq.messages.Dequeue();
                            }
                        }
                    }
                    break;
                default:
                    break;
            }

            Debug.Assert(node != null, "Received unregistered node status");
            if (node == null) {
                Console.WriteLine("Received unregistered node status");
                return noOperationResponse.SerializeToXML();
            }

            if (!this.BackupMode)
            Console.WriteLine("Sending NoOp");
            return noOperationResponse.SerializeToXML();
        }
 public void SerializeDivideProblem()
 {
     DivideProblem d = new DivideProblem();
     string xml = d.SerializeToXML();
     Assert.IsNotNull(xml);
 }
Esempio n. 4
0
        protected override string ReceivedSolvePartialProblems(SolvePartialProblems solvePartialProblems)
        {
            /* Partial problems message is sent by the TM after dividing the problem into smaller partial problems.
             * The data in it consists of two parts – common for all partial problems and specific for the given task.
             * The same Partial Problems schema is used for the messages sent to be computed by the CN and to relay
             * information for synchronizing info with Backup CS.
             */

            this.serverQueues.ProblemsToSolve.Enqueue(solvePartialProblems);
            //if (this.BackupMode == true)
            //    return null;

            if (this.serverQueues.SolveRequests.Count > 0) {
                SolveRequest solveRequest = this.serverQueues.SolveRequests.Dequeue();
                DivideProblem divideProblem = new DivideProblem();
                divideProblem.Data = solveRequest.Data;
                divideProblem.Id = solveRequest.Id;
                Console.WriteLine("Sending DivideProblem as an ans to SolvePartiaProblems");
                return divideProblem.SerializeToXML();
            }

            //TM is not going to join the solutions
            //if (this.serverQueues.Solutions.Count > 0) {
            //    Solutions solutions = this.serverQueues.Solutions.Dequeue();
            //    return solutions.SerializeToXML();
            //}

            Console.WriteLine("Sending NoOp as an ans to SolvePartialProblems");
            return this.GenerateNoOperation().SerializeToXML();
        }