+act #3579 Direct ActorSelection for missing actor to deadLetters

This commit is contained in:
Patrik Nordwall 2013-11-06 14:27:16 +01:00
parent 8fb59a0bc6
commit 47216bd956
3 changed files with 37 additions and 4 deletions

View file

@ -328,6 +328,34 @@ class ActorSelectionSpec extends AkkaSpec("akka.loglevel=DEBUG") with DefaultTim
ActorSelection(c21, "../*/hello").toString must be(s"ActorSelection[Actor[akka://ActorSelectionSpec/user/c2/c21#${c21.path.uid}]/../*/hello]")
}
"send ActorSelection targeted to missing actor to deadLetters" in {
val p = TestProbe()
system.eventStream.subscribe(p.ref, classOf[DeadLetter])
system.actorSelection("/user/missing").tell("boom", testActor)
val d = p.expectMsgType[DeadLetter]
d.message must be("boom")
d.sender must be(testActor)
d.recipient.path.elements.mkString("/", "/", "") must be("/user/missing")
}
"send ActorSelection wildcard targeted to missing actor to deadLetters" in {
val top = system.actorOf(p, "top")
top ! Create("child1")
top ! Create("child2")
val probe = TestProbe()
system.eventStream.subscribe(probe.ref, classOf[DeadLetter])
system.actorSelection("/user/top/*/a").tell("wild", testActor)
// wildcard matches both child1 and child2
val d1 = probe.expectMsgType[DeadLetter]
val d2 = probe.expectMsgType[DeadLetter]
List(d1, d2) foreach { d
d.message must be("wild")
d.sender must be(testActor)
d.recipient.path.elements.mkString("/", "/", "") must (equal("/user/top/child1/a") or equal("/user/top/child2/a"))
}
}
}
}

View file

@ -147,9 +147,11 @@ object ActorSelection {
rec(parent)
case SelectChildName(name)
val child = refWithCell.getSingleChild(name)
if (child == Nobody)
sel.identifyRequest foreach { x sender ! ActorIdentity(x.messageId, None) }
else if (iter.isEmpty)
if (child == Nobody) {
val emptyRef = new EmptyLocalActorRef(refWithCell.provider, anchor.path / sel.elements.map(_.toString),
refWithCell.underlying.system.eventStream)
emptyRef.tell(sel, sender)
} else if (iter.isEmpty)
child.tell(sel.msg, sender)
else
rec(child)

View file

@ -19,6 +19,7 @@ import akka.actor.SelectChildName
import akka.actor.SelectChildPattern
import akka.actor.Identify
import akka.actor.ActorIdentity
import akka.actor.EmptyLocalActorRef
/**
* INTERNAL API
@ -141,7 +142,9 @@ private[akka] class RemoteSystemDaemon(
}
getChild(concatenatedChildNames.iterator) match {
case Nobody
sel.identifyRequest foreach { x sender ! ActorIdentity(x.messageId, None) }
val emptyRef = new EmptyLocalActorRef(system.provider, path / sel.elements.map(_.toString),
system.eventStream)
emptyRef.tell(sel, sender)
case child
child.tell(m, sender)
}