From d9fe236b2e6d562e4ef81fea8e49186231a793b7 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Fri, 13 Aug 2010 14:02:08 +0200 Subject: [PATCH] Added utility method and another test --- akka-core/src/main/scala/dispatch/Dispatchers.scala | 9 ++++++++- akka-core/src/test/scala/dispatch/DispatchersSpec.scala | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/akka-core/src/main/scala/dispatch/Dispatchers.scala b/akka-core/src/main/scala/dispatch/Dispatchers.scala index 79861086fc..58a67fdbd8 100644 --- a/akka-core/src/main/scala/dispatch/Dispatchers.scala +++ b/akka-core/src/main/scala/dispatch/Dispatchers.scala @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009-2010 Scalable Solutions AB + * Copyright (C) 2009-2010 Scalable Solutions AB */ 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 * diff --git a/akka-core/src/test/scala/dispatch/DispatchersSpec.scala b/akka-core/src/test/scala/dispatch/DispatchersSpec.scala index a0eb9c6889..0c6837f764 100644 --- a/akka-core/src/test/scala/dispatch/DispatchersSpec.scala +++ b/akka-core/src/test/scala/dispatch/DispatchersSpec.scala @@ -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) + } + }