Overridden callback.
Overridden callback. Prepends all messages in the stash to the mailbox, clears the stash, stops all children and invokes the postStop() callback of the superclass.
Adds the current message (the message that the actor received last) to the actor's stash.
Adds the current message (the message that the actor received last) to the actor's stash.
if the same message is stashed more than once
StashOverflowExceptionin case of a stash capacity violation
Prepends all messages in the stash to the mailbox, and then clears the stash.
Prepends all messages in the stash to the mailbox, and then clears the stash.
Messages from the stash are enqueued to the mailbox until the capacity of the
mailbox (if any) has been reached. In case a bounded mailbox overflows, a
MessageQueueAppendFailedException is thrown.
The stash is guaranteed to be empty after calling unstashAll().
in case of a capacity violation when prepending the stash to a bounded mailbox
The
Stashtrait enables an actor to temporarily stash away messages that can not or should not be handled using the actor's current behavior.Example:
class ActorWithProtocol extends Actor with Stash { def receive = { case "open" ⇒ unstashAll { case "write" ⇒ // do writing... case "close" ⇒ unstashAll() context.unbecome() case msg ⇒ stash() } case "done" ⇒ // done case msg ⇒ stash() } }Note that the
Stashtrait can only be used together with actors that have a deque-based mailbox. Actors can be configured to use a deque-based mailbox using a configuration like the following (see the documentation on dispatchers on how to configure a custom dispatcher):akka { actor { my-custom-dispatcher { mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox" } } }Note that the
Stashtrait must be mixed into (a subclass of) theActortrait before any trait/class that overrides thepreRestartcallback. This means it's not possible to writeActor with MyActor with StashifMyActoroverridespreRestart.