private String tokenRingName; //It will use to recognize this tokenRing is used for Add or Modification //private HpnXmlRpcClient hpnXmlRpcClient; //it is a copy of the client for sending Token public TokenRing(String tokenRingName) { this.tokenRingName = tokenRingName; this.runTokenRing = false; this.hastToken = false; this.needToken = false; TokenRingQueue.addTokenRing(this); }
public void sendToken() { try { int result = -1; Random rnd = new Random(); int rand = rnd.Next(214748300); HostUrl hostUrl = TokenRingQueue.nextHostOnRing(); if (hostUrl != null) { if (setDestinationHost(hostUrl)) { if (tokenRing.getTokenRingName().Equals("AddTokenRing")) { host.MethodName = "AddTokenRing.receiveToken"; host.Params.Clear(); host.Params.Add(rand); } else if (tokenRing.getTokenRingName().Equals("ModifyTokenRing")) { host.MethodName = "ModifyTokenRing.receiveToken"; host.Params.Clear(); host.Params.Add(rand); } int attempts = 1; do { try { response = host.Send(hostUrlAddress); result = (int)response.Value; break; } catch (Exception) { attempts++; } }while(attempts < 4); if (result != rand + 1) { Console.WriteLine("* The token has not been received by the host : [" + hostUrl.getFullUrl() + "]."); } } } } catch (Exception) {} }