Hi Paolo,
relying on the guardian to get things right is not recommended for real applications: typically your application will have several components which when failing require the application to stop or respond in some very specific manner. Hence my recommendation would be to just create a single top-level actor for one application, which will then create the “top-level” services as its children. This allows you to have full control over all failure scenarios and also enables you to cleanly shutdown the system if this application guardian detects a fatal error condition.
Now to your question: if you don’t put any code in preStart, then it will also not fail. The application guardian could look like this:
class MyApp extends Actor {
override val supervisorStrategy = …
def receive = {
case START =>
context.actorOf(Props[ServiceA], "serviceA")
…
}
// or set StoppingStrategy for the guardian (see akka.actor.guardian-supervisor-strategy)
override def preRestart(...) { context.system.shutdown(); context.stop(self) }
}
and then have a main() which does:
val sys = ActorSystem(…)
sys.actorOf(Props[MyApp], "app") ! START
If anything goes wrong within the MyApp actor, the system will be shut down (or you can do whatever is appropriate).
Regards,
Roland
Dr. Roland KuhnAkka Tech LeadTypesafe – Empowering professional developers to build amazing apps.
twitter:
@rolandkuhn