private void divisionEntry() { if (isOnline) { int b = 0; TokenRing.waitForToken(); getListOfEvents(false); Console.WriteLine("Input the number: "); String date = Console.ReadLine(); b = Convert.ToInt32(date); String lastLine = File.ReadLines("Calendar.txt").Last(); result = Convert.ToInt32(lastLine); calculation_entry entry = new calculation_entry(result, b); entry.writeToFile_division(); foreach (HostIPnPort h in activeNodes) { if (!h.Equals(thisMachineIpnPort)) { addOverRPC(h.getFullUrl(), entry.makeString()); } } TokenRing.sendToken(); } else { Console.WriteLine("Node is offline! Operation is not allowed"); } }
public bool deleteNode(string IpnPort) { Console.WriteLine("Node has signed off the network."); //Client.activeNodes.Remove(ipAddress); int k = 0; while (k < Client.activeNodes.Count && !Client.activeNodes[k].getIPnPort().Equals(IpnPort)) { k++; } if (k < Client.activeNodes.Count) { HostIPnPort obj = Client.activeNodes[k]; Client.activeNodes.Remove(obj); } if (Client.activeNodes.Count == 1) { TokenRing.stopTokenRingAlgorithm(); //If you are alone you must stop Token Ring } return(true); }
private void signOff() { if (isOnline) { isOnline = false; foreach (HostIPnPort h in activeNodes) { if (!h.Equals(thisMachineIpnPort)) { signOffOverRPC(h.getFullUrl()); } } TokenRing.stopTokenRingAlgorithm(); activeNodes.Clear(); activeNodes.Add(thisMachineIpnPort); } else { Console.WriteLine("Node is already online"); } }
public int takeTheToken(int ack) { return(TokenRing.takeTheToken(ack)); }
private void join() { //if offline //make it online //input ip of active node, if it is first onlinenode input 17.0.0.1 //if 127.0.0.1 then isOnline = true //else //get list of all events //ip to url //config xmlrpc //get list of active nodes //for all active nodes - joinoverrpc //else node is already online if (!isOnline) { isOnline = true; Console.WriteLine("Input IP-address of active node"); Console.WriteLine("If it is the first online node input 127.0.0.1"); String ipAddress = Console.ReadLine(); if (!ipAddress.Equals("127.0.0.1")) { //TODO set port Console.WriteLine("Enter the port for this machine : "); int port = int.Parse(Console.ReadLine()); firstActiveNode = new HostIPnPort(ipAddress, port); getListOfEvents(true); IServiceContract proxy = XmlRpcProxyGen.Create <IServiceContract>(); proxy.Url = firstActiveNode.getFullUrl(); Object[] listOfNodes = proxy.getListOfActiveNodes(); for (int i = 0; i < listOfNodes.Length; i++) { HostIPnPort newObj = new HostIPnPort(listOfNodes[i].ToString()); int k = 0; while (k < activeNodes.Count && activeNodes[k].compare(newObj) < 0) { k++; } activeNodes.Insert(k, newObj); //activeNodes.Add(list[i].ToString()); } bool tokenRingStarter = false; if (activeNodes.Count == 2) { tokenRingStarter = true; } foreach (HostIPnPort h in activeNodes) { if (!h.Equals(thisMachineIpnPort)) { joinOverRPC(h.getFullUrl()); } } //config xnlrpc with firstactivenode to url //call Node.getListOfActive Nodes //add all nodes to the list of active nodes //for all activenodes - joinoverRPC(s) if (tokenRingStarter) { TokenRing.startTokenRingAlgorithm(); //for the time that you are starter of the token ring } if (activeNodes.Count > 2) { TokenRing.initiateTokenRing(); //for the time that token does not rotating in the Network Ring and it need to be monitored by this client } } else { isOnline = true; } } else { Console.WriteLine("Node is already online!"); } }