简体   繁体   English

使用父演员参考创建Akka演员孩子

[英]create akka actor child using parent actor reference

I have a child akka actor belonging to the main application actor (parent). 我有一个属于主要应用程序演员(父母)的儿童akka演员。 Now I want to get the reference of this parent actor in this child akka actor and use that reference to create another child actor of this main parent. 现在,我想在该子akka演员中获得该父演员的引用,并使用该引用来创建此主要父对象的另一个子演员。 Now my question lies here : Is it possible to use parent actor reference in a child actor to create another child actor ? 现在我的问题就在这里:是否可以在子演员中使用父演员引用来创建另一个子演员? Any help would be highly appreciated. 任何帮助将不胜感激。 Thanks 谢谢

No, it's not possible to do what you are describing, and it wouldn't be advisable either. 不,您无法做您所描述的事情,也不建议这样做。 An actor's reference to it's parent (via context.parent ) is merely an ActorRef , so you can't use that to create another child from that parental ref as you don't have access to it's ActorContext . 演员对其父对象的引用(通过context.parent )仅是ActorRef ,因此您无法使用该对象从该父引用中创建另一个子对象,因为您无权访问它的ActorContext You could however request that your parent create a new child by sending it a custom message that the parent handles and creates a new child as a result. 但是,您可以通过向父母发送一条自定义消息来请求父母创建一个新孩子,该消息由父母处理并创建一个新孩子。 That's probably your best bet if you need one child to be able to signal to the parent that a sibling needs to be created. 如果您需要一个孩子能够向父母传达需要创建同胞的信号,那可能是最好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM