public void ResendTuple(Tuple t)//Resends the Tuple t saying it is a resending { while (RepFreeze) { } foreach (TimerTuple t3 in TimerAck.ToArray()) { if (t3 != null && t3.AckT.Id.Equals(t.Id)) { Console.WriteLine("Resending tuple: " + t.toString()); SendTuple(t, true);//true states its resending } } }
/// <summary> /// AddTupleToReceiveAck inserts tuple in ToReceiveAck. /// </summary> /// <param name="t">Tuple that will receive ack</param> public void AddTupleToReceiveAck(Tuple t, bool resend)//Add tuple to receive ack { if (!RepInfo.Semantics.Equals("at-most-once")) { if (!resend) { TimerMethod temptimer = new TimerMethod(ResendTuple);//Starts timer to resend tuple t with timeout defined as a constant at the top of this file Timer stateTimer = new Timer(temptimer.ResendTupleMethod, t, TIMEOUT, TIMEOUT); TimerTuple temp = new TimerTuple(t, stateTimer); TimerAck.Add(temp); ToReceiveAck.Add(t); } } }
public void receivedAck(Tuple t, bool notRep)//Remove tuple that needed to receive ack from the list { if (!RepInfo.Semantics.Equals("at-most-once")) { foreach (Tuple t2 in ToReceiveAck.ToArray()) { if (t2 != null && t.Id.Equals(t2.Id)) { ToReceiveAck.Remove(t); removeRepTuple(t);//removes if exists the replica of a a tuple processed foreach (TimerTuple t3 in TimerAck.ToArray()) { if (t3 != null && t.Id.Equals(t3.AckT.Id)) { t3.Time.Dispose(); TimerAck.Remove(t3); Console.WriteLine("receivedAck: " + t.toString()); break; } } if (notRep) { foreach (string url in RepInfo.SiblingsUrls.ToArray())//removes replicated receive acks from siblings { if (url != null && !url.Equals(RepInfo.MyUrl)) { try { OperatorServices obj = (OperatorServices)Activator.GetObject(typeof(OperatorServices), url); obj.receivedAck(t, false); Console.WriteLine("Removed ack of tuple: " + t.toString() + " from sibling: " + url); } catch (System.Net.Sockets.SocketException e) {//if the replica that should received ack is dead no problem } } } } return;//We only want to remove 1 } } Console.WriteLine("receivedAck: Error while removing tuple after being acked: " + t.toString()); } }