From 2b4c8b2508f6a85e03fc106da1f76c5a02ed36d8 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Tue, 21 Feb 2012 17:23:54 +0100 Subject: [PATCH] Changing so that PriorityMailboxes can be used --- .../test/scala/akka/dispatch/MailboxConfigSpec.scala | 4 ++-- akka-actor/src/main/scala/akka/dispatch/Mailbox.scala | 10 ++++++++-- .../code/akka/docs/dispatcher/DispatcherDocSpec.scala | 5 +---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/dispatch/MailboxConfigSpec.scala b/akka-actor-tests/src/test/scala/akka/dispatch/MailboxConfigSpec.scala index 21c6c75cb2..f4d355333a 100644 --- a/akka-actor-tests/src/test/scala/akka/dispatch/MailboxConfigSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/dispatch/MailboxConfigSpec.scala @@ -144,8 +144,8 @@ class PriorityMailboxSpec extends MailboxSpec { val comparator = PriorityGenerator(_.##) lazy val name = "The priority mailbox implementation" def factory = { - case UnboundedMailbox() ⇒ UnboundedPriorityMailbox(comparator).create(None) - case BoundedMailbox(capacity, pushTimeOut) ⇒ BoundedPriorityMailbox(comparator, capacity, pushTimeOut).create(None) + case UnboundedMailbox() ⇒ new UnboundedPriorityMailbox(comparator).create(None) + case BoundedMailbox(capacity, pushTimeOut) ⇒ new BoundedPriorityMailbox(comparator, capacity, pushTimeOut).create(None) } } diff --git a/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala b/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala index 3099fe8f01..6ae7f3ddc7 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Mailbox.scala @@ -380,14 +380,20 @@ case class BoundedMailbox( final val capacity: Int, final val pushTimeOut: Durat } } -case class UnboundedPriorityMailbox( final val cmp: Comparator[Envelope]) extends MailboxType { +/** + * Extend me to provide the comparator + */ +class UnboundedPriorityMailbox( final val cmp: Comparator[Envelope]) extends MailboxType { final override def create(owner: Option[ActorContext]): MessageQueue = new QueueBasedMessageQueue with UnboundedMessageQueueSemantics { final val queue = new PriorityBlockingQueue[Envelope](11, cmp) } } -case class BoundedPriorityMailbox( final val cmp: Comparator[Envelope], final val capacity: Int, final val pushTimeOut: Duration) extends MailboxType { +/** + * Extend me to provide the comparator + */ +class BoundedPriorityMailbox( final val cmp: Comparator[Envelope], final val capacity: Int, final val pushTimeOut: Duration) extends MailboxType { if (capacity < 0) throw new IllegalArgumentException("The capacity for BoundedMailbox can not be negative") if (pushTimeOut eq null) throw new IllegalArgumentException("The push time-out for BoundedMailbox can not be null") diff --git a/akka-docs/scala/code/akka/docs/dispatcher/DispatcherDocSpec.scala b/akka-docs/scala/code/akka/docs/dispatcher/DispatcherDocSpec.scala index fe8eb8a270..f26ac791d1 100644 --- a/akka-docs/scala/code/akka/docs/dispatcher/DispatcherDocSpec.scala +++ b/akka-docs/scala/code/akka/docs/dispatcher/DispatcherDocSpec.scala @@ -120,10 +120,7 @@ object DispatcherDocSpec { } // We create a new Priority dispatcher and seed it with the priority generator - class PrioMailbox(config: Config) extends MailboxType { - val priorityMailbox = UnboundedPriorityMailbox(generator) - def create(owner: Option[ActorContext]) = priorityMailbox.create(owner) - } + class PrioMailbox(config: Config) extends UnboundedPriorityMailbox(generator) //#prio-mailbox class MyActor extends Actor {