Switching from DynamicVariable to ThreadLocal to avoid child threads inheriting the current value
This commit is contained in:
parent
d69baf74ae
commit
d89c286fb2
2 changed files with 7 additions and 5 deletions
|
|
@ -125,7 +125,9 @@ object Actor extends ListenerManagement {
|
|||
*/
|
||||
type Receive = PartialFunction[Any, Unit]
|
||||
|
||||
private[actor] val actorRefInCreation = new scala.util.DynamicVariable[Option[ActorRef]](None)
|
||||
private[actor] val actorRefInCreation = new ThreadLocal[Option[ActorRef]]{
|
||||
override def initialValue = None
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ActorRef out of the Actor with type T.
|
||||
|
|
@ -290,7 +292,7 @@ trait Actor {
|
|||
* the 'forward' function.
|
||||
*/
|
||||
@transient implicit val someSelf: Some[ActorRef] = {
|
||||
val optRef = Actor.actorRefInCreation.value
|
||||
val optRef = Actor.actorRefInCreation.get
|
||||
if (optRef.isEmpty) throw new ActorInitializationException(
|
||||
"ActorRef for instance of actor [" + getClass.getName + "] is not in scope." +
|
||||
"\n\tYou can not create an instance of an actor explicitly using 'new MyActor'." +
|
||||
|
|
@ -298,7 +300,7 @@ trait Actor {
|
|||
"\n\tEither use:" +
|
||||
"\n\t\t'val actor = Actor.actorOf[MyActor]', or" +
|
||||
"\n\t\t'val actor = Actor.actorOf(new MyActor(..))'")
|
||||
Actor.actorRefInCreation.value = None
|
||||
Actor.actorRefInCreation.set(None)
|
||||
optRef.asInstanceOf[Some[ActorRef]].get.id = getClass.getName //FIXME: Is this needed?
|
||||
optRef.asInstanceOf[Some[ActorRef]]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1015,12 +1015,12 @@ class LocalActorRef private[akka] (
|
|||
|
||||
private[this] def newActor: Actor = {
|
||||
try {
|
||||
Actor.actorRefInCreation.value = Some(this)
|
||||
Actor.actorRefInCreation.set(Some(this))
|
||||
val a = actorFactory()
|
||||
if (a eq null) throw new ActorInitializationException("Actor instance passed to ActorRef can not be 'null'")
|
||||
a
|
||||
} finally {
|
||||
Actor.actorRefInCreation.value = None
|
||||
Actor.actorRefInCreation.set(None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue