Package org.apache.pekko.actor
Class AbstractActorWithStash
java.lang.Object
org.apache.pekko.actor.AbstractActor
org.apache.pekko.actor.AbstractActorWithStash
- All Implemented Interfaces:
Actor,Stash,StashSupport,UnrestrictedStash,RequiresMessageQueue<DequeBasedMessageQueueSemantics>
Java API: compatible with lambda expressions
Actor 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 of AbstractActorWithStash 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:
pekko.actor.mailbox.requirements {
"org.apache.pekko.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 pekko.actor.AbstractActorWithUnboundedStash.
There is also an unrestricted version pekko.actor.AbstractActorWithUnrestrictedStash that does not
enforce the mailbox type.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.pekko.actor.AbstractActor
AbstractActor.ActorContext, AbstractActor.ReceiveNested classes/interfaces inherited from interface org.apache.pekko.actor.Actor
Actor.emptyBehavior$, Actor.ignoringBehavior$ -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidMethods inherited from class org.apache.pekko.actor.AbstractActor
context, createReceive, emptyBehavior, getContext, getSelf, getSender, org$apache$pekko$actor$Actor$_setter_$context_$eq, org$apache$pekko$actor$Actor$_setter_$self_$eq, postRestart, postStop, preRestart, preRestart, preStart, receive, receiveBuilder, self, supervisorStrategyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.pekko.actor.Actor
aroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, context, org$apache$pekko$actor$Actor$_setter_$context_$eq, org$apache$pekko$actor$Actor$_setter_$self_$eq, postRestart, preStart, receive, self, sender, supervisorStrategy, unhandledMethods inherited from interface org.apache.pekko.actor.StashSupport
actorCell, clearStash, context, enqueueFirst, prepend, self, stash, theStash_$eq, unstash, unstashAll, unstashAllMethods inherited from interface org.apache.pekko.actor.UnrestrictedStash
postStop, preRestart, super$postStop, super$preRestart
-
Constructor Details
-
AbstractActorWithStash
public AbstractActorWithStash()
-
-
Method Details
-
org$apache$pekko$actor$StashSupport$_setter_$mailbox_$eq
protected void org$apache$pekko$actor$StashSupport$_setter_$mailbox_$eq(DequeBasedMessageQueueSemantics x$1) - Specified by:
org$apache$pekko$actor$StashSupport$_setter_$mailbox_$eqin interfaceStashSupport
-