2.2 Spotlight: Running Actor Apps with akka.Main

One high-level pattern we have recommended often in the past is to minimize the number of top-level actors, which in its logical consequence means to have only exactly one of these. This one top-level actor represents the whole application life-cycle: its constructor is equivalent to a traditional main class in Java and its supervisorStrategy determines which components of the application can be restarted and which failures are fatal.

In the actor above the web front-end is restartable while a failure in the database brings down the whole application (just as a contrived example). This works by stopping the database actor which will trigger DeathWatch to send us a Terminated message upon which we stop ourselves. This actor can be run as a main program like this:

java -classpath <scala, akka and what you need> akka.Main demo.TopLevel

For more information see the API docs for Java and Scala.

Recent comments

Blog comments powered by Disqus

1 Notes

  1. hakkers posted this