Switched the signature of Props(self => Receive) to Props(context => Receive)

This commit is contained in:
Viktor Klang 2011-09-29 12:44:52 +02:00
parent 03a5042e22
commit 8a876cc48a
4 changed files with 20 additions and 18 deletions

View file

@ -81,10 +81,10 @@ class DispatcherActorSpec extends JUnitSuite {
val latch = new CountDownLatch(100)
val start = new CountDownLatch(1)
val fastOne = actorOf(
Props(self { case "sabotage" works.set(false) }).withDispatcher(throughputDispatcher))
Props(context { case "sabotage" works.set(false) }).withDispatcher(throughputDispatcher))
val slowOne = actorOf(
Props(self {
Props(context {
case "hogexecutor" start.await
case "ping" if (works.get) latch.countDown()
}).withDispatcher(throughputDispatcher))
@ -112,14 +112,14 @@ class DispatcherActorSpec extends JUnitSuite {
val ready = new CountDownLatch(1)
val fastOne = actorOf(
Props(self {
case "ping" if (works.get) latch.countDown(); self.stop()
Props(context {
case "ping" if (works.get) latch.countDown(); context.self.stop()
}).withDispatcher(throughputDispatcher))
val slowOne = actorOf(
Props(self {
Props(context {
case "hogexecutor" ready.countDown(); start.await
case "ping" works.set(false); self.stop()
case "ping" works.set(false); context.self.stop()
}).withDispatcher(throughputDispatcher))
slowOne ! "hogexecutor"

View file

@ -358,7 +358,7 @@ object Actor {
* </pre>
*/
def spawn(body: Unit)(implicit dispatcher: MessageDispatcher = Dispatchers.defaultGlobalDispatcher) {
actorOf(Props(self { case "go" try { body } finally { self.stop() } }).withDispatcher(dispatcher)) ! "go"
actorOf(Props(context { case "go" try { body } finally { context.self.stop() } }).withDispatcher(dispatcher)) ! "go"
}
}
@ -546,15 +546,17 @@ trait Actor {
* <p/>
* Is called on a crashed Actor right BEFORE it is restarted to allow clean
* up of resources before Actor is terminated.
* By default it calls postStop()
*/
def preRestart(reason: Throwable, message: Option[Any]) {}
def preRestart(reason: Throwable, message: Option[Any]) { postStop() }
/**
* User overridable callback.
* <p/>
* Is called right AFTER restart on the newly created Actor to allow reinitialization after an Actor crash.
* By default it calls preStart()
*/
def postRestart(reason: Throwable) {}
def postRestart(reason: Throwable) { preStart() }
/**
* User overridable callback.

View file

@ -58,7 +58,7 @@ object Props {
*/
def apply(creator: Creator[_ <: Actor]): Props = default.withCreator(creator.create)
def apply(behavior: ActorRef Actor.Receive): Props = apply(new Actor { def receive = behavior(self) })
def apply(behavior: ActorContext Actor.Receive): Props = apply(new Actor { def receive = behavior(context) })
}
/**

View file

@ -175,32 +175,32 @@ class RemoteDaemon extends Actor {
def handle_fun0_unit(message: RemoteProtocol.RemoteDaemonMessageProtocol) {
new LocalActorRef(
Props(
self {
case f: Function0[_] try { f() } finally { self.stop() }
context {
case f: Function0[_] try { f() } finally { context.self.stop() }
}).copy(dispatcher = computeGridDispatcher), newUuid.toString, systemService = true) ! payloadFor(message, classOf[Function0[Unit]])
}
def handle_fun0_any(message: RemoteProtocol.RemoteDaemonMessageProtocol) {
new LocalActorRef(
Props(
self {
case f: Function0[_] try { reply(f()) } finally { self.stop() }
context {
case f: Function0[_] try { reply(f()) } finally { context.self.stop() }
}).copy(dispatcher = computeGridDispatcher), newUuid.toString, systemService = true) forward payloadFor(message, classOf[Function0[Any]])
}
def handle_fun1_arg_unit(message: RemoteProtocol.RemoteDaemonMessageProtocol) {
new LocalActorRef(
Props(
self {
case (fun: Function[_, _], param: Any) try { fun.asInstanceOf[Any Unit].apply(param) } finally { self.stop() }
context {
case (fun: Function[_, _], param: Any) try { fun.asInstanceOf[Any Unit].apply(param) } finally { context.self.stop() }
}).copy(dispatcher = computeGridDispatcher), newUuid.toString, systemService = true) ! payloadFor(message, classOf[Tuple2[Function1[Any, Unit], Any]])
}
def handle_fun1_arg_any(message: RemoteProtocol.RemoteDaemonMessageProtocol) {
new LocalActorRef(
Props(
self {
case (fun: Function[_, _], param: Any) try { reply(fun.asInstanceOf[Any Any](param)) } finally { self.stop() }
context {
case (fun: Function[_, _], param: Any) try { reply(fun.asInstanceOf[Any Any](param)) } finally { context.self.stop() }
}).copy(dispatcher = computeGridDispatcher), newUuid.toString, systemService = true) forward payloadFor(message, classOf[Tuple2[Function1[Any, Any], Any]])
}