Reputation: 1087
I'm working with Akka and we are still getting to get to know each other.
My scenario is : I have chosen a non-default dispatcher for a supervisor (parent) actor who's role is to manage (supervise) and create child actors to do the work.
Question : Does the child actors inherit the parent's actor?
I am aware that you can explicitly specify a different dispatcher for child actors from parent actors given specifying in the configuration.
akka.actor.deployment {
/my-parent-actor {
dispatcher = dispatcher-for-parent
}
"/my-parent-actor/*" {
dispatcher = dispatcher-for-children
}
}
My question is about if you specify the parent actor dispatcher, without explicitly specifying a dispatcher for the children actors, is there inheritance to the children of the parent's actor.
Upvotes: 11
Views: 1044
Reputation: 35463
From what I've seen, the child will not inherit the supervisor of the parent by default. I couldn't find this explicitly in the docs anywhere, so I wrote a quick piece of code to verify my initial assumption:
import com.typesafe.config.ConfigFactory
import akka.actor._
object DispatcherTest extends App{
val conf = ConfigFactory.parseString("""
{
my-custom-dispatcher {
executor = "thread-pool-executor"
type = PinnedDispatcher
}
}
""")
val system = ActorSystem("test", conf)
val supervisor = system.actorOf(Props[MySupervisor].withDispatcher("my-custom-dispatcher"))
}
class MySupervisor extends Actor{
println(s"I am the supervisor, my dispatcher is: ${context.dispatcher}")
val child = context.actorOf(Props[MyChild])
def receive = {
case _ =>
}
}
class MyChild extends Actor{
println(s"I am the child, my dispatcher is: ${context.dispatcher}")
def receive = {
case _ =>
}
}
If you run this, you will see:
I am the supervisor, my dispatcher is: PinnedDispatcher[my-custom-dispatcher]
I am the child, my dispatcher is: Dispatcher[akka.actor.default-dispatcher]
Upvotes: 18