2013-11-15 11:53:21 +01:00
|
|
|
package sample.hello
|
|
|
|
|
|
|
|
|
|
import akka.actor.ActorSystem
|
|
|
|
|
import akka.actor.Props
|
|
|
|
|
import akka.actor.ActorRef
|
|
|
|
|
import akka.actor.Actor
|
|
|
|
|
import akka.actor.ActorLogging
|
|
|
|
|
import akka.actor.Terminated
|
|
|
|
|
|
|
|
|
|
object Main2 {
|
|
|
|
|
|
|
|
|
|
def main(args: Array[String]): Unit = {
|
|
|
|
|
val system = ActorSystem("Hello")
|
|
|
|
|
val a = system.actorOf(Props[HelloWorld], "helloWorld")
|
|
|
|
|
system.actorOf(Props(classOf[Terminator], a), "terminator")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Terminator(ref: ActorRef) extends Actor with ActorLogging {
|
|
|
|
|
context watch ref
|
|
|
|
|
def receive = {
|
2013-12-03 16:34:26 +01:00
|
|
|
case Terminated(_) =>
|
2013-11-15 11:53:21 +01:00
|
|
|
log.info("{} has terminated, shutting down system", ref.path)
|
2014-08-25 15:49:28 +02:00
|
|
|
context.system.terminate()
|
2013-11-15 11:53:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|