public void ProcessAndForward(CTuple tuple) { if (tuple.GetFields() != null) { Console.WriteLine($"Received {tuple.ID} from {tuple.opName} ({ tuple.repID })"); } originOperators[tuple.opName][tuple.repID].Insert(tuple); }
public override void Deliver(CTuple tuple) { // Console.WriteLine($"{GetHashCode()}: Delivering Tuple {tuple.ToString()} to {tuple.destinationId}."); int id = 0; lock (this) { id = tuple.destinationId == -1 ? RoutingStrategy.ChooseReplica(tuple) : tuple.destinationId; tuple.destinationId = id; } // Console.WriteLine($"{GetHashCode()}: Consulting semantic {Semantic}"); var rep = replicas[id]; somethingSentInRecentPast[id] = true; //if (tuple.GetFields() == null) //Console.WriteLine($"Delivering flush {tuple.ID} to {id}"); switch (Semantic) { case Semantic.AtLeastOnce: case Semantic.ExactlyOnce: controlFlag = false; while (!controlFlag) { rep = replicas[id]; //maybe someone updated it try { rep.ProcessAndForward(tuple, id); controlFlag = true; } //FIXME Exceção que faz timeout automatico catch (Exception e) { Console.WriteLine($"AtLeastOnce : {e.Message}"); }; } break; case Semantic.AtMostOnce: rep.ProcessAndForward(tuple, id); break; default: Console.WriteLine($"The specified semantic ({Semantic}) is not supported within our system"); break; } lock (this) { if (tuple.GetFields() != null) { Console.WriteLine($"Delivered tuple {tuple.ID} to {info.ID} ({id})"); } CachedOutputTuples.Add(tuple); SentTupleIds[id] = tuple.ID; } }
private IEnumerable <CTuple> Process(CTuple tuple) { IEnumerable <CTuple> resultTuples = null; // debug print var data = tuple.GetFields(); IEnumerable <IList <string> > resultData; var startSubId = LastProcessedId.GlobalID == tuple.ID.GlobalID ? LastProcessedId.SubID + 1 : 0; var origin = originOperators[tuple.opName][tuple.repID]; if (origin.LastProcessedId < tuple.ID) { if (data == null) { origin.LastProcessedId = tuple.ID; //this.LastProcessedId = new TupleID(tuple.ID.GlobalID, startSubId); return(new CTuple[0]); } else { resultData = ProcessFunction.Process(data); } origin.LastProcessedId = tuple.ID; } else { // Console.WriteLine($"Already seen {tuple.ID} from {origin.OpId} ({origin.ReplicaId}). Ignoring."); return(new CTuple[0]); } resultTuples = resultData.Select((tupleData, i) => new CTuple(tupleData.ToList(), tuple.ID.GlobalID, startSubId + i, this.OperatorId, this.ID)); if (resultTuples.Any()) { this.LastProcessedId = resultTuples.Last().ID; } // Console.WriteLine($"Processed {tuple.ToString()}"); return(resultTuples); }