Getting Started tutorial improvements (#23210)

This commit is contained in:
Arnout Engelen 2017-07-13 01:24:53 -07:00 committed by GitHub
parent d87cf4aec4
commit f38b928e13
67 changed files with 1451 additions and 1507 deletions

View file

@ -1,9 +1,12 @@
package tutorial_1
import akka.actor.{ Actor, Props }
import akka.testkit.AkkaSpec
// Prevent package clashes with the Java examples:
package docs.tutorial_1
//#print-refs
package com.lightbend.akka.sample
import akka.actor.{ Actor, Props, ActorSystem }
import scala.io.StdIn
class PrintMyActorRefActor extends Actor {
override def receive: Receive = {
case "printit" =>
@ -13,6 +16,8 @@ class PrintMyActorRefActor extends Actor {
}
//#print-refs
import akka.testkit.AkkaSpec
//#start-stop
class StartStopActor1 extends Actor {
override def preStart(): Unit = {
@ -62,30 +67,38 @@ class ActorHierarchyExperiments extends AkkaSpec {
// format: OFF
//#print-refs
val firstRef = system.actorOf(Props[PrintMyActorRefActor], "first-actor")
println(s"First : $firstRef")
firstRef ! "printit"
object ActorHierarchyExperiments extends App {
val system = ActorSystem()
val firstRef = system.actorOf(Props[PrintMyActorRefActor], "first-actor")
println(s"First: $firstRef")
firstRef ! "printit"
println(">>> Press ENTER to exit <<<")
try StdIn.readLine()
finally system.terminate()
}
//#print-refs
// format: ON
}
"start and stop actors" in {
// format: OFF
//#start-stop
//#start-stop-main
val first = system.actorOf(Props[StartStopActor1], "first")
first ! "stop"
//#start-stop
//#start-stop-main
// format: ON
}
"supervise actors" in {
// format: OFF
//#supervise
//#supervise-main
val supervisingActor = system.actorOf(Props[SupervisingActor], "supervising-actor")
supervisingActor ! "failChild"
//#supervise
//#supervise-main
// format: ON
}
}