Suspending AKKA actor

630 Views Asked by At

Suppose there are messages in the mailbox. Is it possible to suspend the Actor from processing the messages and resume it at a later point without holding the thread.

Thanks, Ravi

1

There are 1 best solutions below

2
On

Akka provides a way of changing the behavior of an actor using context.become() and context.unbecome(). It also provides a way to stash() and unstash() your message once you have changed your behavior.

The idea would be to become() a new behavior that basically does nothing (like suspended) but stash the messages. Once a certain condition is met, the actor unbecome()s and unstashAll() the messages to put them back again in the mailbox and start processing them again.

You can find a good example in the Akka docs (look for Stash): http://doc.akka.io/docs/akka/snapshot/scala/actors.html