February 2018
Intermediate to advanced
552 pages
13h 46m
English
When an Actor throws any exception in its execution logic, sometimes its Supervior may decide to restart it. In this case, its preRestart() method is invoked before moving to the Restarted state. As part of this method, the Actor picks up all its subordinate Actors and stops them. Finally, it invokes its postStop() method, as shown here:
trait Actor{
def preStart(): Unit = ()
def postStop(): Unit = ()
def preRestart(reason: Throwable, message: Option[Any]): Unit = {
context.children foreach { child ⇒
context.unwatch(child)
context.stop(child)
}
postStop()
}
}
Read now
Unlock full access