0

I am assuming that A supervisor Actor is Supervising a remote actor. Is there any way to Restart the remote actor if that actor failed while processing the request. And if it is not possible the can anyone suggest me a way to solve this issue. Thank you in advance.

Prog_G
  • 1,539
  • 1
  • 8
  • 22

1 Answers1

2

Just set the restarting Supervision Strategy on the parent actor. I doesn't matter that the child actor is deployed remotely. https://doc.akka.io/docs/akka/current/fault-tolerance.html#creating-a-supervisor-strategy

Michal Borowiecki
  • 4,244
  • 1
  • 11
  • 18
  • But how will the supervisor know about the death of the remote actor? Can you explain me with an example? – Prog_G Apr 26 '18 at 11:55
  • Please read the documentation about how fault-tolerance works in akka: https://doc.akka.io/docs/akka/current/fault-tolerance.html There is an example at the bottom of that page. Also, the remoting section explains how failure detection works in case of loss of communication: https://doc.akka.io/docs/akka/current/remoting.html#watching-remote-actors – Michal Borowiecki Apr 26 '18 at 11:59
  • i am not able to restart the child actor. i am giving you an example nw. i have an actor as Supervisor. inside the supervisor actor prestart method i am creating a List of 10 Actors using `val actorList:List[ActorRef] = List.fill(10)( context.actorOf(Child.props, "child") )` – Prog_G May 02 '18 at 10:18
  • After that i am waiting for a message to terminate the child actor. After getting that message i am calling `context.stop(self)`. And then in the postStop() method i am throwing an custom exception. my supervisionStrategy is `def one: SupervisorStrategy = { OneForOneStrategy(maxNrOfRetries = 5, withinTimeRange = 10 seconds) { case _:customException => Restart } }` My child actor is not restarting. Can you tell me the error in this? – Prog_G May 02 '18 at 10:20
  • I'm not sure I understand your flow. The intention behind supervision strategies is that when an actor fails (an uncaught exception is thrown) the supervision strategy will restart it (or stop it, depending on the decider). Calling context.stop explicitly stops the actor. postStop is executed after it's already stopped, so I wouldn't think the exception from there has any effect. Instead of calling context.stop on itself, have the actor throw the exception immediately, then the supervision strategy has a chance to kick in. – Michal Borowiecki May 02 '18 at 12:44
  • I want to implement Supervision strategy for the worst case i.e if an actor stops suddenly because of some unknown error. So if any actor stops I want to restart it so that it doesn't affect the program. how to deal with this kind of scenario? – Prog_G May 02 '18 at 12:53
  • Stopping the actor explicitly via context.stop is nothing like the worst case. It is an intentional graceful shutdown of the actor. When an unknown error happens, an exception is thrown and that is what triggers the supervision strategy. – Michal Borowiecki May 02 '18 at 17:15
  • Okay. Thank you. In the same scenario how can i implement `BalancingPool` to the List of child actors. – Prog_G May 03 '18 at 04:52