Removing PriorityDispatcher since you can now use Dispatcher with UnboundedPriorityMailbox or BoundedProprityMailbox

This commit is contained in:
Viktor Klang 2011-10-04 20:10:04 +02:00
parent 4df9d621bb
commit 815f710e11
4 changed files with 18 additions and 58 deletions

View file

@ -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

View file

@ -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)
}
}

View file

@ -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");

View file

@ -137,10 +137,10 @@ Browse the `ScalaDoc <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 :-)