dinesh707
dinesh707

Reputation: 12582

How to listen to messages which are sent to ActorSystem (Akka 2.0)

I have a code, where I create an Actor from AkkaSystem.

return system.actorOf(Props.apply(new Creator<Actor>()
....

Inside the child actor I call

context().parent().tell(new DeathByError());
context().stop(self());

is there a way to know from the parent (ActorSystem object) to know that child sent DeathByError message ?

Upvotes: 0

Views: 269

Answers (2)

Diego Martinoia
Diego Martinoia

Reputation: 4652

If you meant "what" child sent the message, Micheal Rose's answer is correct.

If you simply want to receive it, add a handler for it in the parents receive method.

Note that if you "watch" an actor from another actor, the latter is notified when the former dies, without need for you to explicitly sending a message ( http://doc.akka.io/docs/akka/current/scala/actors.html#Actor_Lifecycle )

Upvotes: 0

Michael Rose
Michael Rose

Reputation: 7820

When you are handling the message you can call getSender() which should return the ActorRef of the one who sent the message.

Upvotes: 1

Related Questions