diff --git a/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala b/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala index 322b50b900..f5a704dfb2 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala @@ -46,9 +46,26 @@ private[akka] abstract class Mailbox(val actor: ActorCell, val messageQueue: Mes import Mailbox._ + /** + * Try to enqueue the message to this queue, or throw an exception. + */ def enqueue(receiver: ActorRef, msg: Envelope): Unit = messageQueue.enqueue(receiver, msg) + + /** + * Try to dequeue the next message from this queue, return null failing that. + */ def dequeue(): Envelope = messageQueue.dequeue() + + /** + * Indicates whether this queue is non-empty. + */ def hasMessages: Boolean = messageQueue.hasMessages + + /** + * 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. + */ def numberOfMessages: Int = messageQueue.numberOfMessages @volatile diff --git a/akka-testkit/src/main/scala/akka/testkit/CallingThreadDispatcher.scala b/akka-testkit/src/main/scala/akka/testkit/CallingThreadDispatcher.scala index 84ea7aa197..2fe664d7b6 100644 --- a/akka-testkit/src/main/scala/akka/testkit/CallingThreadDispatcher.scala +++ b/akka-testkit/src/main/scala/akka/testkit/CallingThreadDispatcher.scala @@ -294,7 +294,7 @@ class CallingThreadMailbox(_receiver: ActorCell, val mailboxType: MailboxType) e override def enqueue(receiver: ActorRef, msg: Envelope): Unit = throw new UnsupportedOperationException("CallingThreadMailbox cannot enqueue normally") override def dequeue(): Envelope = throw new UnsupportedOperationException("CallingThreadMailbox cannot dequeue normally") override def hasMessages: Boolean = q.get.q.hasMessages - override def numberOfMessages: Int = -1 + override def numberOfMessages: Int = 0 def queue = q.get