His
His

Reputation: 6043

In Akka Java actor model, can a router create actors with non-default constructor?

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!

Upvotes: 2

Views: 629

Answers (1)

Björn Antonsson
Björn Antonsson

Reputation: 1019

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

Upvotes: 5

Related Questions