public void HandleFailure(ISupervisor supervisor, PID child, Exception reason) { var directive = _decider(child, reason); switch (directive) { case SupervisorDirective.Resume: //resume the failing child child.SendSystemMessage(ResumeMailbox.Instance); break; case SupervisorDirective.Restart: //restart the failing child child.SendSystemMessage(new Restart()); break; case SupervisorDirective.Stop: //stop the failing child child.Stop(); break; case SupervisorDirective.Escalate: supervisor.EscalateFailure(child, reason); break; default: throw new ArgumentOutOfRangeException(); } }
public override void SendUserMessage(PID pid, object message, PID sender) { if (message is T) { _tcs.TrySetResult((T)message); pid.Stop(); } }
protected internal override void SendUserMessage(PID pid, object message) { var env = MessageEnvelope.Unwrap(message); if (env.message is T || message == null) { if (_cts != null && _cts.IsCancellationRequested) { pid.Stop(); return; } _tcs.TrySetResult((T)env.message); pid.Stop(); } else { throw new InvalidOperationException($"Unexpected message. Was type {env.message.GetType()} but expected {typeof(T)}"); } }
public override void SendUserMessage(PID pid, object message, PID sender) { if (message is T) { if (_cts != null && _cts.IsCancellationRequested) { return; } _tcs.TrySetResult((T)message); pid.Stop(); } }
//public bool RequestRestartPermission(int maxNrOfRetries, TimeSpan? withinTimeSpan) //{ // if (maxNrOfRetries == 0) // { // return false; // } // FailureCount++; // //supervisor says child may restart, and we don't care about any timewindow // if (withinTimeSpan == null) // { // return FailureCount <= maxNrOfRetries; // } // var max = DateTime.Now - withinTimeSpan; // if (LastFailureTime > max) // { // return FailureCount <= maxNrOfRetries; // } // //we are past the time limit, we can safely reset the failure count and restart // FailureCount = 0; // return true; //} public void HandleFailure(ISupervisor supervisor, PID child, RestartStatistics crs, Exception reason) { var directive = _decider(child, reason); switch (directive) { case SupervisorDirective.Resume: //resume the failing child child.SendSystemMessage(ResumeMailbox.Instance); break; case SupervisorDirective.Restart: //restart the failing child if (crs.RequestRestartPermission(_maxNrOfRetries, _withinTimeSpan)) { Console.WriteLine($"Restarting {child.ToShortString()} Reason {reason}"); child.SendSystemMessage(Restart.Instance); } else { Console.WriteLine($"Stopping {child.ToShortString()} Reason { reason}"); child.Stop(); } break; case SupervisorDirective.Stop: //stop the failing child Console.WriteLine($"Stopping {child.ToShortString()} Reason {reason}"); child.Stop(); break; case SupervisorDirective.Escalate: supervisor.EscalateFailure(child, reason); break; default: throw new ArgumentOutOfRangeException(); } }
public override void SendUserMessage(PID pid, object message, PID sender) { if (message is T || message == null) { if (_cts != null && _cts.IsCancellationRequested) { return; } _tcs.TrySetResult((T)message); pid.Stop(); } else { throw new InvalidOperationException($"Unexpected message. Was type {message.GetType()} but expected {typeof(T)}"); } }