2014-02-10 91 views
2

在SBT 0.13的項目,我把下面的位於下application.conf文件src/main/resourcesakka.io調度配置異常

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 ="" 
} 

現在當我創建演員我得到異常:

object Main extends App { 

    implicit val system = ActorSystem() 

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

} 

我越來越:

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) 

我錯過了什麼?

+1

您可能只是忘記了將資源目錄包含在IDE的構建路徑中。 –

回答

2

首先,確保你的配置被加載:

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

瞭解更多關於在這裏:​​http://doc.akka.io/docs/akka/2.2.3/general/configuration.html#Logging_of_Configuration

其次,以下配置沒有意義:

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 ="" 
} 
-1

你要做的執行上下文調度程序的查找,像這樣

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

,然後通過這個ExecutionContext中的ActorSystem。從文檔

報價: 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

+0

謝謝你的評論,但我還沒有用ExecutionContext創建我的ActorSystem。第二個問題executionContext是隱式變量,我應該如何傳遞它? –