Interface StashBuffer<T>
The buffer can hold at most the given capacity number of messages.
Not for user extension.
-
Method Summary
Modifier and TypeMethodDescriptionintcapacity()What is the capacity of this buffer.voidclear()Removes all messages from the buffer.<U> booleancontains(U message) Tests whether thisStashBuffercontains a given message.booleanTests whether a predicate holds for at least one element of thisStashBuffer.voidIterate over all elements of the buffer and apply a function to each element, without removing them.head()Return the first element of the message buffer without removing it.booleanisEmpty()Check if the message buffer is empty.booleanisFull()booleannonEmpty()Check if the message buffer is not empty.intsize()How many elements are in the message buffer.Add one element to the end of the message buffer.Transition to the givenbehaviorand processnumberOfMessagesof the stashed messages.unstashAll(Behavior<T> behavior) Transition to the givenbehaviorand process all stashed messages.
-
Method Details
-
isEmpty
boolean isEmpty()Check if the message buffer is empty.- Returns:
- if the buffer is empty
-
nonEmpty
boolean nonEmpty()Check if the message buffer is not empty.- Returns:
- if the buffer is not empty
-
size
int size()How many elements are in the message buffer.- Returns:
- the number of elements in the message buffer
-
capacity
int capacity()What is the capacity of this buffer.- Returns:
- the capacity of this buffer
-
isFull
boolean isFull()- Returns:
trueif no more messages can be added, i.e. size equals the capacity of the stash buffer
-
stash
Add one element to the end of the message buffer.- Parameters:
message- the message to buffer- Returns:
- this message buffer
-
head
T head()Return the first element of the message buffer without removing it.- Returns:
- the first element or throws
NoSuchElementExceptionif the buffer is empty - Throws:
NoSuchElementException- if the buffer is empty
-
foreach
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
-
contains
<U> boolean contains(U message) Tests whether thisStashBuffercontains a given message.- Parameters:
message- the message to test- Returns:
- true if the buffer contains the message, false otherwise.
-
exists
Tests whether a predicate holds for at least one element of thisStashBuffer.- Parameters:
predicate- the predicate used to test- Returns:
- true if the predicate holds for at least one message, false otherwise.
-
clear
void clear()Removes all messages from the buffer. -
unstashAll
Transition to the givenbehaviorand process all stashed messages. Messages will be processed in the same order they arrived. TheStashBufferwill 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
behaviorpassed tounstashAllmust not beunhandled. -
unstash
Transition to the givenbehaviorand processnumberOfMessagesof the stashed messages. The messages will be processed in the same order they arrived.The purpose of this method, compared to
unstashAllis to unstash a limited number of messages and then send a message toselfbefore 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
behaviorpassed tounstashmust not beunhandled.
-