Terminating actors

There are a couple of ways to stop an actor in Akka. The most direct approach involves calling the stop method of the context, like so:

context stop child
context.stop(self)

The actor terminates asynchronously after it finishes processing its current message, but not after other messages in the inbox. This contrasts to sending an actor a PoisonPill or Kill message, which is enqueued into the mailbox and processed in an orderly fashion.

The Kill message will cause an actor to throw an ActorKilledException, which in turn will involve its supervision chain (more on that topic later in this chapter) to decide how this actor's failure should be handled.

Stopping an actor using a context or PoisonPill in contrast to Kill is done gracefully. The actor will stop all of its children, execute life cycle hooks, and inform its supervisor appropriately.

The actor's termination is propagated top-down, but the actual stopping occurs bottom-up. One slow actor that takes a long (or infinite) time to stop can prevent the whole chain of actors from being terminated.

Now that we have our blocking Mixer, it is time to define a Chef:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.135.249