Interface StashBuffer<T>

  • All Known Implementing Classes:
    StashBufferImpl

    public interface StashBuffer<T>
    A non thread safe mutable message buffer that can be used to buffer messages inside actors and then unstash them.

    The buffer can hold at most the given capacity number of messages.

    Not for user extension.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      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.
      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.
      StashBuffer<T> stash​(T message)
      Add one element to the end of the message buffer.
      Behavior<T> unstash​(Behavior<T> behavior, int numberOfMessages, scala.Function1<T,​T> wrap)
      Process numberOfMessages of the stashed messages with the behavior and the returned Behavior from each processed message.
      Behavior<T> unstashAll​(Behavior<T> behavior)
      Process all stashed messages with the behavior and the returned Behavior from each processed message.
    • Method Detail

      • 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:
        true if no more messages can be added, i.e. size equals the capacity of the stash buffer
      • stash

        StashBuffer<T> stash​(T message)
        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 NoSuchElementException if the buffer is empty
      • foreach

        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.

        Parameters:
        f - the function to apply to each element
      • clear

        void clear()
        Removes all messages from the buffer.
      • unstashAll

        Behavior<T> unstashAll​(Behavior<T> behavior)
        Process all stashed messages with the behavior and the returned Behavior from each processed message. The StashBuffer 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 initial behavior passed to unstashAll must not be unhandled.

        Parameters:
        behavior - (undocumented)
        Returns:
        (undocumented)
      • unstash

        Behavior<T> unstash​(Behavior<T> behavior,
                            int numberOfMessages,
                            scala.Function1<T,​T> wrap)
        Process numberOfMessages of the stashed messages with the behavior and the returned Behavior 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 to self 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 the wrap.

        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 to unstash must not be unhandled.

        Parameters:
        behavior - (undocumented)
        numberOfMessages - (undocumented)
        wrap - (undocumented)
        Returns:
        (undocumented)