I have an ActorSystem where I create one top level actor and in this top level actor, I create a couple of child actors. So far good!
What I then do is to expose these child actors to my Application controller (in a Play application) so that I can directly pipe the messages intended for the corresponding child actor from my Play controller. Is this a good practice or should I always pipe the messages to the child actor via the supervisor? In code, it would look like below:
class Application extends Controller with MyActors {
def createUser = { request =>
val user: User = ... get the User from the request body
userActor ! user
}
}
Here is what my Supervisor Actor looks like and it is controlled by the Play applications lifecycle plugin:
class SupervisorActor extends Actor with ActorLogging {
val allActors = MyActors(context.system.settings.config, context)
context watch allActors.userActor
// TODO: what should we do in this SupervisorActor?
def receive = {
case Terminated(terminate) => context stop self
case _ =>
}
}
I then inject this MyActors into the Play Application controller. So my question, is this a good approach? The child actors are receiving messages directly from the outside world, without the messages having to go through the Supervisor actor. Is this a good approach. What problems could I face with this approach?