Renamed childExists to child and return Option[ActorRef]. See #2343

This commit is contained in:
Björn Antonsson 2012-08-21 12:37:08 +02:00
parent bce95e81ef
commit 4afff48757
3 changed files with 13 additions and 3 deletions

View file

@ -418,7 +418,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
def receive = { case _ }
}), "child")
def receive = { case name: String sender ! context.childExists(name) }
def receive = { case name: String sender ! context.child(name).isDefined }
}), "parent")
assert(Await.result((parent ? "child"), remaining) === true)

View file

@ -105,7 +105,7 @@ trait ActorContext extends ActorRefFactory {
/**
* Returns true if a child with the given name exists.
*/
def childExists(name: String): Boolean
def child(name: String): Option[ActorRef]
/**
* Returns the dispatcher (MessageDispatcher) that is used for this Actor.
@ -155,6 +155,12 @@ trait UntypedActorContext extends ActorContext {
*/
def getChildren(): java.lang.Iterable[ActorRef]
/**
* Returns a reference to the named child or null if no child with
* that name exists.
*/
def getChild(name: String): ActorRef
/**
* Changes the Actor's behavior to become the new 'Procedure' handler.
* Puts the behavior on top of the hotswap stack.

View file

@ -27,7 +27,11 @@ private[akka] trait Children { this: ActorCell ⇒
final def children: Iterable[ActorRef] = childrenRefs.children
final def getChildren(): java.lang.Iterable[ActorRef] = children.asJava
final def childExists(name: String): Boolean = childrenRefs.getByName(name).isDefined
final def child(name: String): Option[ActorRef] = childrenRefs.getByName(name).flatMap({
case s: ChildRestartStats Some(s.child)
case ChildNameReserved None
})
final def getChild(name: String): ActorRef = child(name).getOrElse(null)
def actorOf(props: Props): ActorRef =
makeChild(this, props, randomName(), async = false, systemService = false)