From 00dea71492dfcaaf20ae4d6668b5a253cebcf9de Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Thu, 10 Mar 2011 12:03:57 +0100 Subject: [PATCH] =?UTF-8?q?Commented=20out=20the=20BoundedPriorityMailbox,?= =?UTF-8?q?=20since=20it=20wasn=C2=B4t=20bounded,=20and=20broke=20out=20th?= =?UTF-8?q?e=20mailbox=20logic=20into=20PriorityMailbox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExecutorBasedEventDrivenDispatcher.scala | 32 +++++++++++-------- .../scala/akka/dispatch/MailboxHandling.scala | 6 ++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/akka-actor/src/main/scala/akka/dispatch/ExecutorBasedEventDrivenDispatcher.scala b/akka-actor/src/main/scala/akka/dispatch/ExecutorBasedEventDrivenDispatcher.scala index 4551eaf54a..e3a72c4c9f 100644 --- a/akka-actor/src/main/scala/akka/dispatch/ExecutorBasedEventDrivenDispatcher.scala +++ b/akka-actor/src/main/scala/akka/dispatch/ExecutorBasedEventDrivenDispatcher.scala @@ -228,36 +228,40 @@ trait ExecutableMailbox extends Runnable { self: MessageQueue => */ class PriorityExecutorBasedEventDrivenDispatcher( name: String, - comparator: java.util.Comparator[MessageInvocation], + val comparator: java.util.Comparator[MessageInvocation], throughput: Int = Dispatchers.THROUGHPUT, throughputDeadlineTime: Int = Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, - mailboxType: MailboxType = Dispatchers.MAILBOX_TYPE, + mailboxType: UnboundedMailbox = UnboundedMailbox(false), config: ThreadPoolConfig = ThreadPoolConfig() - ) extends ExecutorBasedEventDrivenDispatcher(name, throughput, throughputDeadlineTime, mailboxType, config) { + ) extends ExecutorBasedEventDrivenDispatcher(name, throughput, throughputDeadlineTime, mailboxType, config) with PriorityMailbox { - def this(name: String, comparator: java.util.Comparator[MessageInvocation], throughput: Int, throughputDeadlineTime: Int, mailboxType: MailboxType) = + def this(name: String, comparator: java.util.Comparator[MessageInvocation], throughput: Int, throughputDeadlineTime: Int, mailboxType: UnboundedMailbox) = this(name, comparator, throughput, throughputDeadlineTime, mailboxType,ThreadPoolConfig()) // Needed for Java API usage - def this(name: String, comparator: java.util.Comparator[MessageInvocation], throughput: Int, mailboxType: MailboxType) = + def this(name: String, comparator: java.util.Comparator[MessageInvocation], throughput: Int, mailboxType: UnboundedMailbox) = this(name, comparator, throughput, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, mailboxType) // Needed for Java API usage def this(name: String, comparator: java.util.Comparator[MessageInvocation], throughput: Int) = - this(name, comparator, throughput, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, Dispatchers.MAILBOX_TYPE) // Needed for Java API usage + this(name, comparator, throughput, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, UnboundedMailbox(false)) // Needed for Java API usage def this(name: String, comparator: java.util.Comparator[MessageInvocation], config: ThreadPoolConfig) = - this(name, comparator, Dispatchers.THROUGHPUT, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, Dispatchers.MAILBOX_TYPE, config) + this(name, comparator, Dispatchers.THROUGHPUT, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, UnboundedMailbox(false), config) def this(name: String, comparator: java.util.Comparator[MessageInvocation]) = - this(name, comparator, Dispatchers.THROUGHPUT, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, Dispatchers.MAILBOX_TYPE) // Needed for Java API usage + this(name, comparator, Dispatchers.THROUGHPUT, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, UnboundedMailbox(false)) // Needed for Java API usage +} - override def createMailbox(actorRef: ActorRef): AnyRef = mailboxType match { +trait PriorityMailbox { self: ExecutorBasedEventDrivenDispatcher => + def comparator: java.util.Comparator[MessageInvocation] + + override def createMailbox(actorRef: ActorRef): AnyRef = self.mailboxType match { case UnboundedMailbox(blocking) => new UnboundedPriorityMessageQueue(blocking, comparator) with ExecutableMailbox { - def dispatcher = PriorityExecutorBasedEventDrivenDispatcher.this + def dispatcher = self } - case BoundedMailbox(blocking, capacity, pushTimeOut) => - new BoundedPriorityMessageQueue(capacity, pushTimeOut, blocking, comparator) with ExecutableMailbox { - def dispatcher = PriorityExecutorBasedEventDrivenDispatcher.this - } + case BoundedMailbox(blocking, capacity, pushTimeOut) => throw new IllegalStateException("PriorityMailbox does not work when a Bounded mailbox is specified.") + /*new BoundedPriorityMessageQueue(capacity, pushTimeOut, blocking, comparator) with ExecutableMailbox { + def dispatcher = self + }*/ } } \ No newline at end of file diff --git a/akka-actor/src/main/scala/akka/dispatch/MailboxHandling.scala b/akka-actor/src/main/scala/akka/dispatch/MailboxHandling.scala index 8a6bbea316..9e40dbfa68 100644 --- a/akka-actor/src/main/scala/akka/dispatch/MailboxHandling.scala +++ b/akka-actor/src/main/scala/akka/dispatch/MailboxHandling.scala @@ -81,6 +81,8 @@ class UnboundedPriorityMessageQueue(val blockDequeue: Boolean, cmp: Comparator[M PriorityBlockingQueue[MessageInvocation](11, cmp) with UnboundedMessageQueueSemantics -class BoundedPriorityMessageQueue(capacity: Int, val pushTimeOut: Duration, val blockDequeue: Boolean, cmp: Comparator[MessageInvocation]) extends +/* PriorityBlockingQueue cannot be bounded + class BoundedPriorityMessageQueue(capacity: Int, val pushTimeOut: Duration, val blockDequeue: Boolean, cmp: Comparator[MessageInvocation]) extends PriorityBlockingQueue[MessageInvocation](capacity, cmp) with - BoundedMessageQueueSemantics \ No newline at end of file + BoundedMessageQueueSemantics + */ \ No newline at end of file