akka-actor(嘿咻demo)

import akka.actor.Actor
import akka.actor.ActorRef
import akka.actor.actorRef2Scala
import akka.actor.ActorSystem
import akka.actor.Props


object HeiXiuMain extends App {
  val system = ActorSystem("heixiu-actor")
  val hei = system.actorOf(Props[HeiActor], name = "hei")
  val xiu = system.actorOf(Props(new XiuActor(hei)), name = "xiu")
  xiu ! "start"


  Thread.sleep(10)
  system.shutdown()
}
class XiuActor(hei: ActorRef) extends Actor {
  def receive = {
    case "start" => hei ! "xiu"
    case "hei" =>
      println("咻")
      hei ! "xiu"
    case _ => println("嘿咻")
  }
}
class HeiActor() extends Actor {
  def receive = {
    case "xiu" =>
      println("嘿")
      sender ! "hei"
    case _ => println("嘿咻")
  }
}

你可能感兴趣的:(akka)