Search code examples
akkaactor

Obtaining AKKA actor name from ActorRef


Is there a way to get the actor name from an ActorRef in AKKA?

I am referring to the name one would give an actor with:

val myActorRef = context.actorOf(props, "MyActorName")

Solution

  • The name is accessible from the path:

    val name = myActorRef.path.name
    

    Similarly, the name is also in the path elements:

    val nameAgain = myActorRef.path.elements.last