diff --git a/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala b/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala index 637d772900..e861411530 100644 --- a/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala @@ -9,22 +9,22 @@ class PriorityDispatcherSpec extends WordSpec with MustMatchers { "A PriorityDispatcher" must { "Order it's messages according to the specified comparator using an unbounded mailbox" in { - testOrdering(UnboundedMailbox()) + testOrdering(UnboundedPriorityMailbox(PriorityGenerator({ + case i: Int ⇒ i //Reverse order + case 'Result ⇒ Int.MaxValue + }: Any ⇒ Int))) } "Order it's messages according to the specified comparator using a bounded mailbox" in { - testOrdering(BoundedMailbox(1000)) + testOrdering(BoundedPriorityMailbox(PriorityGenerator({ + case i: Int ⇒ i //Reverse order + case 'Result ⇒ Int.MaxValue + }: Any ⇒ Int), 1000)) } } def testOrdering(mboxType: MailboxType) { - val dispatcher = new PriorityDispatcher("Test", - PriorityGenerator({ - case i: Int ⇒ i //Reverse order - case 'Result ⇒ Int.MaxValue - }: Any ⇒ Int), - throughput = 1, - mailboxType = mboxType) + val dispatcher = new Dispatcher("Test", throughput = 1, mailboxType = mboxType) val actor = actorOf(Props(new Actor { var acc: List[Int] = Nil diff --git a/akka-actor/src/main/scala/akka/dispatch/Dispatcher.scala b/akka-actor/src/main/scala/akka/dispatch/Dispatcher.scala index 04ee11b1b6..5dfb4095c3 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Dispatcher.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Dispatcher.scala @@ -162,44 +162,4 @@ abstract class PriorityGenerator extends java.util.Comparator[Envelope] { final def compare(thisMessage: Envelope, thatMessage: Envelope): Int = gen(thisMessage.message) - gen(thatMessage.message) -} - -// TODO: should this be deleted, given that any dispatcher can now use UnboundedPriorityMailbox? - -/** - * A version of Dispatcher that gives all actors registered to it a priority mailbox, - * prioritized according to the supplied comparator. - * - * The dispatcher will process the messages with the _lowest_ priority first. - */ -class PriorityDispatcher( - name: String, - val comparator: java.util.Comparator[Envelope], - throughput: Int = Dispatchers.THROUGHPUT, - throughputDeadlineTime: Int = Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, - mailboxType: MailboxType = Dispatchers.MAILBOX_TYPE, - executorServiceFactoryProvider: ExecutorServiceFactoryProvider = ThreadPoolConfig()) extends Dispatcher(name, throughput, throughputDeadlineTime, mailboxType, executorServiceFactoryProvider) { - - def this(name: String, comparator: java.util.Comparator[Envelope], throughput: Int, throughputDeadlineTime: Int, mailboxType: MailboxType) = - this(name, comparator, throughput, throughputDeadlineTime, mailboxType, ThreadPoolConfig()) // Needed for Java API usage - - def this(name: String, comparator: java.util.Comparator[Envelope], throughput: Int, mailboxType: MailboxType) = - this(name, comparator, throughput, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, mailboxType) // Needed for Java API usage - - def this(name: String, comparator: java.util.Comparator[Envelope], throughput: Int) = - this(name, comparator, throughput, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, Dispatchers.MAILBOX_TYPE) // Needed for Java API usage - - def this(name: String, comparator: java.util.Comparator[Envelope], executorServiceFactoryProvider: ExecutorServiceFactoryProvider) = - this(name, comparator, Dispatchers.THROUGHPUT, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, Dispatchers.MAILBOX_TYPE, executorServiceFactoryProvider) - - def this(name: String, comparator: java.util.Comparator[Envelope]) = - this(name, comparator, Dispatchers.THROUGHPUT, Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS, Dispatchers.MAILBOX_TYPE) // Needed for Java API usage - - protected val mailbox = mailboxType match { - case _: UnboundedMailbox ⇒ UnboundedPriorityMailbox(comparator) - case BoundedMailbox(cap, timeout) ⇒ BoundedPriorityMailbox(comparator, cap, timeout) - case other ⇒ throw new IllegalArgumentException("Only handles BoundedMailbox and UnboundedMailbox, but you specified [" + other + "]") - } - - override def createMailbox(actor: ActorCell): Mailbox = mailbox.create(this) -} +} \ No newline at end of file diff --git a/akka-docs/java/dispatchers.rst b/akka-docs/java/dispatchers.rst index e70776840b..d9f32f38c9 100644 --- a/akka-docs/java/dispatchers.rst +++ b/akka-docs/java/dispatchers.rst @@ -140,10 +140,10 @@ Browse the :ref:`scaladoc` or look at the code for all the options available. Priority event-based ^^^^^^^^^^^^^^^^^^^^ -Sometimes it's useful to be able to specify priority order of messages, that is done by using PriorityDispatcher and supply -a java.util.Comparator[MessageInvocation] or use a akka.dispatch.PriorityGenerator (recommended): +Sometimes it's useful to be able to specify priority order of messages, that is done by using Dispatcher and supply either +an UnboundedPriorityMailbox or BoundedPriorityMailbox with a java.util.Comparator[MessageInvocation] or use a akka.dispatch.PriorityGenerator (recommended): -Creating a PriorityDispatcher using PriorityGenerator: +Creating a Dispatcher with a priority mailbox using PriorityGenerator: .. code-block:: java @@ -172,7 +172,7 @@ Creating a PriorityDispatcher using PriorityGenerator: // We create an instance of the actor that will print out the messages it processes ActorRef ref = Actors.actorOf(MyActor.class); // We create a new Priority dispatcher and seed it with the priority generator - ref.setDispatcher(new PriorityDispatcher("foo", gen)); + ref.setDispatcher(new Dispatcher("foo", 5, new UnboundedPriorityMailbox(gen))); ref.getDispatcher().suspend(ref); // Suspending the actor so it doesn't start to treat the messages before we have enqueued all of them :-) ref.tell("lowpriority"); diff --git a/akka-docs/scala/dispatchers.rst b/akka-docs/scala/dispatchers.rst index 4ed8fc1bd1..fa00c746f5 100644 --- a/akka-docs/scala/dispatchers.rst +++ b/akka-docs/scala/dispatchers.rst @@ -137,10 +137,10 @@ Browse the `ScalaDoc `_ or look at the code for all the options availa Priority event-based ^^^^^^^^^^^^^^^^^^^^ -Sometimes it's useful to be able to specify priority order of messages, that is done by using PriorityDispatcher and supply -a java.util.Comparator[MessageInvocation] or use a akka.dispatch.PriorityGenerator (recommended): +Sometimes it's useful to be able to specify priority order of messages, that is done by using Dispatcher and supply +an UnboundedPriorityMailbox or BoundedPriorityMailbox with a java.util.Comparator[MessageInvocation] or use a akka.dispatch.PriorityGenerator (recommended): -Creating a PriorityDispatcher using PriorityGenerator: +Creating a Dispatcher using PriorityGenerator: .. code-block:: scala @@ -158,7 +158,7 @@ Creating a PriorityDispatcher using PriorityGenerator: def receive = { case x => println(x) } - }).withDispatcher(new PriorityDispatcher("foo", gen))) // We create a new Priority dispatcher and seed it with the priority generator + }).withDispatcher(new Dispatcher("foo", 5, UnboundedPriorityMailbox(gen)))) // We create a new Priority dispatcher and seed it with the priority generator a.dispatcher.suspend(a) // Suspending the actor so it doesn't start to treat the messages before we have enqueued all of them :-)