Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a message to an actor's parent in Akka Classic?

Tags:

java

akka

What is the method for an actor to send a message to its parent?

I'm using Akka 2.2

like image 410
seinecle Avatar asked Jul 25 '13 09:07

seinecle


People also ask

Can Akka actors stop other actors?

In Akka, you can stop Actors by invoking the stop() method of either ActorContext or ActorSystem class. ActorContext is used to stop child actor and ActorSystem is used to stop top level Actor.

What is ActorSystem in Akka?

Companion object ActorSystem An actor system is a hierarchical group of actors which share common configuration, e.g. dispatchers, deployments, remote capabilities and addresses. It is also the entry point for creating or looking up actors. There are several possibilities for creating actors (see akka.


2 Answers

You are looking for

getContext().parent() 

which gives you the ActorRef of the parent, so you can do

getContext().parent().tell(...) 
like image 89
Endre Varga Avatar answered Sep 20 '22 11:09

Endre Varga


With Akka 2.4, you have to do context.parent inside an actor to have its parent actor reference. After that, you can send it a message as before (context.parent ! "hello").

like image 41
Simon Avatar answered Sep 18 '22 11:09

Simon