Class Cascade.LinkedBlockingQueueMailbox<I>

java.lang.Object
com.mackenziehigh.cascade.Cascade.LinkedBlockingQueueMailbox<I>
Type Parameters:
I - is the type of messages that will be stored in the mailbox.
All Implemented Interfaces:
Cascade.Stage.Actor.Mailbox<I>
Enclosing interface:
Cascade

public static final class Cascade.LinkedBlockingQueueMailbox<I> extends Object implements Cascade.Stage.Actor.Mailbox<I>
A Mailbox implementation based on a LinkedBlockingQueue.
  • Method Details

    • create

      public static <I> Cascade.Stage.Actor.Mailbox<I> create()
      Create a new mailbox.
      Type Parameters:
      I - is the type of messages that will be stored in the mailbox.
      Returns:
      the new mailbox.
    • create

      public static <I> Cascade.Stage.Actor.Mailbox<I> create(int capacity)
      Create a new mailbox.
      Type Parameters:
      I - is the type of messages that will be stored in the mailbox.
      Parameters:
      capacity - is the maximum number of messages that can be stored simultaneously.
      Returns:
      the new mailbox.
    • offer

      public boolean offer(I message)
      Add a message to the mailbox.
      Specified by:
      offer in interface Cascade.Stage.Actor.Mailbox<I>
      Parameters:
      message - will be added to the mailbox, if possible.
      Returns:
      true, only if the message was in-fact added to the mailbox.
    • poll

      public I poll()
      Remove a message from the mailbox.

      If any message is in the mailbox, then this method must return non-null. In other words, a mailbox cannot choose to delay the removal of a message by forcing the caller to call this method again at a later time.

      A mailbox can choose to unilaterally drop messages. In other words, a message that was successfully offer()-ed to this mailbox may never be returned by poll(), at the sole discretion of the mailbox itself.

      Specified by:
      poll in interface Cascade.Stage.Actor.Mailbox<I>
      Returns:
      the message that was removed, or null, if no message was available.