public void run() { try { int ack = 5; IServiceContract proxy = XmlRpcProxyGen.Create <IServiceContract>(); proxy.Url = nextNodeOnRing.getFullUrl(); int respond = proxy.takeTheToken(ack); if (respond != ack + 1) { Console.WriteLine("Token Ring algorithm has failed."); } } catch (Exception e) { Console.WriteLine("Token Ring algorithm has failed."); Console.WriteLine(e.Message); } }
private void getListOfEvents(bool getFromAnotherNode) { if (getFromAnotherNode) //only when node joins the network { IServiceContract proxy = XmlRpcProxyGen.Create <IServiceContract>(); proxy.Url = firstActiveNode.getFullUrl(); Object[] list = proxy.getList(); using (StreamWriter writer = new StreamWriter("Calendar.txt", false)) { for (int i = 0; i < list.Length; i++) { writer.WriteLine(list[i].ToString()); } } //if true - configuration of the xmlrpc and getting string[] Calendar.getList //clear the file //write to file new entries } else { //else read from the file and print try { using (StreamReader sr = new StreamReader("Calendar.txt")) { String line = sr.ReadToEnd(); Console.WriteLine(line); } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } } }
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!"); } }
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!"); } }