2011-09-15 08:12:07 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.actor
|
|
|
|
|
|
|
|
|
|
import akka.dispatch._
|
|
|
|
|
import akka.japi.Creator
|
|
|
|
|
import akka.util._
|
2011-10-18 11:26:35 +02:00
|
|
|
import collection.immutable.Stack
|
2011-09-15 08:12:07 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ActorRef configuration object, this is threadsafe and fully sharable
|
|
|
|
|
*
|
|
|
|
|
* Props() returns default configuration
|
|
|
|
|
* FIXME document me
|
|
|
|
|
*/
|
|
|
|
|
object Props {
|
2011-10-15 11:18:25 +02:00
|
|
|
import FaultHandlingStrategy._
|
|
|
|
|
|
2011-09-15 08:12:07 +02:00
|
|
|
final val defaultCreator: () ⇒ Actor = () ⇒ throw new UnsupportedOperationException("No actor creator specified!")
|
2011-10-06 21:19:46 +02:00
|
|
|
final val defaultDispatcher: MessageDispatcher = null
|
|
|
|
|
final val defaultTimeout: Timeout = Timeout(Duration.MinusInf)
|
2011-10-15 11:18:25 +02:00
|
|
|
final val defaultDecider: Decider = {
|
|
|
|
|
case _: ActorInitializationException ⇒ Stop
|
2011-10-20 23:37:54 +02:00
|
|
|
case _: ActorKilledException ⇒ Stop
|
2011-10-15 11:18:25 +02:00
|
|
|
case _: Exception ⇒ Restart
|
|
|
|
|
case _ ⇒ Escalate
|
|
|
|
|
}
|
|
|
|
|
final val defaultFaultHandler: FaultHandlingStrategy = OneForOneStrategy(defaultDecider, None, None)
|
2011-11-08 12:30:46 +01:00
|
|
|
|
2011-10-18 11:26:35 +02:00
|
|
|
final val noHotSwap: Stack[Actor.Receive] = Stack.empty
|
2011-09-15 08:12:07 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The default Props instance, uses the settings from the Props object starting with default*
|
|
|
|
|
*/
|
|
|
|
|
final val default = new Props()
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a cached default implementation of Props
|
|
|
|
|
*/
|
|
|
|
|
def apply(): Props = default
|
|
|
|
|
|
2011-10-21 15:11:43 +02:00
|
|
|
val empty = Props(new Actor { def receive = Actor.emptyBehavior })
|
2011-10-15 11:18:25 +02:00
|
|
|
|
2011-09-15 08:12:07 +02:00
|
|
|
/**
|
|
|
|
|
* Returns a Props that has default values except for "creator" which will be a function that creates an instance
|
|
|
|
|
* of the supplied type using the default constructor
|
|
|
|
|
*/
|
|
|
|
|
def apply[T <: Actor: ClassManifest]: Props =
|
|
|
|
|
default.withCreator(implicitly[ClassManifest[T]].erasure.asInstanceOf[Class[_ <: Actor]].newInstance)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a Props that has default values except for "creator" which will be a function that creates an instance
|
|
|
|
|
* of the supplied class using the default constructor
|
|
|
|
|
*/
|
|
|
|
|
def apply(actorClass: Class[_ <: Actor]): Props =
|
|
|
|
|
default.withCreator(actorClass.newInstance)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a Props that has default values except for "creator" which will be a function that creates an instance
|
|
|
|
|
* using the supplied thunk
|
|
|
|
|
*/
|
|
|
|
|
def apply(creator: ⇒ Actor): Props = default.withCreator(creator)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a Props that has default values except for "creator" which will be a function that creates an instance
|
|
|
|
|
* using the supplied thunk
|
|
|
|
|
*/
|
|
|
|
|
def apply(creator: Creator[_ <: Actor]): Props = default.withCreator(creator.create)
|
|
|
|
|
|
2011-09-29 12:44:52 +02:00
|
|
|
def apply(behavior: ActorContext ⇒ Actor.Receive): Props = apply(new Actor { def receive = behavior(context) })
|
2011-10-11 16:05:48 +02:00
|
|
|
|
|
|
|
|
def apply(faultHandler: FaultHandlingStrategy): Props = apply(new Actor { def receive = { case _ ⇒ } }).withFaultHandler(faultHandler)
|
2011-09-15 08:12:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ActorRef configuration object, this is thread safe and fully sharable
|
|
|
|
|
*/
|
|
|
|
|
case class Props(creator: () ⇒ Actor = Props.defaultCreator,
|
|
|
|
|
@transient dispatcher: MessageDispatcher = Props.defaultDispatcher,
|
|
|
|
|
timeout: Timeout = Props.defaultTimeout,
|
2011-10-18 15:39:26 +02:00
|
|
|
faultHandler: FaultHandlingStrategy = Props.defaultFaultHandler) {
|
2011-12-13 14:09:40 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API
|
|
|
|
|
*/
|
|
|
|
|
def this(factory: UntypedActorFactory) = this(
|
|
|
|
|
creator = () ⇒ factory.create(),
|
|
|
|
|
dispatcher = Props.defaultDispatcher,
|
|
|
|
|
timeout = Props.defaultTimeout,
|
|
|
|
|
faultHandler = Props.defaultFaultHandler)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API
|
|
|
|
|
*/
|
|
|
|
|
def this(actorClass: Class[_ <: Actor]) = this(
|
|
|
|
|
creator = () ⇒ actorClass.newInstance,
|
|
|
|
|
dispatcher = Props.defaultDispatcher,
|
|
|
|
|
timeout = Props.defaultTimeout,
|
|
|
|
|
faultHandler = Props.defaultFaultHandler)
|
|
|
|
|
|
2011-09-15 08:12:07 +02:00
|
|
|
/**
|
|
|
|
|
* No-args constructor that sets all the default values
|
|
|
|
|
* Java API
|
|
|
|
|
*/
|
|
|
|
|
def this() = this(
|
|
|
|
|
creator = Props.defaultCreator,
|
|
|
|
|
dispatcher = Props.defaultDispatcher,
|
|
|
|
|
timeout = Props.defaultTimeout,
|
2011-10-18 15:39:26 +02:00
|
|
|
faultHandler = Props.defaultFaultHandler)
|
2011-09-15 08:12:07 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a new Props with the specified creator set
|
|
|
|
|
* Scala API
|
|
|
|
|
*/
|
|
|
|
|
def withCreator(c: ⇒ Actor) = copy(creator = () ⇒ c)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a new Props with the specified creator set
|
|
|
|
|
* Java API
|
|
|
|
|
*/
|
|
|
|
|
def withCreator(c: Creator[Actor]) = copy(creator = () ⇒ c.create)
|
|
|
|
|
|
2011-10-07 15:22:36 +02:00
|
|
|
/**
|
|
|
|
|
* Returns a new Props with the specified creator set
|
|
|
|
|
* Java API
|
|
|
|
|
*/
|
|
|
|
|
def withCreator(c: Class[_ <: Actor]) = copy(creator = () ⇒ c.newInstance)
|
|
|
|
|
|
2011-09-15 08:12:07 +02:00
|
|
|
/**
|
|
|
|
|
* Returns a new Props with the specified dispatcher set
|
|
|
|
|
* Java API
|
|
|
|
|
*/
|
|
|
|
|
def withDispatcher(d: MessageDispatcher) = copy(dispatcher = d)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a new Props with the specified timeout set
|
|
|
|
|
* Java API
|
|
|
|
|
*/
|
|
|
|
|
def withTimeout(t: Timeout) = copy(timeout = t)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a new Props with the specified faulthandler set
|
|
|
|
|
* Java API
|
|
|
|
|
*/
|
|
|
|
|
def withFaultHandler(f: FaultHandlingStrategy) = copy(faultHandler = f)
|
|
|
|
|
|
|
|
|
|
}
|