=doc #3689 Make activator template for akka.Main
This commit is contained in:
parent
8b6b2965e5
commit
362074177a
25 changed files with 428 additions and 184 deletions
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package sample.hello
|
||||
|
||||
import akka.actor.Actor
|
||||
|
||||
object Greeter {
|
||||
case object Greet
|
||||
case object Done
|
||||
}
|
||||
|
||||
class Greeter extends Actor {
|
||||
def receive = {
|
||||
case Greeter.Greet ⇒
|
||||
println("Hello World!")
|
||||
sender ! Greeter.Done
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package sample.hello
|
||||
|
||||
import akka.actor.Actor
|
||||
import akka.actor.Props
|
||||
|
||||
class HelloWorld extends Actor {
|
||||
|
||||
override def preStart(): Unit = {
|
||||
// create the greeter actor
|
||||
val greeter = context.actorOf(Props[Greeter], "greeter")
|
||||
// tell it to perform the greeting
|
||||
greeter ! Greeter.Greet
|
||||
}
|
||||
|
||||
def receive = {
|
||||
// when the greeter is done, stop this actor and with it the application
|
||||
case Greeter.Done ⇒ context.stop(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package sample.hello
|
||||
|
||||
object Main {
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
akka.Main.main(Array(classOf[HelloWorld].getName))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
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 = {
|
||||
case Terminated(_) ⇒
|
||||
log.info("{} has terminated, shutting down system", ref.path)
|
||||
context.system.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue