public void requestTuples(string receiverRouting, int receiverTarget, IList <string> receiverUrls) { if (!requested) { requested = true; this.receiver_routing = receiverRouting; this.receiver_target = receiverTarget; //Dictionary for hashing routing if (receiver_routing.StartsWith(SysConfig.HASHING) && this.res.Count == 0 && notSentTuples.Count != 0) { string[] aux = this.receiver_routing.Split('('); int field = Int32.Parse(aux[1].First() + ""); foreach (KeyValuePair <string, IList <IList <string> > > entry in notProcessedTuples) { foreach (List <string> tuple in entry.Value) { int replica = Math.Abs(tuple[field - 1].GetHashCode()) % receiverUrls.Count; IList <IList <string> > set; if (!(res.ContainsKey(replica))) { set = new List <IList <string> >(); set.Add(tuple); res.Add(replica, set); } else { set = res[replica]; set.Add(tuple); res[replica] = set; } } } } foreach (string url in receiverUrls) { channel = new TcpChannel(); IRemoteOperator op = (IRemoteOperator)Activator.GetObject(typeof(Operator), url); if (op == null) { throw new CannotAccessRemoteObjectException("Cannot get remote Operator from " + url); } receivers.Add(op); this.receivers_urls.Add(url); if (notSentTuples.Count > 0) { if ((this.receiver_routing.Equals(SysConfig.PRIMARY) && url.Equals(receiverUrls[0]))) { //ERROR can be here, there was notProcessedTuples foreach (KeyValuePair <string, IList <IList <string> > > entry in notSentTuples) { string machine = entry.Key.Split(';')[0]; string sequence = entry.Key.Split(';')[1]; relationingSequences.Add("" + seq, "" + sequence); not_acked.Add(machine + ";" + seq + ";" + receivers_urls[0], entry.Value); RemoteAsyncProcessTuplesDelegate remoteDel = new RemoteAsyncProcessTuplesDelegate(op.doProcessTuples); seq += 1; IAsyncResult remoteResult = remoteDel.BeginInvoke(urls[0], "" + seq, entry.Value, null, null); //receiver.doProcessTuples(notSentTuples); } } else if (url.Equals(receiverUrls[0]) && this.receiver_routing.Equals(SysConfig.RANDOM)) //RANDOM ROUTING { foreach (KeyValuePair <string, IList <IList <string> > > entry in notSentTuples) { string machine = entry.Key.Split(';')[0]; string sequence = entry.Key.Split(';')[1]; relationingSequences.Add("" + seq, "" + sequence); not_acked.Add(machine + ";" + seq + ";" + receivers_urls[0], entry.Value); RemoteAsyncProcessTuplesDelegate remoteProcTupleDel = new RemoteAsyncProcessTuplesDelegate(op.doProcessTuples); seq += 1; IAsyncResult remoteResult = remoteProcTupleDel.BeginInvoke(urls[0], "" + seq, entry.Value, null, null); } } else if (this.receiver_routing.StartsWith(SysConfig.HASHING)) //HASHING ROUTING { foreach (int rep in res.Keys) { if (url.Equals(receiverUrls[rep])) { relationingSequences.Add("" + seq, "" + seq); not_acked.Add(this.urls[0] + ";" + seq + ";" + url, res[rep]); RemoteAsyncProcessTuplesDelegate remoteProcTupleDel = new RemoteAsyncProcessTuplesDelegate(op.doProcessTuples); seq += 1; IAsyncResult remoteResult = remoteProcTupleDel.BeginInvoke(this.urls[0], "" + seq, res[rep], null, null); } } } notSentTuples = new Dictionary <string, IList <IList <string> > >(); } } } else { foreach (string url in receivers_bad_urls) { sendDeadReplica(url); } receivers_bad_urls = new List <string>(); } }
private bool processTuples(string machine, string machine_seq, IList <IList <string> > tuples) { if (!canProcessTuples()) { notProcessedTuples.Add(machine + ";" + machine_seq, tuples); return(false); } Assembly assembly = Assembly.Load(this.opTypeCode); foreach (Type type in assembly.GetTypes()) { if (type.IsClass == true) { if (type.FullName.EndsWith("." + this.className)) { object ClassObj = Activator.CreateInstance(type); object[] args; object resultObject; IList <IList <string> > result = new List <IList <string> >(); string resu = ""; foreach (IList <string> tuple in tuples) { foreach (string s in tuple) { resu += s + ","; } resu += "\n"; } Console.WriteLine("DEBUG Before Processing:\n" + resu); if (className.Equals("UniqueOperator") || className.Equals("FilterOperator") || className.Equals("CountOperator") || className.Equals("DupOperator")) { args = new object[] { tuples, this.opSpecs }; resultObject = type.InvokeMember(this.method, BindingFlags.Default | BindingFlags.InvokeMethod, null, ClassObj, args); result = (IList <IList <string> >)resultObject; if (className.Equals("UniqueOperator")) { IList <IList <string> > aux2 = new List <IList <string> >(); foreach (IList <string> tup in result) { foreach (string str in tup) { IList <string> aux = new List <string>(); bool unique = true; foreach (string str_unique in uniqueTuples) { if (str_unique.Equals(str)) { unique = false; break; } } if (unique) { uniqueTuples.Add(str); aux.Add(str); aux2.Add(aux); } } } result = aux2; } } else { foreach (IList <string> tuple in tuples) { args = new object[] { tuple }; resultObject = type.InvokeMember(this.method, BindingFlags.Default | BindingFlags.InvokeMethod, null, ClassObj, args); IList <IList <string> > temp = (IList <IList <string> >)resultObject; foreach (List <string> t in temp) { result.Add(t); } } } resu = ""; foreach (IList <string> tuple in result) { foreach (string s in tuple) { resu += s + ","; } resu += "\n"; } Console.WriteLine("DEBUG After Processing:\n" + resu); if (fullLoggingLevel && result.Count > 0) { RemoteAsyncLogDelegate RemoteDel = new RemoteAsyncLogDelegate(puppet.registerLog); //converting to puppet master format IList <string> res = new List <string>(); foreach (IList <string> l in result) { String temp = ""; if (l.Count > 0) { temp += l[0]; } for (int i = 1; i < l.Count; i++) { temp += "," + l[i]; } res.Add(temp); } IAsyncResult RemAr = RemoteDel.BeginInvoke(urls[0], res, null, null); } if (receivers.Count == 0 && result.Count > 0) { notSentTuples.Add(machine + ";" + machine_seq, result); if (finalOperator && notSentTuples.Count > 0) { sendAckToPrevious(machine, machine_seq); //outputToFile(notSentTuples); notSentTuples = new Dictionary <string, IList <IList <string> > >(); } } else { if (receiver_routing.Equals(SysConfig.PRIMARY) && result.Count > 0) { relationingSequences.Add("" + seq, "" + machine_seq); not_acked.Add(machine + ";" + seq + ";" + receivers_urls[0], result); RemoteAsyncProcessTuplesDelegate remoteProcTupleDel = new RemoteAsyncProcessTuplesDelegate(receivers[0].doProcessTuples); seq += 1; IAsyncResult remoteResult = remoteProcTupleDel.BeginInvoke(this.urls[0], "" + seq, result, null, null); //receiver.doProcessTuples(result); } else if (receiver_routing.Equals(SysConfig.RANDOM) && result.Count > 0) //Random Routing { Random r = new Random(); receiver_target = r.Next() % receivers.Count(); relationingSequences.Add("" + seq, "" + machine_seq); not_acked.Add(machine + ";" + seq + ";" + receivers_urls[receiver_target], result); RemoteAsyncProcessTuplesDelegate remoteProcTupleDel = new RemoteAsyncProcessTuplesDelegate(receivers[receiver_target].doProcessTuples); seq += 1; IAsyncResult remoteResult = remoteProcTupleDel.BeginInvoke(this.urls[0], "" + seq, result, null, null); } else if (receiver_routing.StartsWith(SysConfig.HASHING) && result.Count > 0) //Hashing Routing { string[] aux = this.receiver_routing.Split('('); int field = Int32.Parse(aux[1].First() + ""); res = new Dictionary <int, IList <IList <string> > >(); foreach (IList <string> tuple in result) { int replica = Math.Abs(tuple[field - 1].GetHashCode()) % Int32.Parse(this.repFact); if (!res.ContainsKey(replica)) { IList <IList <string> > temp = new List <IList <string> >(); temp.Add(tuple); res.Add(replica, temp); } else { res[replica].Add(tuple); } } foreach (int rep in res.Keys) { relationingSequences.Add("" + seq, "" + machine_seq); not_acked.Add(machine + ";" + seq + ";" + receivers_urls[rep], res[rep]); RemoteAsyncProcessTuplesDelegate remoteProcTupleDel = new RemoteAsyncProcessTuplesDelegate(receivers[rep].doProcessTuples); seq += 1; IAsyncResult remoteResult = remoteProcTupleDel.BeginInvoke(this.urls[0], "" + seq, res[rep], null, null); } } } notProcessedTuples = new Dictionary <string, IList <IList <string> > >(); return(true); } } } throw (new System.Exception("could not invoke method")); }