Discovering an actor

Actor discovery is an alternative way to obtain an actor reference. The preferred way is still to incorporate actor references into the message protocol.

Akka provides the possibility to look up a single child actor by name (only exact match) with the following method:

def child(name: String): Option[ActorRef[Nothing]]

This returns a reference to a child actor if a child with such a name exists and is alive. Please note that because of the return type of this method, the result needs to be coerced to the proper type by the use of the narrow method of ActorRef

Another method that allows us to look up all of the children of an actor that are alive is as follows:

def children: Iterable[ActorRef[Nothing]]

The type of result ...

Get Learn Scala Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.