Class Cascade.PriorityBlockingQueueMailbox<I>

java.lang.Object
com.mackenziehigh.cascade.Cascade.PriorityBlockingQueueMailbox<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.PriorityBlockingQueueMailbox<I> extends Object implements Cascade.Stage.Actor.Mailbox<I>
A Mailbox implementation based on a PriorityBlockingQueue.
  • Method Details

    • create

      public static <I> Cascade.Stage.Actor.Mailbox<I> create(int initial, Comparator<I> ordering)
      Create a new mailbox.
      Type Parameters:
      I - is the type of messages that will be stored in the mailbox.
      Parameters:
      initial - is the initial size of the backing data-structure.
      ordering - assigns priorities to messages in the mailbox.
      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.