Re: [akka-user] How catch exception raise in the preStart method for top level actor

223 views
Skip to first unread message

Roland Kuhn

unread,
Feb 7, 2013, 4:23:20 PM2/7/13
to akka...@googlegroups.com
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


7 feb 2013 kl. 13:57 skrev Paolo Di Tommaso:

Dear all, 

I'm wondering how to catch an exception raised in the preStart for a top-level actor. 

As far I've understood for children actors I can override the default SupervisorStrategy to handle it. But how to manage it for the top most actor ? 


Cheers,
Paolo


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Empowering professional developers to build amazing apps.
twitter: @rolandkuhn

Reply all
Reply to author
Forward
0 new messages