Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Akka, what happens if I watch() a dead ActorRef?

Tags:

akka

watch

If I call context.watch() on an ActorRef that is already dead, am I guaranteed to still receive a termination message?

Also, after having received a termination message regarding a specific actor, do I still need to call unwatch()?

Also, are watch() calls reference counted? If I call watch() twice, followed by unwatch() once, am I guaranteed to still get termination messages?

like image 517
SoftMemes Avatar asked Jun 01 '12 10:06

SoftMemes


People also ask

What happens when an actor fails in Akka?

You are viewing the documentation for the new actor APIs, to view the Akka Classic documentation, see Classic Fault Tolerance. When an actor throws an unexpected exception, a failure, while processing a message or during initialization, the actor will by default be stopped.

Can an Akka actor stop itself?

An actor can stop itself by returning. Behaviors. stopped as the next behavior. A child actor can be forced to stop after it finishes processing its current message by using the stop method of the ActorContext from the parent actor.

Can an Akka actor 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. The actual termination of the actor is performed asynchronously.

What happens to an Actors reference when an actor is restarted as a result of a crash?

Note that a restart of an actor caused by a failure still means that it is the same actor incarnation, i.e. a restart is not visible for the consumer of the ActorRef.


1 Answers

I think the documentation is pretty clear:

"One important property is that the message will be delivered irrespective of the order in which the monitoring request and target’s termination occur, i.e. you still get the message even if at the time of registration the target is already dead."

  • http://doc.akka.io/docs/akka/2.0.1/general/supervision.html

And, you do not need to unwatch since the actor can't die twice, and it's not reference counted. It's binary.

Cheers, √

like image 154
Viktor Klang Avatar answered Nov 25 '22 21:11

Viktor Klang