Yes, redefining supervisorStrategy . For example, from the documents :
import akka.actor.OneForOneStrategy import akka.actor.SupervisorStrategy._ import scala.concurrent.duration._ override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) { case _: ArithmeticException => Resume case _: NullPointerException => Restart case _: IllegalArgumentException => Stop case _: Exception => Escalate }
Then, after reading the note:
If a strategy is declared inside the controlling subject (as opposed to inside the accompanying object), its decisive element has access to all internal states of the actor in thread safe mode, including receiving a link to the current process that has not passed the child (available as the sender of the error message).
Therefore, instead of matching with the type of exception, you would have to match with the sender (just enter here, it may not compile):
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) { if (sender == SomeSpecialChild) Escalate else Restart }
There is nothing wrong with that, but if you have groups of children playing different roles, you should probably follow the first Akka rule (well, my first Akka rule): when in doubt, you probably want another actor. Create one actor to control role A and another to control role B. You still need to override supervisorStrategy , but the test will be simpler. And it will be easier to manage any other special differences between roles A and B.
Rob napier
source share