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) {} }
private bool setDestinationHost(HostUrl hostUrl) { this.hostUrlAddress = hostUrl.getFullUrl(); return(true); //it comes from java implementation }