Applying the supervision strategy

While overriding the default supervisorStrategy, all we do is define the value with arguments and provide a Decider; this decider contains the logic to be implemented in case of exceptions. It looks like this:

import{Resume, Restart} 
override val supervisorStrategy = 
    maxNrOfRetries = 3, 
    withinTimeRange = 1 minute 
    case _: ArithmeticException => {"Supervisor handling ArithmeticException! n Resuming!") 
    case _: Exception => {"Supervisor handling Exception! n Restarting!") 

Here, we have defined a OneForOneStrategy, and on a case by case basis, the action to be performed in regards to the failing actor. A full example ...

Get Learning Scala Programming now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.