Added utility method and another test

This commit is contained in:
Viktor Klang 2010-08-13 14:02:08 +02:00
parent 51d89c6d92
commit d9fe236b2e
2 changed files with 12 additions and 1 deletions

View file

@ -1,5 +1,5 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
package se.scalablesolutions.akka.dispatch
@ -112,6 +112,13 @@ object Dispatchers extends Logging {
*/
def newThreadBasedDispatcher(actor: ActorRef) = new ThreadBasedDispatcher(actor)
/**
* Utility function that tries to load the specified dispatcher config from the akka.conf
* or else use the supplied default dispatcher
*/
def fromConfig(key: String, default: => MessageDispatcher = defaultGlobalDispatcher): MessageDispatcher =
config.getConfigMap(key).flatMap(from).getOrElse(default)
/*
* Creates of obtains a dispatcher from a ConfigMap according to the format below
*

View file

@ -67,4 +67,8 @@ class DispatchersSpec extends JUnitSuite {
assert(typesAndValidators.forall( tuple => tuple._2(allDispatchers(tuple._1).get) ))
}
@Test def defaultingToDefaultWhileLoadingTheDefaultShouldWork {
assert(from(Config.fromMap(Map(tipe -> "Default"))).getOrElse(defaultGlobalDispatcher) == defaultGlobalDispatcher)
}
}