Class StashBuffer<T>
- java.lang.Object
-
- akka.actor.typed.javadsl.StashBuffer<T>
-
- Direct Known Subclasses:
StashBufferImpl
public abstract class StashBuffer<T> extends java.lang.Object
Check if the message buffer is empty.
-
-
Constructor Summary
Constructors Constructor Description StashBuffer()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <T> StashBuffer<T>
create(int capacity)
abstract void
forEach(java.util.function.Consumer<T> f)
Iterate over all elements of the buffer and apply a function to each element, without removing them.abstract T
head()
Return the first element of the message buffer without removing it.abstract boolean
isEmpty()
abstract boolean
isFull()
abstract boolean
nonEmpty()
Check if the message buffer is not empty.abstract int
size()
How many elements are in the message buffer.abstract StashBuffer<T>
stash(T message)
Add one element to the end of the message buffer.abstract Behavior<T>
unstash(ActorContext<T> ctx, Behavior<T> behavior, int numberOfMessages, java.util.function.Function<T,T> wrap)
ProcessnumberOfMessages
of the stashed messages with thebehavior
and the returnedBehavior
from each processed message.abstract Behavior<T>
unstashAll(ActorContext<T> ctx, Behavior<T> behavior)
Process all stashed messages with thebehavior
and the returnedBehavior
from each processed message.
-
-
-
Method Detail
-
create
public static <T> StashBuffer<T> create(int capacity)
-
isEmpty
public abstract boolean isEmpty()
-
nonEmpty
public abstract boolean nonEmpty()
Check if the message buffer is not empty.- Returns:
- if the buffer is not empty
-
size
public abstract int size()
How many elements are in the message buffer.- Returns:
- the number of elements in the message buffer
-
isFull
public abstract boolean isFull()
- Returns:
true
if no more messages can be added, i.e. size equals the capacity of the stash buffer
-
stash
public abstract StashBuffer<T> stash(T message)
Add one element to the end of the message buffer.StashOverflowException
is thrown if the bufferisFull()
.- Parameters:
message
- the message to buffer- Returns:
- this message buffer
-
head
public abstract T head()
Return the first element of the message buffer without removing it.- Returns:
- the first element or throws
NoSuchElementException
if the buffer is empty
-
forEach
public abstract void forEach(java.util.function.Consumer<T> f)
Iterate over all elements of the buffer and apply a function to each element, without removing them.- Parameters:
f
- the function to apply to each element
-
unstashAll
public abstract Behavior<T> unstashAll(ActorContext<T> ctx, Behavior<T> behavior)
Process all stashed messages with thebehavior
and the returnedBehavior
from each processed message. TheStashBuffer
will be empty after processing all messages, unless an exception is thrown or messages are stashed while unstashing.If an exception is thrown by processing a message a proceeding messages and the message causing the exception have been removed from the
StashBuffer
, but unprocessed messages remain.It's allowed to stash messages while unstashing. Those newly added messages will not be processed by this call and have to be unstashed in another call.
The
behavior
passed tounstashAll
must not beunhandled
.- Parameters:
ctx
- (undocumented)behavior
- (undocumented)- Returns:
- (undocumented)
-
unstash
public abstract Behavior<T> unstash(ActorContext<T> ctx, Behavior<T> behavior, int numberOfMessages, java.util.function.Function<T,T> wrap)
ProcessnumberOfMessages
of the stashed messages with thebehavior
and the returnedBehavior
from each processed message.The purpose of this method, compared to
unstashAll
, is to unstash a limited number of messages and then send a message toself
before continuing unstashing more. That means that other new messages may arrive in-between and those must be stashed to keep the original order of messages. To differentiate between unstashed and new incoming messages the unstashed messages can be wrapped in another message with thewrap
.If an exception is thrown by processing a message a proceeding messages and the message causing the exception have been removed from the
StashBuffer
, but unprocessed messages remain.It's allowed to stash messages while unstashing. Those newly added messages will not be processed by this call and have to be unstashed in another call.
The
behavior
passed tounstash
must not beunhandled
.- Parameters:
ctx
- (undocumented)behavior
- (undocumented)numberOfMessages
- (undocumented)wrap
- (undocumented)- Returns:
- (undocumented)
-
-