John Anderson
John Anderson

Reputation: 97

How to get an ActorRef from "this"

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...

Upvotes: 1

Views: 1009

Answers (2)

Prog_G
Prog_G

Reputation: 1615

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

Upvotes: 1

mavarazy
mavarazy

Reputation: 7735

From an Actor you can use self to get the ActorRef

Upvotes: 8

Related Questions