public override void execute(string[] args) { if (args.Length < 2) { throw new WrongNumberOfArgsException(); } OperatorBuilder opb; int interval; if ((opb = operatorsInfo.getOpInfo(args[0])) == null) { throw new WrongOperatorException(); } if (!int.TryParse(args[1], out interval)) { throw new WrongTypeOfArgException(); } foreach (string addr in opb.Addresses) { ReplicaInterface obj = (ReplicaInterface)Activator.GetObject(typeof(ReplicaInterface), addr); RemoteAsyncDelegateWithTime RemoteDel = new RemoteAsyncDelegateWithTime(obj.Interval); IAsyncResult RemAr = RemoteDel.BeginInvoke(interval, null, obj); } }
public override void execute(string[] args) { if (args.Length < 2) { throw new WrongNumberOfArgsException(); } OperatorBuilder opb; int repIndex; if ((opb = operatorsInfo.getOpInfo(args[0])) == null) { throw new WrongOperatorException(); } if (!int.TryParse(args[1], out repIndex)) { throw new WrongTypeOfArgException(); } if (!(repIndex < opb.Addresses.Count && repIndex >= 0)) { throw new IndexOutOfBoundsException(); } ReplicaInterface obj = (ReplicaInterface)Activator.GetObject(typeof(ReplicaInterface), opb.Addresses[repIndex]); RemoteAsyncDelegate RemoteDel = new RemoteAsyncDelegate(obj.Unfreeze); IAsyncResult RemAr = RemoteDel.BeginInvoke(null, obj); }
public override void sendTuple(ReplicaInterface replica, TupleWrapper tuple) { Console.WriteLine("\n Inside sendTuple"); Exception exception = null; var thread = new Thread(() => { try { replica.addTuple(tuple); } catch (Exception e) { exception = e; } }); thread.Start(); if (!thread.Join(TIMEOUT_VALUE)) { Console.WriteLine("####### didnt finish call in 5 seconds"); thread.Abort(); //throw new TimeoutException(); throw new CouldNotSendTupleException(); } if (exception != null) { throw exception; } }
public override List <string[]> Operate(string[] tuple) { string element = tuple[fieldIndex]; if (wasElementSeen(element)) { return(null); } processedTuple(tuple); bool wasInOther = false; foreach (string s in OtherReplicas) { try { ReplicaInterface rep = getGeneralReplica(s); if (wasInOther = rep.wasElementSeen(element)) { break; } } catch (System.Net.Sockets.SocketException) { } } if (wasInOther) { return(null); } List <string[]> l = new List <string[]>(); l.Add(tuple); return(l); }
public void sendToNext(TupleWrapper tuple) { if (nextOperator.Count != 0) { ReplicaInterface replica = null; string outputReplica = calculateNext(tuple.Tuple); try { replica = (ReplicaInterface)Activator.GetObject(typeof(ReplicaInterface), outputReplica); } catch (System.Net.Sockets.SocketException e) { Console.WriteLine("Error with host " + outputReplica); Console.WriteLine(e); } try { // TODO FIXME something not right with tuple on mylib.dll version of professors semantics.sendTuple(replica, tuple); } catch (System.Net.Sockets.SocketException) { // The replica is dead Console.WriteLine(" ##!! " + outputReplica + " was down, removed from nextOperator list. Resending !!##\n"); nextOperator.Remove(outputReplica); sendToNext(tuple); } catch (CouldNotSendTupleException) { // The replica is alive, but slow Console.WriteLine(" ##!! " + outputReplica + " did not respond in time. Resending !!##\n"); sendToNext(tuple); } catch (Exception) { } } //ELSE can write on file }
private void confirmElectionRelay(TupleWrapper t, ReplicaInterface r, string replicaAddr, ref int counter, ref object o) { r.confirmElection(t, replicaAddress); lock (o) { counter++; } }
/// <summary>Infinit cicle for checking the state of other replicas ant take mesures</summary> public void failureDetector() { while (true) { Thread.Sleep(5000); List <string> otherReplicasURLcopy = allReplicasURL.ToList(); otherReplicasURLcopy.Remove(replicaAddress); foreach (string url in otherReplicasURLcopy) { Console.WriteLine("ping to {0}", url); try { Exception exception = null; ReplicaInterface replica = (ReplicaInterface)Activator.GetObject(typeof(ReplicaInterface), url); var thread = new Thread(() => { try { replica.ping(replicaAddress, true); } catch (Exception e) { exception = e; } }); thread.Start(); var completed = thread.Join(500); if (!completed) { completed = thread.Join(500); if (!completed) { completed = thread.Join(1000); if (!completed) { completed = thread.Join(1000); if (!completed) { completed = thread.Join(2000); } } } } if (!completed) { Console.WriteLine("!!!ping to {0} failed", url); failedPings[url] = failedPings[url] + 1; thread.Abort(); if (failedPings[url] == 6) //TODO reduce the time needed to fail, or not { failedPings[url] = 0; handleSlowReplica(url); } } if (exception != null) { Console.WriteLine("!!! {0} is crashed", url); handleCrashedReplica(url); } } catch { Console.WriteLine("!!!exception on failure detection"); } } } }
private ReplicaInterface getReplica(string url) { try { ReplicaInterface ri = (ReplicaInterface)Activator.GetObject(typeof(ReplicaInterface), url); return(ri); } catch (System.Net.Sockets.SocketException e) { Console.WriteLine("Error with host " + url); Console.WriteLine(e); } return(null); }
protected ReplicaInterface getGeneralReplica(string url) { ReplicaInterface obj = null; try { obj = (ReplicaInterface)Activator.GetObject(typeof(ReplicaInterface), url); } catch (System.Net.Sockets.SocketException e) { Console.WriteLine("Error with host " + url); Console.WriteLine(e); } return(obj); }
public override List <string[]> Operate(string[] tuple) { int globalCounter = ++counter; foreach (string url in OtherReplicas) { try { ReplicaInterface r = getGeneralReplica(url); globalCounter += r.numberOfProcessedTuples(); } catch (System.Net.Sockets.SocketException) { } } List <string[]> l = new List <string[]>(); string[] tupleOut = { globalCounter.ToString() }; l.Add(tupleOut); return(l); }
public override void execute(string[] args) { if (args.Length == 0) { throw new WrongNumberOfArgsException(); } OperatorBuilder opb; if ((opb = operatorsInfo.getOpInfo(args[0])) == null) { throw new WrongOperatorException(); } foreach (string addr in opb.Addresses) { ReplicaInterface obj = (ReplicaInterface)Activator.GetObject(typeof(ReplicaInterface), addr); RemoteAsyncDelegate RemoteDel = new RemoteAsyncDelegate(obj.Start); IAsyncResult RemAr = RemoteDel.BeginInvoke(null, obj); } }
private void tryElectionOfProcessingReplicaRelay(TupleWrapper t, ReplicaInterface r, string replicaAddress) { r.tryElectionOfProcessingReplica(t, replicaAddress); }
public abstract void sendTuple(ReplicaInterface replica, TupleWrapper tuple);
public override void sendTuple(ReplicaInterface replica, TupleWrapper tuple) { RemoteAsyncDelegate RemoteDel = new RemoteAsyncDelegate(replica.addTuple); IAsyncResult RemAr = RemoteDel.BeginInvoke(tuple, null, replica); }
public override void sendTuple(ReplicaInterface replica, TupleWrapper tuple) { alos.sendTuple(replica, tuple); }
private void callSpecificReplica(string address) { ReplicaInterface obj = (ReplicaInterface)Activator.GetObject(typeof(ReplicaInterface), address); RemoteAsyncDelegate RemoteDel = new RemoteAsyncDelegate(obj.Status); IAsyncResult RemAr = RemoteDel.BeginInvoke(null, obj); }