public abstract class UntypedActorWithStash extends UntypedActor implements Stash
The stash enables an actor to temporarily stash away messages that can not or should not be handled using the actor's current behavior.
Example:public class MyActorWithStash extends UntypedActorWithStash { int count = 0; public void onReceive(Object msg) { if (msg instanceof String) { if (count < 0) { getSender().tell(new Integer(((String) msg).length()), getSelf()); } else if (count == 2) { count = -1; unstashAll(); } else { count += 1; stash(); } } } }Note that the subclasses of
UntypedActorWithStash
by default request a Deque based mailbox since this class
implements the RequiresMessageQueue<DequeBasedMessageQueueSemantics>
marker interface.
You can override the default mailbox provided when DequeBasedMessageQueueSemantics
are requested via config:
akka.actor.mailbox.requirements { "akka.dispatch.BoundedDequeBasedMessageQueueSemantics" = your-custom-mailbox }Alternatively, you can add your own requirement marker to the actor and configure a mailbox type to be used for your marker.
For a Stash
based actor that enforces unbounded deques see UntypedActorWithUnboundedStash
.
There is also an unrestricted version UntypedActorWithUnrestrictedStash
that does not
enforce the mailbox type.
Actor.emptyBehavior$, Actor.ignoringBehavior$
Constructor and Description |
---|
UntypedActorWithStash() |
Modifier and Type | Method and Description |
---|---|
DequeBasedMessageQueueSemantics |
mailbox() |
context, getContext, getSelf, getSender, onReceive, postRestart, postStop, preRestart, preStart, receive, self, supervisorStrategy, unhandled
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
postStop, preRestart
aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, context, postRestart, preStart, receive, self, sender, supervisorStrategy, unhandled
actorCell, clearStash, context, enqueueFirst, prepend, self, stash, unstash, unstashAll, unstashAll
public DequeBasedMessageQueueSemantics mailbox()
mailbox
in interface StashSupport