In Akka Java actor model, can a router create acto

2019-07-17 00:34发布

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?

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?

Thanks!

1条回答
一夜七次
2楼-- · 2019-07-17 01:21

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(...))

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

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

查看更多
登录 后发表回答