test

我是帅哥我会乱说吗

actor模型
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import akka.actor.{ActorPath, ActorSelection}

/**
* @author Barudisshu
*/
object GreetingsActor extends App {

import akka.actor.{Actor, ActorSystem, Props}

case class Name(name: String)

class GreetingsActor extends Actor {
override def receive: Receive = {
case Name(n) => println("Hello " + n)
case name: String => println("Goodbye " + name)
}
}

val system = ActorSystem("greetings")
val a = system.actorOf(Props[GreetingsActor], name = "greetings-actor")

a ! Name("Nilanjan")
a ! "World"

val path : ActorPath = system / "GreetingsActor"
val actorSelection: ActorSelection = system.actorSelection(path)

actorSelection ! Name

Thread.sleep(50)
system.shutdown()
}