public void InitiateBackup(IPAddress myAddress, int myPort, IPAddress masterAddress, int masterPort) { SmartConsole.PrintHeader("Starting backup server"); SmartConsole.PrintLine("Address: " + myAddress.ToString() + ":" + myPort, SmartConsole.DebugLevel.Advanced); // Create overall system tracker SystemTracker systemTracker = new SystemTracker(); // Create list of all clients ClientTracker clientTracker = new ClientTracker(); // Task Tracker TaskTracker taskTracker = new TaskTracker(); // Start network connection NetworkServer server = new NetworkServer(myAddress, myPort); // Create messageHandler MessageHandler messageHandler = new MessageHandler(systemTracker, clientTracker, taskTracker, server); // Start message queue MessageQueue messageQueue = new MessageQueue(server); // Start Message processor CommunicationServer.MessageCommunication.MessageProcessor messageProcessor = new CommunicationServer.MessageCommunication.MessageProcessor(messageQueue, messageHandler); // blockade to block untill server is switched to primary mode Object backupBlockade = new Object(); server.Open(); messageQueue.Start(); messageProcessor.Start(); /********************* REGISTER AS NORMAL CLIENT *********************/ RegisterType type = RegisterType.CommunicationServer; NetworkNode node = new NetworkNode(type); systemTracker.Node = node; NetworkClient client = new NetworkClient(masterAddress, masterPort); client.Connect(); SmartConsole.PrintLine("Sending Register message...", SmartConsole.DebugLevel.Advanced); CommunicationServer.MessageCommunication.KeepAliveTimer keepAliveTimer = new CommunicationServer.MessageCommunication.KeepAliveTimer(messageHandler, client, server, systemTracker, node, clientTracker, backupBlockade); keepAliveTimer.Communicate(node.ToRegisterMessage()); /********************* START COMMUNICATING WITH PRIMARY SERVER *********************/ SmartConsole.PrintLine("Backup Server starting work", SmartConsole.DebugLevel.Advanced); keepAliveTimer.Start(); // This will hold untill server is switched to primary mode lock (backupBlockade) { Monitor.Wait(backupBlockade); } /********************* SWITCH TO PRIMARY SERVER *********************/ SmartConsole.PrintHeader("SWITCHING TO PRIMARY"); Server.primaryMode = true; client.Disconnect(); clientTracker.RefreshTimeout(); // Start measuring timeout clientTracker.StartTimeout(); // Start console manager ConsoleManager consoleManager = new ConsoleManager(server); consoleManager.Start(); }