1

Lets say you have an actor class:

class MyActor extends Actor { }

And somewhere within MyActor, you'd like to pass it to another actor. But, you need "this" as an ActorRef. Since "this" is of type Actor, it can not be passed where ActorRef is required.

So the question is, how can an Actor ("this") get a reference to itself as an ActorRef? Is this even possible, or am I totally misunderstanding something...

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
John Anderson
  • 97
  • 1
  • 7

2 Answers2

8

From an Actor you can use self to get the ActorRef

mavarazy
  • 7,562
  • 1
  • 34
  • 60
  • 1
    You can find details on this question too: http://stackoverflow.com/questions/19887419/how-can-i-get-the-name-of-an-akka-actor-from-within-the-actor-itself – Vasile Mihali Apr 12 '17 at 06:16
1

If you know the path of an actor and you want to know its ActorRef then you can obtain it. You just have to create an actor using the actor selection and then send an Identity(none) message to that actor. It will send its ActorRefas a reply.

You find a more detailed explanation here: https://doc.akka.io/docs/akka/snapshot/actors.html

clemens
  • 16,716
  • 11
  • 50
  • 65
Prog_G
  • 1,539
  • 1
  • 8
  • 22