[英]how akka ActorSystem process receives from actor
how can I make a process create Actor with ActorOf and allows actor to ping the parent process.如何让一个进程使用 ActorOf 创建 Actor 并允许 Actor ping 父进程。 My purpose is to allow an actor to send a signal to its parent process (ActorSystem main thread) to call system.terminate.
我的目的是允许演员向其父进程(ActorSystem 主线程)发送信号以调用 system.terminate。 But no clue how to do this.
但不知道如何做到这一点。 Here is snipit, but instead, I don't want to call terminate from the main, but rather get a signal from actor to call terminate.
这是 snipit,但相反,我不想从 main 调用 terminate,而是从 actor 获得一个信号来调用 terminate。 Is this doable?
这是可行的吗?
object MyTest {
def main(args: Array[String]): Unit = {
println("test test")
Thread.sleep(10000)
val system = ActorSystem("HelloSystem")
system.actorOf(TestActor.props("testactor"), name = "testactor")
system.terminate()
}
}
object TestActor {
def props(conf: String): Props = Props(new TestActor(conf))
case class AnswerMe(txt: String)
}
class TestActor(conf: String) extends Actor {
import TestActor._
override def receive: PartialFunction[Any, Unit] = {
case AnswerMe(txt) => {
println(s"$txt")
?? ! "answer"
}
}
}
I just figure out myself.我只是弄清楚自己。 I will simply pass the ActorSystem to the actor, then in the actor, it will call system.terminate.
我将简单地将 ActorSystem 传递给 actor,然后在 actor 中,它会调用 system.terminate。 then it will exit the parent.
然后它将退出父级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.