Reputation: 907
How can I get the actorRef or name of the failing node? I need to restart the node if the exception happens once. If the exception happens > 1, then I need to resume.
My thought was to have the supervisor store how many times a given node has had the exception - but I can't figure out which node failed. Maybe the approach is bad.
x would be the count of times the failing node had a given exception.
OneForOneStrategy() {
case _: FileNotFoundException =>
// Need to know how many times node n has had this exception and restart/resume as required.
if(x == 1)
Restart
else
Resume
case _: Exception => Stop
}
Upvotes: 1
Views: 72
Reputation: 26
Actually in supervisor's Decider you can obtain the failing child's ActorRef via sender() method.
Upvotes: 1
Reputation: 8901
You could catch the FileNotFoundException
and throw a CustomException
that has an ActorRef field set to the excepting Actor (self). Then in your OneForOne, you catch the CustomException
that has the ActorRef
field set to the problem actor. So now you have a reference to the failing actor, then check the exception count as you described inside your supervisor and make the call on whether or not to restart/resume.
Upvotes: 1