Interface Stash
-
- All Superinterfaces:
Actor
,RequiresMessageQueue<DequeBasedMessageQueueSemantics>
,StashSupport
,UnrestrictedStash
- All Known Subinterfaces:
AbstractPersistentActorLike
,AsyncWriteProxy
,AtLeastOnceDelivery
,AtLeastOnceDeliveryLike
,Eventsourced
,PersistenceStash
,PersistentActor
,PersistentFSM<S,D,E>
- All Known Implementing Classes:
AbstractActorWithStash
,AbstractFSMWithStash
,AbstractPersistentActor
,AbstractPersistentActorWithAtLeastOnceDelivery
,AbstractPersistentActorWithTimers
,AbstractPersistentFSM
,AbstractPersistentLoggingFSM
,JournalPerfSpec.BenchActor
,PersistencePluginProxy
,PersistentShardCoordinator
public interface Stash extends UnrestrictedStash, RequiresMessageQueue<DequeBasedMessageQueueSemantics>
TheStash
trait 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() context.become({ case "write" => // do writing... case "close" => unstashAll() context.unbecome() case msg => stash() }, discardOld = false) case "done" => // done case msg => stash() } }
Note that the
Stash
trait can only be used together with actors that have a deque-based mailbox. By default Stash based actors request a Deque based mailbox since the stash trait extendsRequiresMessageQueue[DequeBasedMessageQueueSemantics]
. You can override the default mailbox provided whenDequeBasedMessageQueueSemantics
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
that also enforces unboundedness of the deque seepekko.actor.UnboundedStash
. For aStash
that does not enforce any mailbox type seepekko.actor.UnrestrictedStash
.Note that the
Stash
trait must be mixed into (a subclass of) theActor
trait before any trait/class that overrides thepreRestart
callback. This means it's not possible to writeActor with MyActor with Stash
ifMyActor
overridespreRestart
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pekko.actor.Actor
Actor.emptyBehavior$, Actor.ignoringBehavior$
-
-
Method Summary
-
Methods 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, unhandled
-
Methods inherited from interface org.apache.pekko.actor.StashSupport
actorCell, clearStash, context, enqueueFirst, mailbox, org$apache$pekko$actor$StashSupport$_setter_$mailbox_$eq, prepend, self, stash, theStash_$eq, unstash, unstashAll, unstashAll
-
Methods inherited from interface org.apache.pekko.actor.UnrestrictedStash
postStop, preRestart, super$postStop, super$preRestart
-
-