Пример #1
0
        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();
            }
        }
Пример #2
0
 public override void SendUserMessage(PID pid, object message, PID sender)
 {
     if (message is T)
     {
         _tcs.TrySetResult((T)message);
         pid.Stop();
     }
 }
Пример #3
0
        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)}");
            }
        }
Пример #4
0
        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();
            }
        }
Пример #5
0
        //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();
            }
        }
Пример #6
0
        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)}");
            }
        }