public Boolean setMasterAddressId(String iD, String address) { NetworkBean data = new NetworkBean(); data.setMasterAddress(address); data.setMasterPid(iD); return(true); }
public void bullyAlgorithm() { NetworkBean data = new NetworkBean(); Boolean noMasterFound = true; // ServerOperations serveroperation = new ServerOperations(); String response = ""; foreach (KeyValuePair <string, string> entry in data.getpId_Address()) { String sendAddress = entry.Value; long pId = Int64.Parse(entry.Key); long currentNodepId = Int64.Parse(data.getpId()); if (pId > currentNodepId) { try { elctMasterNode proxy = XmlRpcProxyGen.Create <elctMasterNode>(); proxy.Url = sendAddress; response = proxy.electMasterNode(data.getpId()); Console.WriteLine(data.getpId() + " Sends the bully election message to :" + sendAddress); Console.WriteLine("response is :" + response); } catch (Exception e) { // TODO Auto-generated catch block Console.WriteLine("no response"); // removeNode(sendAddress); data.getpId_Address().Remove(sendAddress); } } if (response.Length > 0) { noMasterFound = false; break; } } // if no master is found then this node is the new master if (noMasterFound) { Console.WriteLine("No master found I am the new master"); data.setMasterPid(data.getpId()); data.setMasterAddress(data.getAddress()); propagateNewMasterNode(data.getpId(), data.getAddress()); } }
public void signOff() { NetworkBean data = new NetworkBean(); foreach (KeyValuePair <string, string> entry in data.getpId_Address()) { String sendAddress = entry.Value; String iD = entry.Key; try { nodeSignoff proxy = XmlRpcProxyGen.Create <nodeSignoff>(); proxy.Url = sendAddress; proxy.nodeSignOff(data.getpId()); Console.WriteLine("sending message Signing off to :" + sendAddress); } catch (Exception e) { // TODO Auto-generated catch block Console.WriteLine("Could not send the message succesfully.. node denied connection"); removeNode(iD); // Console.WriteLine(e.StackTrace); } } if (data.getMasterPid().Equals(data.getpId())) { foreach (KeyValuePair <string, string> entry in data.getpId_Address()) { addr = entry.Value; ide = entry.Key; } foreach (KeyValuePair <string, string> entry in data.getpId_Address()) { try { // NetworkBean data = new NetworkBean(); ServerOperations serveroperaation = new ServerOperations(); setMasterAddrId proxy = XmlRpcProxyGen.Create <setMasterAddrId>(); proxy.Url = entry.Value; proxy.setMasterAddressId(ide, addr); } catch (Exception e) { // Console.WriteLine(e.StackTrace); } } String response = ""; foreach (KeyValuePair <string, string> entry in data.getpId_Address()) { String sendAddress = entry.Value; try { callBullyAfterSignoff proxy = XmlRpcProxyGen.Create <callBullyAfterSignoff>(); proxy.Url = sendAddress; response = proxy.callBullyAfterSignOff(data.getpId()); Console.WriteLine(data.getpId() + " Sends the bully election message to :" + sendAddress); Console.WriteLine("response is :" + response); } catch (Exception e) { // TODO Auto-generated catch block Console.WriteLine("no response"); // Console.WriteLine(e.StackTrace); } if (response.Length > 0) { break; } } } data.getpId_Address().Clear(); data.setMasterAddress(data.getAddress()); data.setMasterPid(data.getpId()); }
public void start(int port) { // for CookComputing.XmlRpcV2 // RemotingConfiguration.Configure("SumAndDiff.exe.config", false); // for CookComputing.XmlRpc /* try { RemotingConfiguration.Configure("C:\\Users\\UMAIR\\Documents\\Visual Studio 2015\\Projects\\Node1\\Node1\\App.config"); } * catch(Exception e) * { * Console.WriteLine(e.Message); * } * * RemotingConfiguration.RegisterWellKnownServiceType( * typeof(CsServer), * "CsServer.rem", * WellKnownObjectMode.Singleton); * Console.WriteLine("Press to shutdown"); * Console.ReadLine();*/ // system.("csc /r:system.web.dll /r:CookComputing.XmlRpcV2.dll /target:library CsServer.cs "); HttpListener listener = new HttpListener(); string ip = Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString(); String url = "http://" + ip + ":" + port + "/"; Console.WriteLine(url); String iD = DateTime.Now.ToString("yyyyMMddHHmmssfff"); NetworkBean data = new NetworkBean(); CentralisedMutualExclusion cme = new CentralisedMutualExclusion(); Ricart_Agarwala RA = new Ricart_Agarwala(); LamportClock clock = new LamportClock(); data.setAddress(url); //data.setpId(Long.parseLong(iD)); data.setpId(iD); data.setPort(port); data.setMasterAddress(url); data.setMasterPid(iD); cme.setCRInUse(false); RA.setRequestCR(false); RA.setUsingCR(false); RA.setNumberOfNodesResponded(0); RA.setMyTimeStamp("0"); data.setDistributedStringVariable(""); data.setStartCME(false); data.setStartRicartAgarwala(false); data.setMessage(""); clock.setC(1); data.setNoOfNodesFinishedOperation(0); data.setRnd(); //Console.WriteLine(url+iD); listener.Prefixes.Add(url); try { listener.Start(); } catch (Exception e) { Console.WriteLine(e.Message); } while (true) { HttpListenerContext context = listener.GetContext(); XmlRpcListenerService svc = new CsServer(); svc.ProcessRequest(context); Thread.Sleep(1); } Console.WriteLine("server started"); }