protected override string ReceivedRegister(Register register, IPAddress senderAddr) { string type = register.Type; Node newNode; ulong ID = RegisteredNodes.NextNodeID; switch (Utilities.NodeTypeForName(type)) { case NodeType.TaskManager: newNode = new TaskManager(); if (senderAddr != null) { newNode.IP = senderAddr; } newNode.NodeType = Nodes.NodeType.TaskManager; newNode.ID = register.Id; this.RegisteredComponents.RegisterTaskManager(newNode); break; case NodeType.ComputationalNode: newNode = new ComputationalNode(); newNode.ID = register.Id; if (senderAddr != null) { newNode.IP = senderAddr; } newNode.NodeType = Nodes.NodeType.ComputationalNode; this.RegisteredComponents.RegisterComputationalNode(newNode); break; case NodeType.Server: newNode = new Server(); newNode.ID = ID; BackupServerQueue bsq = new BackupServerQueue { backupServerId = ID, messages = new Queue <string>() }; if (senderAddr != null) { newNode.IP = senderAddr; } newNode.NodeType = Nodes.NodeType.Server; this.backupServerQueues.Add(bsq); this.RegisteredComponents.RegisterBackupServer(newNode); this.backupServerQueues.Add(bsq); break; case NodeType.Client: //not needed! break; default: break; } //Register message is sent by TM, CN and Backup CS to the CS after they are activated. RegisterResponse response = new RegisterResponse(); response.Id = ID; response.Timeout = this.Timeout; List <RegisterResponseBackupCommunicationServersBackupCommunicationServer> backupServers = new List <RegisterResponseBackupCommunicationServersBackupCommunicationServer>(); foreach (Node comp in this.RegisteredComponents.BackupServers) { RegisterResponseBackupCommunicationServersBackupCommunicationServer backup = new RegisterResponseBackupCommunicationServersBackupCommunicationServer(); if (comp.IP == null) { break; } backup.address = comp.IP.ToString(); if (comp.Port > 0) { backup.port = comp.Port; backup.portSpecified = true; } backupServers.Add(backup); } response.BackupCommunicationServers = backupServers.ToArray(); if (!this.BackupMode) { Console.WriteLine("Sending RegisterResponse"); } return(response.SerializeToXML()); }
protected override string ReceivedRegister(Register register, IPAddress senderAddr) { string type = register.Type; Node newNode; ulong ID = RegisteredNodes.NextNodeID; switch (Utilities.NodeTypeForName(type)) { case NodeType.TaskManager: newNode = new TaskManager(); if(senderAddr != null) newNode.IP = senderAddr; newNode.NodeType = Nodes.NodeType.TaskManager; newNode.ID = register.Id; this.RegisteredComponents.RegisterTaskManager(newNode); break; case NodeType.ComputationalNode: newNode = new ComputationalNode(); newNode.ID = register.Id; if (senderAddr != null) newNode.IP = senderAddr; newNode.NodeType = Nodes.NodeType.ComputationalNode; this.RegisteredComponents.RegisterComputationalNode(newNode); break; case NodeType.Server: newNode = new Server(); newNode.ID = ID; BackupServerQueue bsq = new BackupServerQueue { backupServerId = ID, messages = new Queue<string>() }; if (senderAddr != null) newNode.IP = senderAddr; newNode.NodeType = Nodes.NodeType.Server; this.backupServerQueues.Add(bsq); this.RegisteredComponents.RegisterBackupServer(newNode); this.backupServerQueues.Add(bsq); break; case NodeType.Client: //not needed! break; default: break; } //Register message is sent by TM, CN and Backup CS to the CS after they are activated. RegisterResponse response = new RegisterResponse(); response.Id = ID; response.Timeout = this.Timeout; List<RegisterResponseBackupCommunicationServersBackupCommunicationServer> backupServers = new List<RegisterResponseBackupCommunicationServersBackupCommunicationServer>(); foreach (Node comp in this.RegisteredComponents.BackupServers) { RegisterResponseBackupCommunicationServersBackupCommunicationServer backup = new RegisterResponseBackupCommunicationServersBackupCommunicationServer(); if (comp.IP == null) break ; backup.address = comp.IP.ToString(); if (comp.Port > 0) { backup.port = comp.Port; backup.portSpecified = true; } backupServers.Add(backup); } response.BackupCommunicationServers = backupServers.ToArray(); if(!this.BackupMode) Console.WriteLine("Sending RegisterResponse"); return response.SerializeToXML(); }