|
Akka/Scala example source code file (Main.scala)
The Main.scala Akka example source code/** * Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> */ package akka import akka.actor.ActorSystem import akka.actor.ExtendedActorSystem import akka.actor.Actor import akka.actor.Terminated import akka.actor.ActorLogging import akka.actor.Props import akka.actor.ActorRef import scala.util.control.NonFatal /** * Main class to start an [[akka.actor.ActorSystem]] with one * top level application supervisor actor. It will shutdown * the actor system when the top level actor is terminated. */ object Main { /** * @param args one argument: the class of the application supervisor actor */ def main(args: Array[String]): Unit = { if (args.length != 1) { println("you need to provide exactly one argument: the class of the application supervisor actor") } else { val system = ActorSystem("Main") try { val appClass = system.asInstanceOf[ExtendedActorSystem].dynamicAccess.getClassFor[Actor](args(0)).get val app = system.actorOf(Props(appClass), "app") val terminator = system.actorOf(Props(classOf[Terminator], app), "app-terminator") } catch { case NonFatal(e) ⇒ system.shutdown(); throw e } } } class Terminator(app: ActorRef) extends Actor with ActorLogging { context watch app def receive = { case Terminated(_) ⇒ log.info("application supervisor has terminated, shutting down") context.system.shutdown() } } } Other Akka source code examplesHere is a short list of links related to this Akka Main.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.