如何在 Akka 中向演员的父母发送消息?(Java 语言)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17853573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 17:48:29  来源:igfitidea点击:

How to send a message to an actor's parent in Akka? (Java Language)

javaakka

提问by seinecle

newbie's question:

新手问题:

what is the method for an actor to send a message to its parent? Must be obvious but I can't find it in the docs. Using Akka 2.2

演员向其父级发送消息的方法是什么?必须很明显,但我在文档中找不到它。使用 Akka 2.2

回答by Endre Varga

You are looking for

你正在寻找

getContext().parent()

which gives you the ActorRef of the parent, so you can do

它为您提供了父级的 ActorRef,因此您可以执行

getContext().parent().tell(...)

回答by Simon

With Akka 2.4, you have to do context.parentinside an actor to have its parent actor reference. After that, you can send it a message as before (context.parent ! "hello").

在 Akka 2.4 中,您必须context.parent在 actor 内部执行以获取其父 actor 引用。之后,您可以像以前一样向其发送消息 ( context.parent ! "hello")。