Create Actors from Controllers using factories

58 views
Skip to first unread message

Gabriel Giussi

unread,
Nov 9, 2017, 8:44:07 AM11/9/17
to Play framework dev
Hi everyone, I'm wondering why the InjectedActorSupport only supports an ActorContext to create child actors and not also an ActorSystem, because this is limiting us to create actors directly from controllers.
If there are no reasons or recommendations against this (creating actors directly from controllers), I can make a PR adding a new method to InjectedActorSupport if you think it helps.

Cheers.

James Roper

unread,
Nov 9, 2017, 7:58:19 PM11/9/17
to Gabriel Giussi, Play framework dev
Hi Gabriel,

The reason for this is that it's generally not good practice to create many actors directly from outside the actor system, because you can't supervise them - that is, you can't say what should happen when they crash (should they be stopped, restarted, escalated etc?). In all the scenarios where I've wanted to create an actor from a controller, it's always ended up being a better design for me to not do that, rather, to send a message to another manager actor to create the child actor. When you do this, it gives you a lot more flexibility in future, for example, lets say in future you have a requirement that when a user resubmits the same operation, it shouldn't start a new actor but should connect to the existing actor. If you have a manager actor, that's very easy to do, you can atomically check if the manager actor has a child for that operation already, and create a new child if necessary. If not, it's not possible. And then in future you move to a multi node setup, and you might decide to shard your actors across a cluster - again, very easy if you were using a manager actor because all you need to do is replace the manager actor with cluster sharding, or put a clustered consistent hashing router in front of your manager, but if creating actors directly from the controller, not possible.

Regards,

James

--
You received this message because you are subscribed to the Google Groups "Play framework dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework-dev+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Gabriel Giussi

unread,
Nov 10, 2017, 5:59:04 AM11/10/17
to Play framework dev
Thanks James, it's much clearer now.
Reply all
Reply to author
Forward
0 new messages