Class StashBufferImpl<T>
- java.lang.Object
-
- akka.actor.typed.internal.StashBufferImpl<T>
-
- All Implemented Interfaces:
StashBuffer<T>
,StashBuffer<T>
public final class StashBufferImpl<T> extends java.lang.Object implements StashBuffer<T>, StashBuffer<T>
INTERNAL API
-
-
Constructor Summary
Constructors Constructor Description StashBufferImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> StashBufferImpl<T>
apply(ActorContext<T> ctx, int capacity)
int
capacity()
What is the capacity of this buffer.void
clear()
Removes all messages from the buffer.void
foreach(scala.Function1<T,scala.runtime.BoxedUnit> f)
Iterate over all elements of the buffer and apply a function to each element, without removing them.void
forEach(Procedure<T> f)
Iterate over all elements of the buffer and apply a function to each element, without removing them.T
head()
Return the first element of the message buffer without removing it.boolean
isEmpty()
Check if the message buffer is empty.boolean
isFull()
boolean
nonEmpty()
Check if the message buffer is not empty.int
size()
How many elements are in the message buffer.StashBufferImpl<T>
stash(T message)
Add one element to the end of the message buffer.java.lang.String
toString()
Behavior<T>
unstash(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.Behavior<T>
unstash(Behavior<T> behavior, int numberOfMessages, scala.Function1<T,T> wrap)
ProcessnumberOfMessages
of the stashed messages with thebehavior
and the returnedBehavior
from each processed message.Behavior<T>
unstashAll(Behavior<T> behavior)
Process all stashed messages with thebehavior
and the returnedBehavior
from each processed message.void
unstashed(ActorContext<T> ctx, <any> node)
-
-
-
Method Detail
-
apply
public static <T> StashBufferImpl<T> apply(ActorContext<T> ctx, int capacity)
-
capacity
public int capacity()
Description copied from interface:StashBuffer
What is the capacity of this buffer.- Specified by:
capacity
in interfaceStashBuffer<T>
- Specified by:
capacity
in interfaceStashBuffer<T>
- Returns:
- the capacity of this buffer
-
isEmpty
public boolean isEmpty()
Description copied from interface:StashBuffer
Check if the message buffer is empty.- Specified by:
isEmpty
in interfaceStashBuffer<T>
- Specified by:
isEmpty
in interfaceStashBuffer<T>
- Returns:
- if the buffer is empty
-
nonEmpty
public boolean nonEmpty()
Description copied from interface:StashBuffer
Check if the message buffer is not empty.- Specified by:
nonEmpty
in interfaceStashBuffer<T>
- Specified by:
nonEmpty
in interfaceStashBuffer<T>
- Returns:
- if the buffer is not empty
-
size
public int size()
Description copied from interface:StashBuffer
How many elements are in the message buffer.- Specified by:
size
in interfaceStashBuffer<T>
- Specified by:
size
in interfaceStashBuffer<T>
- Returns:
- the number of elements in the message buffer
-
isFull
public boolean isFull()
- Specified by:
isFull
in interfaceStashBuffer<T>
- Specified by:
isFull
in interfaceStashBuffer<T>
- Returns:
true
if no more messages can be added, i.e. size equals the capacity of the stash buffer
-
stash
public StashBufferImpl<T> stash(T message)
Description copied from interface:StashBuffer
Add one element to the end of the message buffer.StashOverflowException
is thrown if the bufferStashBuffer.isFull()
.- Specified by:
stash
in interfaceStashBuffer<T>
- Specified by:
stash
in interfaceStashBuffer<T>
- Parameters:
message
- the message to buffer- Returns:
- this message buffer
-
clear
public void clear()
Description copied from interface:StashBuffer
Removes all messages from the buffer.- Specified by:
clear
in interfaceStashBuffer<T>
- Specified by:
clear
in interfaceStashBuffer<T>
-
head
public T head()
Description copied from interface:StashBuffer
Return the first element of the message buffer without removing it.- Specified by:
head
in interfaceStashBuffer<T>
- Specified by:
head
in interfaceStashBuffer<T>
- Returns:
- the first element or throws
NoSuchElementException
if the buffer is empty
-
foreach
public void foreach(scala.Function1<T,scala.runtime.BoxedUnit> f)
Description copied from interface:StashBuffer
Iterate over all elements of the buffer and apply a function to each element, without removing them.- Specified by:
foreach
in interfaceStashBuffer<T>
- Parameters:
f
- the function to apply to each element
-
forEach
public void forEach(Procedure<T> f)
Description copied from interface:StashBuffer
Iterate over all elements of the buffer and apply a function to each element, without removing them.- Specified by:
forEach
in interfaceStashBuffer<T>
- Parameters:
f
- the function to apply to each element
-
unstashAll
public Behavior<T> unstashAll(Behavior<T> behavior)
Description copied from interface:StashBuffer
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
.- Specified by:
unstashAll
in interfaceStashBuffer<T>
- Specified by:
unstashAll
in interfaceStashBuffer<T>
-
unstash
public Behavior<T> unstash(Behavior<T> behavior, int numberOfMessages, scala.Function1<T,T> wrap)
Description copied from interface:StashBuffer
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
.- Specified by:
unstash
in interfaceStashBuffer<T>
-
unstash
public Behavior<T> unstash(Behavior<T> behavior, int numberOfMessages, java.util.function.Function<T,T> wrap)
Description copied from interface:StashBuffer
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
.- Specified by:
unstash
in interfaceStashBuffer<T>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
unstashed
public void unstashed(ActorContext<T> ctx, <any> node)
-
-