akka.dispatch
Class Mailbox

java.lang.Object
  extended by akka.dispatch.Mailbox
All Implemented Interfaces:
SystemMessageQueue, java.lang.Runnable
Direct Known Subclasses:
CallingThreadMailbox

public abstract class Mailbox
extends java.lang.Object
implements SystemMessageQueue, java.lang.Runnable

Mailbox and InternalMailbox is separated in two classes because ActorCell is needed for implementation, but can't be exposed to user defined mailbox subclasses.

INTERNAL API


Constructor Summary
Mailbox(MessageQueue messageQueue)
           
 
Method Summary
protected  int _statusDoNotCallMeDirectly()
           
protected  SystemMessage _systemQueueDoNotCallMeDirectly()
           
 ActorCell actor()
           
 boolean becomeClosed()
          set new primary status Closed.
 boolean canBeScheduledForExecution(boolean hasMessageHint, boolean hasSystemMessageHint)
           
protected  void cleanUp()
          Overridable callback to clean up the mailbox, called when an actor is unregistered.
static int Closed()
           
 int currentStatus()
           
static boolean debug()
           
 Envelope dequeue()
          Try to dequeue the next message from this queue, return null failing that.
 MessageDispatcher dispatcher()
           
 void enqueue(ActorRef receiver, Envelope msg)
          Try to enqueue the message to this queue, or throw an exception.
 boolean hasMessages()
          Indicates whether this queue is non-empty.
 boolean isClosed()
           
 boolean isScheduled()
           
 boolean isSuspended()
           
 MessageQueue messageQueue()
           
 int numberOfMessages()
          Should return the current number of messages held in this queue; may always return 0 if no other value is available efficiently.
static int Open()
           
 void processAllSystemMessages()
          Will at least try to process all queued system messages: in case of failure simply drop and go on to the next, because there is nothing to restart here (failure is in ActorCell somewhere …).
 boolean resume()
          Reduce the suspend count by one.
 void run()
           
static int Scheduled()
           
 void setActor(ActorCell cell)
           
 boolean setAsIdle()
          Reset Scheduled status, keeping primary status as is.
 boolean setAsScheduled()
          Set Scheduled status, keeping primary status as is.
protected  void setStatus(int newStatus)
           
static int shouldNotProcessMask()
           
 boolean shouldProcessMessage()
           
static int shouldScheduleMask()
           
 boolean suspend()
          Increment the suspend count by one.
 int suspendCount()
           
static int suspendMask()
           
static int suspendUnit()
           
protected  LatestFirstSystemMessageList systemQueueGet()
           
protected  boolean systemQueuePut(LatestFirstSystemMessageList _old, LatestFirstSystemMessageList _new)
           
protected  boolean updateStatus(int oldStatus, int newStatus)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface akka.dispatch.SystemMessageQueue
hasSystemMessages, systemDrain, systemEnqueue
 

Constructor Detail

Mailbox

public Mailbox(MessageQueue messageQueue)
Method Detail

Open

public static final int Open()

Closed

public static final int Closed()

Scheduled

public static final int Scheduled()

shouldScheduleMask

public static final int shouldScheduleMask()

shouldNotProcessMask

public static final int shouldNotProcessMask()

suspendMask

public static final int suspendMask()

suspendUnit

public static final int suspendUnit()

debug

public static final boolean debug()

messageQueue

public MessageQueue messageQueue()

actor

public ActorCell actor()

setActor

public void setActor(ActorCell cell)

dispatcher

public MessageDispatcher dispatcher()

enqueue

public void enqueue(ActorRef receiver,
                    Envelope msg)
Try to enqueue the message to this queue, or throw an exception.

Parameters:
receiver - (undocumented)
msg - (undocumented)

dequeue

public Envelope dequeue()
Try to dequeue the next message from this queue, return null failing that.

Returns:
(undocumented)

hasMessages

public boolean hasMessages()
Indicates whether this queue is non-empty.

Returns:
(undocumented)

numberOfMessages

public int numberOfMessages()
Should return the current number of messages held in this queue; may always return 0 if no other value is available efficiently. Do not use this for testing for presence of messages, use hasMessages instead.

Returns:
(undocumented)

_statusDoNotCallMeDirectly

protected int _statusDoNotCallMeDirectly()

_systemQueueDoNotCallMeDirectly

protected SystemMessage _systemQueueDoNotCallMeDirectly()

currentStatus

public final int currentStatus()

shouldProcessMessage

public final boolean shouldProcessMessage()

suspendCount

public final int suspendCount()

isSuspended

public final boolean isSuspended()

isClosed

public final boolean isClosed()

isScheduled

public final boolean isScheduled()

updateStatus

protected final boolean updateStatus(int oldStatus,
                                     int newStatus)

setStatus

protected final void setStatus(int newStatus)

resume

public final boolean resume()
Reduce the suspend count by one. Caller does not need to worry about whether status was Scheduled or not.

Returns:
true if the suspend count reached zero

suspend

public final boolean suspend()
Increment the suspend count by one. Caller does not need to worry about whether status was Scheduled or not.

Returns:
true if the previous suspend count was zero

becomeClosed

public final boolean becomeClosed()
set new primary status Closed. Caller does not need to worry about whether status was Scheduled or not.

Returns:
(undocumented)

setAsScheduled

public final boolean setAsScheduled()
Set Scheduled status, keeping primary status as is.

Returns:
(undocumented)

setAsIdle

public final boolean setAsIdle()
Reset Scheduled status, keeping primary status as is.

Returns:
(undocumented)

systemQueueGet

protected final LatestFirstSystemMessageList systemQueueGet()

systemQueuePut

protected final boolean systemQueuePut(LatestFirstSystemMessageList _old,
                                       LatestFirstSystemMessageList _new)

canBeScheduledForExecution

public final boolean canBeScheduledForExecution(boolean hasMessageHint,
                                                boolean hasSystemMessageHint)

run

public final void run()
Specified by:
run in interface java.lang.Runnable

processAllSystemMessages

public final void processAllSystemMessages()
Will at least try to process all queued system messages: in case of failure simply drop and go on to the next, because there is nothing to restart here (failure is in ActorCell somewhere …). In case the mailbox becomes closed (because of processing a Terminate message), dump all already dequeued message to deadLetters.


cleanUp

protected void cleanUp()
Overridable callback to clean up the mailbox, called when an actor is unregistered. By default it dequeues all system messages + messages and ships them to the owning actors' systems' DeadLetterMailbox