Change RemoteActorRef to not start before it's been published. #2575

This commit is contained in:
Björn Antonsson 2012-10-15 13:33:39 +02:00
parent 4d003c50e7
commit 1d578a9aa2
3 changed files with 12 additions and 15 deletions

View file

@ -270,14 +270,10 @@ private[akka] class LocalActorRef private[akka] (
*/
private val actorCell: ActorCell = newActorCell(_system, this, _props, _supervisor)
actorCell.init(ThreadLocalRandom.current.nextInt(), sendSupervise = true)
if (actorCellShouldStart)
actorCell.start()
protected def newActorCell(system: ActorSystemImpl, ref: InternalActorRef, props: Props, supervisor: InternalActorRef): ActorCell =
new ActorCell(system, ref, props, supervisor)
protected def actorCellShouldStart(): Boolean = false
protected def actorContext: ActorContext = actorCell
/**

View file

@ -158,8 +158,7 @@ class RemoteActorRefProvider(
local.actorOf(system, props, supervisor, path, false, deployment.headOption, false, async)
} else {
val rpath = RootActorPath(addr) / "remote" / transport.address.hostPort / path.elements
useActorOnNode(rpath, props, d, supervisor)
new RemoteActorRef(this, transport, rpath, supervisor)
new RemoteActorRef(this, transport, rpath, supervisor, Some(props), Some(d))
}
case _ local.actorOf(system, props, supervisor, path, systemService, deployment.headOption, false, async)
@ -169,12 +168,12 @@ class RemoteActorRefProvider(
def actorFor(path: ActorPath): InternalActorRef =
if (path.address == rootPath.address || path.address == transport.address) actorFor(rootGuardian, path.elements)
else new RemoteActorRef(this, transport, path, Nobody)
else new RemoteActorRef(this, transport, path, Nobody, props = None, deploy = None)
def actorFor(ref: InternalActorRef, path: String): InternalActorRef = path match {
case ActorPathExtractor(address, elems)
if (address == rootPath.address || address == transport.address) actorFor(rootGuardian, elems)
else new RemoteActorRef(this, transport, new RootActorPath(address) / elems, Nobody)
else new RemoteActorRef(this, transport, new RootActorPath(address) / elems, Nobody, props = None, deploy = None)
case _ local.actorFor(ref, path)
}
@ -213,7 +212,9 @@ private[akka] class RemoteActorRef private[akka] (
val provider: RemoteActorRefProvider,
remote: RemoteTransport,
val path: ActorPath,
val getParent: InternalActorRef)
val getParent: InternalActorRef,
props: Option[Props],
deploy: Option[Deploy])
extends InternalActorRef with RemoteRef {
def getChild(name: Iterator[String]): InternalActorRef = {
@ -221,7 +222,7 @@ private[akka] class RemoteActorRef private[akka] (
s.headOption match {
case None this
case Some("..") getParent getChild name
case _ new RemoteActorRef(provider, remote, path / s, Nobody)
case _ new RemoteActorRef(provider, remote, path / s, Nobody, props = None, deploy = None)
}
}
@ -243,7 +244,7 @@ private[akka] class RemoteActorRef private[akka] (
provider.deadLetters ! message
}
def start(): Unit = ()
def start(): Unit = if (props.isDefined && deploy.isDefined) provider.useActorOnNode(path, props.get, deploy.get, getParent)
def suspend(): Unit = sendSystemMessage(Suspend())
@ -255,4 +256,4 @@ private[akka] class RemoteActorRef private[akka] (
@throws(classOf[java.io.ObjectStreamException])
private def writeReplace(): AnyRef = SerializedActorRef(path)
}
}

View file

@ -42,6 +42,9 @@ class TestActorRef[T <: Actor](
_supervisor,
_supervisor.path / name) {
// we need to start ourselves since the creation of an actor has been split into initialization and starting
underlying.start()
import TestActorRef.InternalGetActor
override def newActorCell(system: ActorSystemImpl, ref: InternalActorRef, props: Props, supervisor: InternalActorRef): ActorCell =
@ -54,9 +57,6 @@ class TestActorRef[T <: Actor](
}
}
// we need to start ourselves since the creation of an actor has been split into initialization and starting
override def actorCellShouldStart(): Boolean = true
/**
* Directly inject messages into actor receive behavior. Any exceptions
* thrown will be available to you, while still being able to use