在Akka Java actor模型中,路由器可以使用非默认构造函数创建actor吗?

编程入门 行业动态 更新时间:2024-10-24 13:26:28
本文介绍了在Akka Java actor模型中,路由器可以使用非默认构造函数创建actor吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Akka Java actor模型中,如果我有RoundRobinRouter,则在调用其 tell()方法时,我希望路由器(作为主机)创建子actor使用非默认构造函数,因为我需要传递一些参数。我该怎么做?

In Akka Java actor model, if I have a RoundRobinRouter, when its tell() method is called, I want the router (as the master) to create children actors with non-default constructor because I need to pass in some parameters. How can I do this?

我知道我可以使用 Props 使用具有非默认构造函数的演员,但是

I understand that I can an actor with non-default constructor using Props, but how is it used when the master actor is a router?

谢谢!

推荐答案

构造路由器的道具是该路由器路由的道具,而不是路由器本身。

The props in the construction of a Router is the props for the routees of that router, not the router itself.

您可以简单地执行以下操作:

You could simply do something like:

system.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return new MyActor("foo", "bar"); } }).withRouter(...))

所有路由都将是MyActor类型,并带有特定的构造函数。

And all the routees will be of type MyActor with the specific constructor called.

您可以使用通常的Props做任何事情能够。有关更多信息,请参见 Akka文档

You can do anything with the Props that you normally can. For more information see The Akka Docs

更多推荐

在Akka Java actor模型中,路由器可以使用非默认构造函数创建actor吗?

本文发布于:2023-11-25 12:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629660.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   路由器   函数   模型   Akka

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!