Reputation: 97
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
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 ActorRef
as a reply.
You find a more detailed explanation here: https://doc.akka.io/docs/akka/snapshot/actors.html
Upvotes: 1