public List <string> DestributeTuple(TuplePack toAnnounce, List <string> siblingsUrls) { // assures that we don't stay in while loop so often // and in the case of need to mantain state we get the tuple asap! List <string> sucessfullySent = new List <string>(); foreach (string siblingUrl in siblingsUrls) { try { var replica = (ISibling)Activator.GetObject(typeof(ISibling), siblingUrl); replica.AnnounceTuple(toAnnounce); sucessfullySent.Add(siblingUrl); } // crashed - theres nothing we can do catch (SocketException e) { sucessfullySent.Add(siblingUrl); } // maybe slowed - we need to assure that it gets there catch (SlowException e) { } } return(sucessfullySent); }
public IList <TuplePack> Process(TuplePack input) { return(new List <TuplePack>() { input }); }
public IList <TuplePack> Process(TuplePack input) { // Check if the index is valid in the list int size = _fieldNumber + 1; if (!(size <= input.Content.Count)) { return(null); } IList <TuplePack> outputList = new List <TuplePack>() { input }; switch (_condition) { case ">": return(String.Compare(input.Content[_fieldNumber], _value) > 0 ? outputList : null); case "<": return(String.Compare(input.Content[_fieldNumber], _value) < 0 ? outputList : null); case "=": return(String.Compare(input.Content[_fieldNumber], _value) == 0 ? outputList : null); default: return(null); } }
public override void Route(TuplePack input) { System.Random rnd = new System.Random(); // rnd.Next(replica.Count) - number between [0;replica.count[ int randomInt = rnd.Next(_urls.Count); SendTuplePack(randomInt, _urls, input); }
public override void Dispatch(TuplePack input) { Console.WriteLine(input); // put job in queue SlaveObj.AddJob(input); // behave likea slow network/operator Thread.Sleep(SlaveObj.RandSeed.Next(1000, 5000)); throw new SlowException(); }
/// auxiliary: add job to jobQueue public void AddJob(TuplePack tuple) { Console.WriteLine(tuple); if (_jobQueue.Contains(tuple)) { return; } _jobQueue.Enqueue(tuple); }
public override void Route(TuplePack input) { int hashNumber = 0; if (_urls.Count != 0) { hashNumber = (input.Content[_fieldId - 1].GetHashCode() % (_urls.Count)); } SendTuplePack(hashNumber, _urls, input); }
public override void AnnounceTuple(TuplePack toAnnounce) { if (!SlaveObj.SeenTuplePacks.Contains(toAnnounce)) { SlaveObj.SeenTuplePacks.Add(toAnnounce); // if I belong to a operator that needs to mantain state I need to process if (SlaveObj.Stateful) { SlaveObj.ProcessObj.Process(toAnnounce); } } }
public IList <TuplePack> Process(TuplePack input) { _seenTuples++; List <string> output = new List <string>() { _seenTuples.ToString() }; return(new List <TuplePack>() { new TuplePack(0, null, output) }); }
public IList <TuplePack> Process(TuplePack input) { if (_fieldNumber + 1 <= input.Content.Count) { if (!_seenTuples.Contains(input.Content[_fieldNumber])) { _seenTuples.Add(input.Content[_fieldNumber]); return(new List <TuplePack>() { input }); } } return(null); }
public IList <TuplePack> Process(TuplePack input) { object output = null; try { // C# Reflection var importDll = Assembly.LoadFile(Environment.CurrentDirectory + @"\..\..\..\Inputs\" + _dll); // The substring is used to cut the .dll, since we need the namespace string ns = _dll.Substring(0, _dll.IndexOf(".")); Type type = importDll.GetType(ns + "." + _invokeClass); object instance = Activator.CreateInstance(type); output = type.InvokeMember( _method, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, instance, new object[] { input.Content }); } catch (Exception e) { Console.WriteLine("Exception at custom operator: " + e.GetBaseException()); } IList <IList <string> > res = (IList <IList <string> >)output; IList <TuplePack> outputTuplePacks = new List <TuplePack>(); if (res != null) { foreach (var var in res) { List <string> trimmed = new List <string>(); foreach (var str in var) { trimmed.Add(str.Trim()); } TuplePack newTuplePack = new TuplePack(0, string.Empty, trimmed); outputTuplePacks.Add(newTuplePack); } } return(outputTuplePacks.Count == 0 ? null : outputTuplePacks); }
public override void Dispatch(TuplePack input) { // start command was issued || unfreeze happened if (input == null) { // try importing IList <Dictionary <int, string> > tuplesLists = SlaveObj.ImportObj.Import(); // input comes from upstream operator (via routing) || // already imported my tuples and I got unfrozen if (tuplesLists == null) { return; } // first list my tuples // second list siblings tuples if (tuplesLists.Count == 2) { SlaveObj.BufferFirstOperatorLines = tuplesLists[1]; } foreach (var l in tuplesLists[0]) { Console.WriteLine(l.Key + "||" + l.Value); } /* * // input via file * int packNumber = 0; * foreach (string s in tuples) * { * ProcessRoutePack(new TuplePack(packNumber++, "File Imported", SplitTuple(s))); * } * } * // upstream operator has sent a tuple * else * { * ProcessRoutePack(input); * }*/ } }
// if it there is someone that respondes false, then he is processing something public override bool TryToPurpose(TuplePack input) { List <bool> purposed = new List <bool>(); foreach (string siblingUrl in SlaveObj.Siblings) { try { var replica = (ISibling)Activator.GetObject(typeof(ISibling), siblingUrl); purposed.Add(replica.Purpose(input)); } // he is dead or slowed so it's opinion doens't count catch (Exception e) { } } // i am alone I can assume I am my own boss if (purposed.Count == 0) { return(false); } return(!purposed.Contains(false)); }
private void TryAgain(TuplePack inputPack, int index, List <string> urls) { Console.WriteLine("Could not locate " + urls[index]); // try again dynamic reconfiguration if (!_invalidIndexes.Contains(index)) { _invalidIndexes.Enqueue(index); } if (_invalidIndexes.Count == urls.Count) { Console.WriteLine("All downstream replicas are DOWN!"); return; } for (int i = 0; i < urls.Count; i++) { if (!_invalidIndexes.Contains(i)) { CallNextReplica(i, urls, inputPack); return; } } }
private List <bool> MayIProcess(TuplePack input) { List <bool> decisions = new List <bool>(); List <string> toRemove = new List <string>(); Siblings = new List <ISibling>(); // Query my brothers foreach (string siblingUrl in SlaveObj.Siblings) { try { ISibling replica = (ISibling)Activator.GetObject(typeof(ISibling), siblingUrl); Siblings.Add(replica); decisions.Add(replica.PollTuple(input)); } catch (SocketException e) { // Sibling has crashed don't consider it toRemove.Add(siblingUrl); } catch (NotImplementedException e) { // Sibling doens't respond } catch (Exception e) { Console.WriteLine(e.GetBaseException()); } } // remove the siblings that don't need to be considered foreach (var siblingurl in toRemove) { SlaveObj.Siblings.Remove(siblingurl); } return(decisions); }
// do stuff public void Dispatch(TuplePack input) { Console.WriteLine("Dispatch method called..."); /*if (_semantic.ToLower().Equals("exactly-once")) { * if(input != null && ! * RouteObj.IsLast()) { * // Exponencial backoff * double baseExponent = 9; * bool whileCond = true; * while (whileCond) * { * try * { * // maybe one of my brothers already seen it and i don't need to purpose * whileCond = State.TryToPurpose(input); * if (SeenTuplePacks.Contains(input)) * return; * Console.WriteLine("Purposing tuple to my sibilings!!"); * Thread.Sleep(Convert.ToInt32((Math.Pow(2, baseExponent) - 1)/2)); * baseExponent += _rnd.NextDouble(); * } * catch (Exception e) * { * Console.WriteLine("lololsoslls"); * whileCond = false; * } * } * } * lock (this) * { * _state.Dispatch(input); * } * } * else */ _state.Dispatch(input); }
private void CallNextReplica(int index, List <string> urls, TuplePack inputPack) { RemoteAsyncDelegate remoteDel = new RemoteAsyncDelegate(GetDownstreamReplicas(urls)[index].Dispatch); if (_semantic.Equals("at-most-once")) { remoteDel.BeginInvoke(inputPack, null, null); } else if (_semantic.Equals("exactly-once") || _semantic.Equals("at-least-once")) { remoteDel.BeginInvoke( inputPack, (IAsyncResult ar) => { try { remoteDel.EndInvoke(ar); } // it crashed catch (SocketException e) { TryAgain(inputPack, index, urls); } // it may be slowed catch (Exception e) { TryAgain(inputPack, index, urls); } }, null); } else { Console.WriteLine("I don't support such semantic!"); } }
public bool PollTuple(TuplePack toRoute) { return(State.PollTuple(toRoute)); }
public abstract void AnnounceTuple(TuplePack toAnnounce);
public abstract bool TryToPurpose(TuplePack purpose);
public abstract bool Purpose(TuplePack toDispatch);
public override bool PollTuple(TuplePack toRoute) { return(SlaveObj.SeenTuplePacks.Contains(toRoute)); }
// Responsible to process and route the tuples private void ProcessRoutePack(TuplePack input) { /*SleepInterval(SlaveObj.IntervalValue); * Console.WriteLine("Let's see if I have to process: " + input); * * if (SlaveObj.SeenTuplePacks.Contains(input)) * { * Console.WriteLine("I already seen that tuple!"); * return; * } * * // Check if the tuple was already seen * if (SlaveObj.Semantic.Equals("exactly-once")) * { * Console.WriteLine("Deciding with my siblings..."); * // while loop: * // break conditions: * // -> if one of the decisions is false, its sign that the tuple hasn't been processed. * // -> if all the decisions are false and the number of them it's equal to the siblings number - then you can assume that none processed. * // so try again until you can match the break conditions. * while (true) * { * Thread.Sleep(SlaveObj.RandSeed.Next(800, 1500)); * List<bool> decisions = MayIProcess(input); * // Can't know for sure if the input has been processed, since a sibling didn't respond * if (AlreadySeen(decisions)) * { * Console.WriteLine("Tuple has already been seen by one of my siblings!"); * return; * } * if (decisions.Count == Siblings.Count && NoneSeen(decisions)) * break; * } * } * * IList<TuplePack> tuplesList = SlaveObj.ProcessObj.Process(input); * * if (tuplesList != null) * { * string processedTuples = string.Empty; * foreach (var tuplepack in tuplesList) * { * tuplepack.OpUrl = SlaveObj.Url; * tuplepack.SeqNumber = SlaveObj.SeqNumber; * SlaveObj.SeqNumber++; * * // Route * SlaveObj.RouteObj.Route(tuplepack); * * // If I processed I have seen it * if (SlaveObj.Semantic.Equals("exactly-once")) { * SlaveObj.SeenTuplePacks.Add(input); * List<string> sucesffulySent = DestributeTuple(input, SlaveObj.Siblings); * // if I need to mantain the state I need to assure that all of my siblings get the tuple * if (SlaveObj.Stateful) * { * // avoid resend to the siblings that already received * int difference = SlaveObj.Siblings.Count - sucesffulySent.Count; * while (difference != 0) * { * sucesffulySent = DestributeTuple(input, sucesffulySent); * difference = difference - sucesffulySent.Count; * } * } * } * * ReplicaUpdate(SlaveObj.Url, tuplepack.Content); * // Debug purposes * processedTuples += tuplepack.Content.Count == 1 ? tuplepack.Content[0] + " " : MergeOutput(tuplepack.Content) + " "; * } * Console.WriteLine("Processed from: " + MergeOutput(input.Content) + " : " + processedTuples); * }*/ }
public override bool Purpose(TuplePack toDispatch) { return(Monitor.IsEntered(SlaveObj)); }
public override bool TryToPurpose(TuplePack purpose) { throw new NotImplementedException(); }
public override bool Purpose(TuplePack toDispatch) { throw new NotImplementedException(); }
public override void AnnounceTuple(TuplePack toAnnounce) { throw new NotImplementedException(); }
public void AnnounceTuple(TuplePack toAnnounce) { State.AnnounceTuple(toAnnounce); }
public bool Purpose(TuplePack toDispatch) { return(State.Purpose(toDispatch)); }
public override bool PollTuple(TuplePack toRoute) { throw new NotImplementedException(); }