Package akka.actor
Class AbstractActorWithStash
- java.lang.Object
-
- akka.actor.AbstractActor
-
- akka.actor.AbstractActorWithStash
-
- All Implemented Interfaces:
Actor
,Stash
,StashSupport
,UnrestrictedStash
,RequiresMessageQueue<DequeBasedMessageQueueSemantics>
public abstract class AbstractActorWithStash extends AbstractActor implements Stash
Java API: compatible with lambda expressionsActor base class that should be extended to create an actor with a 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 AbstractActorWithStash { int count = 0; public MyActorWithStash() { receive(ReceiveBuilder. match(String.class, s -> { if (count < 0) { sender().tell(new Integer(s.length()), self()); } else if (count == 2) { count = -1; unstashAll(); } else { count += 1; stash(); }}).build() ); } }
Note that the subclasses ofAbstractActorWithStash
by default request a Deque based mailbox since this class implements theRequiresMessageQueue<DequeBasedMessageQueueSemantics>
marker interface. You can override the default mailbox provided whenDequeBasedMessageQueueSemantics
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 seeAbstractActorWithUnboundedStash
. There is also an unrestricted versionAbstractActorWithUnrestrictedStash
that does not enforce the mailbox type.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class akka.actor.AbstractActor
AbstractActor.ActorContext, AbstractActor.Receive
-
Nested classes/interfaces inherited from interface akka.actor.Actor
Actor.emptyBehavior$, Actor.ignoringBehavior$
-
-
Constructor Summary
Constructors Constructor Description AbstractActorWithStash()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
akka$actor$StashSupport$_setter_$mailbox_$eq(DequeBasedMessageQueueSemantics x$1)
-
Methods inherited from class akka.actor.AbstractActor
akka$actor$Actor$_setter_$context_$eq, akka$actor$Actor$_setter_$self_$eq, context, createReceive, emptyBehavior, getContext, getSelf, getSender, postRestart, postStop, preRestart, preRestart, preStart, receive, receiveBuilder, self, supervisorStrategy
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface akka.actor.Actor
akka$actor$Actor$_setter_$context_$eq, akka$actor$Actor$_setter_$self_$eq, aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, context, postRestart, preStart, receive, self, sender, supervisorStrategy, unhandled
-
Methods inherited from interface akka.actor.StashSupport
actorCell, clearStash, context, enqueueFirst, prepend, self, stash, theStash_$eq, unstash, unstashAll, unstashAll
-
Methods inherited from interface akka.actor.UnrestrictedStash
postStop, preRestart, super$postStop, super$preRestart
-
-
-
-
Method Detail
-
akka$actor$StashSupport$_setter_$mailbox_$eq
protected void akka$actor$StashSupport$_setter_$mailbox_$eq(DequeBasedMessageQueueSemantics x$1)
- Specified by:
akka$actor$StashSupport$_setter_$mailbox_$eq
in interfaceStashSupport
-
-