Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka context watch/unwatch happens-before relationship

I have the following sequential actions on two actors, a parent P and a child C:

  1. P watches C (context watch c)
  2. P unwatches C (context unwatch c)
  3. P stops C gracefully (c ! PoisonPill)

What I want to know is; am I guaranteed that P does not receive a Terminated event for C?

Here's a sample piece of code

class HappensBefore extends App {
  class C extends Actor { def receive = {} } 
  class P extends Actor {
    val c = context actorOf Props[C]
    context watch c
    context unwatch c
    c ! PoisonPill
    def receive = { case Terminated(child) => println("Oh Noes!") }
  }
  ActorSystem("test") actorOf Props[P]
}
like image 432
oxbow_lakes Avatar asked May 14 '12 17:05

oxbow_lakes


People also ask

What does the life cycle postStop do?

2) postStop() This method is used to release resources after stopping the Actor. It may be used for deregistering this Actor. Messages sent to a stopped actor will be redirected to the deadLetters of the ActorSystem.

Is Akka asynchronous?

Akka actors are asynchronous from the beginning. Reactive programs can be implemented in either way, synchronous and asynchronous.

Which method provides initial Behaviour to actor?

Start Hook This method is called when the actor is first created.

How does Akka work internally?

Akka ensures that each instance of an actor runs in its own lightweight thread and that messages are processed one at a time. In this way, each actor's state can be reliably maintained without the developer needing to explicitly worry about synchronization or race conditions.


1 Answers

No, there is no such guarantee.

like image 159
Viktor Klang Avatar answered Sep 28 '22 02:09

Viktor Klang