Fixing akka-rest breakage from Configurator.getInstance

This commit is contained in:
Viktor Klang 2010-03-20 12:41:35 +01:00
parent 7f7a0485b2
commit aef25b7517

View file

@ -9,19 +9,21 @@ import com.sun.jersey.core.spi.component.ioc.IoCFullyManagedComponentProvider
import se.scalablesolutions.akka.config.Configurator
import se.scalablesolutions.akka.util.Logging
import se.scalablesolutions.akka.actor.Actor
class ActorComponentProvider(val clazz: Class[_], val configurators: List[Configurator])
extends IoCFullyManagedComponentProvider with Logging {
override def getScope = ComponentScope.Singleton
override def getInstance: AnyRef = {
override def getInstance: Actor = {
val instances = for {
conf <- configurators
if conf.isDefined(clazz)
} yield conf.getInstance(clazz).asInstanceOf[AnyRef]
instance <- conf.getInstance(clazz)
} yield instance
instances match {
case instance :: Nil => instance
case (instance : Actor) :: Nil => instance
case Nil => throw new IllegalArgumentException("No Actor for class [" + clazz + "] could be found. Make sure you have defined and configured the class as an Active Object or Actor in a Configurator")
case _ => throw new IllegalArgumentException("Actor for class [" + clazz + "] is defined in more than one Configurator. Eliminate the redundancy.")
}