What is the reason that actor with router will not consider 
dispatcher/mailbox configuration from config file? We had to manually 
specify withDispatcher()/withMailbox in code for actors with router. is 
there any work around to pick the same from configuration. Is it ok to over 
ride the default dispatcher for actors with router?


  def actorOf(system: ActorSystemImpl, props: Props, supervisor: 
InternalActorRef, path: ActorPath,
              systemService: Boolean, deploy: Option[Deploy], lookupDeploy: 
Boolean, async: Boolean): InternalActorRef = {
    props.deploy.routerConfig match {
      *case NoRouter* ⇒
        if (settings.DebugRouterMisconfiguration) {
          deployer.lookup(path) foreach { d ⇒
            if (d.routerConfig != NoRouter)
              log.warning("Configuration says that [{}] should be a router, 
but code disagrees. Remove the config or add a routerConfig to its Props.", 
path)
          }
        }

        val props2 =
          // mailbox and dispatcher defined in deploy should override props
          (if (lookupDeploy) deployer.lookup(path) else deploy) match {
            case Some(d) ⇒
              (d.dispatcher, d.mailbox) match {
                case (Deploy.NoDispatcherGiven, Deploy.NoMailboxGiven) ⇒ 
props
                case (dsp, Deploy.NoMailboxGiven)                      ⇒ 
props.withDispatcher(dsp)
                case (Deploy.NoMailboxGiven, mbx)                      ⇒ 
props.withMailbox(mbx)
                *case (dsp, mbx)                                        ⇒ 
props.withDispatcher(dsp).withMailbox(mbx)*
              }
            case _ ⇒ props // no deployment config found
          }

        if (!system.dispatchers.hasDispatcher(props2.dispatcher))
          throw new ConfigurationException(s"Dispatcher 
[${props2.dispatcher}] not configured for path $path")

        try {
          val dispatcher = system.dispatchers.lookup(props2.dispatcher)
          val mailboxType = system.mailboxes.getMailboxType(props2, 
dispatcher.configurator.config)

          if (async) new RepointableActorRef(system, props2, dispatcher, 
mailboxType, supervisor, path).initialize(async)
          else new LocalActorRef(system, props2, dispatcher, mailboxType, 
supervisor, path)
        } catch {
          case NonFatal(e) ⇒ throw new ConfigurationException(
            s"configuration problem while creating [$path] with dispatcher 
[${props2.dispatcher}] and mailbox [${props2.mailbox}]", e)
        }

     * case router *⇒
        val lookup = if (lookupDeploy) deployer.lookup(path) else None
        val r = router :: deploy.map(_.routerConfig).toList ::: 
lookup.map(_.routerConfig).toList reduce ((a, b) ⇒ b withFallback a)
        val p = props.withRouter(r)

        if (!system.dispatchers.hasDispatcher(p.dispatcher))
          throw new ConfigurationException(s"Dispatcher [${p.dispatcher}] 
not configured for routees of $path")
        if (!system.dispatchers.hasDispatcher(r.routerDispatcher))
          throw new ConfigurationException(s"Dispatcher [${p.dispatcher}] 
not configured for router of $path")

        val routerProps = Props(
          p.deploy.copy(dispatcher = p.routerConfig.routerDispatcher),
          classOf[RoutedActorCell.RouterActorCreator], 
Vector(p.routerConfig))
        val routeeProps = p.withRouter(NoRouter)

        try {
          val routerDispatcher = 
system.dispatchers.lookup(p.routerConfig.routerDispatcher)
          val routerMailbox = system.mailboxes.getMailboxType(routerProps, 
routerDispatcher.configurator.config)

          // routers use context.actorOf() to create the routees, which 
does not allow us to pass
          // these through, but obtain them here for early verification
          val routeeDispatcher = system.dispatchers.lookup(p.dispatcher)
          system.mailboxes.getMailboxType(routeeProps, 
routeeDispatcher.configurator.config)

          new RoutedActorRef(system, routerProps, routerDispatcher, 
routerMailbox, routeeProps, supervisor, path).initialize(async)
        } catch {
          case NonFatal(e) ⇒ throw new ConfigurationException(
            s"configuration problem while creating [$path] with router 
dispatcher [${routerProps.dispatcher}] and mailbox [${routerProps.mailbox}] 
" +
              s"and routee dispatcher [${routeeProps.dispatcher}] and 
mailbox [${routeeProps.mailbox}]", e)
        }
    }
  }

-- 
*****************************************************************************************************
** New discussion forum: https://discuss.akka.io/ replacing akka-user 
google-group soon.
** This group will soon be put into read-only mode, and replaced by 
discuss.akka.io
** More details: https://akka.io/blog/news/2018/03/13/discuss.akka.io-announced
*****************************************************************************************************
>>>>>>>>>> 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/akka-user/47f8dbf5-1e88-4866-adb1-1f042cd8a2cb%40googlegroups.com.

Reply via email to