Pergunta

In sbt 0.13 project, I put the following in application.conf file located under src/main/resources

application.conf:

blocking-dispatcher {
type = PinnedDispatcher 

executor = "thread-pool-executor"
thread-pool-executor {
core-pool-size-min = 2
core-pool-size-factor = 2.0
core-pool-size-max = 10
}
throughput = 100
mailbox-capacity = -1
mailbox-type =""
}

now when I create actor I'm getting exception:

object Main extends App {

  implicit val system =  ActorSystem()

  val fileReaderActor  = system.actorOf(Props(new FileReaderActor(fileName)).withDispatcher("blocking-dispatcher"), "fileReaderActor")

}

I'm getting:

Exception in thread "main" akka.ConfigurationException: Dispatcher [blocking-dispatcher] not configured for path akka://default/user/fileReaderActor
    at akka.actor.LocalActorRefProvider.actorOf(ActorRefProvider.scala:714)
    at akka.actor.dungeon.Children$class.makeChild(Children.scala:191)
    at akka.actor.dungeon.Children$class.attachChild(Children.scala:42)
    at akka.actor.ActorCell.attachChild(ActorCell.scala:338)
    at akka.actor.ActorSystemImpl.actorOf(ActorSystem.scala:518)
    at Main$delayedInit$body.apply(Main.scala:14)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at Main$.main(Main.scala:8)
    at Main.main(Main.scala)

What am I missing?

Foi útil?

Solução

First, make sure that your config gets loaded:

System.out.println(system.settings());
// this is a shortcut for system.settings().config().root().render()

Read more about it here: http://doc.akka.io/docs/akka/2.2.3/general/configuration.html#Logging_of_Configuration

Second, the following configuration doesn't really make sense:

blocking-dispatcher {
    type = PinnedDispatcher 

    executor = "thread-pool-executor"
    thread-pool-executor {
        core-pool-size-min = 2 <----- Since you're using a PinnedDispatcher, it only uses 1 thread
        core-pool-size-factor = 2.0 <----- same here
        core-pool-size-max = 10 <----- same here
    } <--- PinnedDispatcher will automatically make it 1 thread: https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/dispatch/PinnedDispatcher.scala#L27
    throughput = 100
    mailbox-capacity = -1
    mailbox-type =""
}

Outras dicas

You have to do the lookup of the execution context dispatcher like so

implicit val executionContext = system.dispatchers.lookup("blocking-dispatcher")

and then pass this executionContext to the ActorSystem.

Quote from documentation: If an ActorSystem is created with an ExecutionContext passed in, this ExecutionContext will be used as the default executor for all dispatchers in this ActorSystem. If no ExecutionContext is given, it will fallback to the executor specified in akka.actor.default-dispatcher.default-executor.fallback[1]

[1] http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top