//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(); } }