package com.bjsxt
import scala.actors.Actor
case class Message(actor:Actor,msg:String)
class MyActor1 extends Actor {
def act(): Unit = {
while(true){
receive {
case message:Message =>{
if(message.msg.equals("hello~")){
println("hello~")
message.actor ! "hi~"
}else if(message.msg.equals("could we have a date?")){
println("could we have a date?")
message.actor ! "no..."
}
}
case _ =>println("no match ...")
}
}
}
}
class MyActor2(actor:Actor) extends Actor {
actor ! Message(this,"hello~")
def act(): Unit = {
while(true){
receive {
case s:String =>{
if(s.equals("hi~")){
println("hi~")
actor ! Message(this,"could we have a date?")
}else if(s.equals("no...")){
println("no...")
println("。。。。。。。。。。")
}
}
case _ =>println("no match ...")
}
}
}
}
object Lesson_Actor02 {
def main(args: Array[String]): Unit = {
val actor1 = new MyActor1()
val actor2 = new MyActor2(actor1)
actor1.start()
actor2.start()
}
}
Akka communication model in scala
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326170697&siteId=291194637
Recommended
Ranking