private void HandleInvokeFailure(Exception cause, IEnumerable<IActorRef> childrenNotToSuspend = null)
{
// prevent any further messages to be processed until the actor has been restarted
if (!IsFailed)
{
try
{
SuspendNonRecursive();
if (CurrentMessage is Failed)
{
var failedChild = Sender;
childrenNotToSuspend = childrenNotToSuspend.Concat(failedChild); //Function handles childrenNotToSuspend being null
SetFailed(failedChild);
}
else
{
SetFailed(_self);
}
SuspendChildren(childrenNotToSuspend == null ? null : childrenNotToSuspend.ToList());
//Tell supervisor
Parent.Tell(new Failed(_self, cause, _self.Path.Uid));
}
catch (Exception e)
{
HandleNonFatalOrInterruptedException(() =>
{
Publish(new Error(e, _self.Path.ToString(), _actor.GetType(), "Emergency stop: exception in failure handling for " + cause));
try
{
StopChildren();
}
finally
{
FinishTerminate();
}
});
}
}
}