Initial draft of UntypedActor for Java API

This commit is contained in:
Jonas Bonér 2010-07-28 13:08:24 +02:00
parent ed2d9d67ff
commit d6b728d298
4 changed files with 55 additions and 12 deletions

View file

@ -436,12 +436,12 @@ trait Actor extends Logging {
}
private val lifeCycles: Receive = {
case HotSwap(code) => become(code)
case Exit(dead, reason) => self.handleTrapExit(dead, reason)
case Link(child) => self.link(child)
case Unlink(child) => self.unlink(child)
case HotSwap(code) => become(code)
case Exit(dead, reason) => self.handleTrapExit(dead, reason)
case Link(child) => self.link(child)
case Unlink(child) => self.unlink(child)
case UnlinkAndStop(child) => self.unlink(child); child.stop
case Restart(reason) => throw reason
case Restart(reason) => throw reason
}
}

View file

@ -714,7 +714,7 @@ private[akka] sealed class TypedActorAspect {
object Dispatcher {
val ZERO_ITEM_CLASS_ARRAY = Array[Class[_]]()
val ZERO_ITEM_OBJECT_ARRAY = Array[Object]()
var crashedActorTl:ThreadLocal[Dispatcher] = new ThreadLocal();
// var crashedActorTl: ThreadLocal[Dispatcher] = new ThreadLocal();
}
/**
@ -771,7 +771,7 @@ private[akka] class Dispatcher(transactionalRequired: Boolean) extends Actor {
}
override def preRestart(reason: Throwable) {
crashedActorTl.set(this)
// crashedActorTl.set(this)
targetInstance.preRestart(reason)
// rewrite target instance in Dispatcher and AspectWerkz Proxy
@ -786,11 +786,11 @@ private[akka] class Dispatcher(transactionalRequired: Boolean) extends Actor {
override def init {
// Get the crashed dispatcher from thread local and intitialize this actor with the
// contents of the old dispatcher
val oldActor = crashedActorTl.get
if (oldActor != null) {
initialize(oldActor.targetClass, oldActor.targetInstance, oldActor.proxy, oldActor.context)
crashedActorTl.set(null)
}
// val oldActor = crashedActorTl.get
// if (oldActor != null) {
// initialize(oldActor.targetClass, oldActor.targetInstance, oldActor.proxy, oldActor.context)
// crashedActorTl.set(null)
// }
}
override def shutdown {

View file

@ -0,0 +1,34 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
package se.scalablesolutions.akka.actor
/**
* FIXME: document
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
abstract class UntypedActor extends Actor {
protected[akka] var context: Option[ActorContext] = None
protected def receive = {
case msg =>
if (context.isEmpty) {
val ctx = new ActorContext(self)
context = Some(ctx)
onReceive(msg, ctx)
} else onReceive(msg, context.get)
}
def onReceive(message: Any, context: ActorContext): Unit
}
/**
* FIXME: document
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
class ActorContext(self: ActorRef) {
}

View file

@ -0,0 +1,9 @@
package se.scalablesolutions.akka.actor;
import se.scalablesolutions.akka.actor.*;
public class TestUntypedActor extends UntypedActor {
public void onReceive(Object message, ActorContext context) {
System.out.println("TestUntypedActor got " + message);
}
}