Changing so that PriorityMailboxes can be used

This commit is contained in:
Viktor Klang 2012-02-21 17:23:54 +01:00
parent db5bf9dd75
commit 2b4c8b2508
3 changed files with 11 additions and 8 deletions

View file

@ -144,8 +144,8 @@ class PriorityMailboxSpec extends MailboxSpec {
val comparator = PriorityGenerator(_.##) val comparator = PriorityGenerator(_.##)
lazy val name = "The priority mailbox implementation" lazy val name = "The priority mailbox implementation"
def factory = { def factory = {
case UnboundedMailbox() UnboundedPriorityMailbox(comparator).create(None) case UnboundedMailbox() new UnboundedPriorityMailbox(comparator).create(None)
case BoundedMailbox(capacity, pushTimeOut) BoundedPriorityMailbox(comparator, capacity, pushTimeOut).create(None) case BoundedMailbox(capacity, pushTimeOut) new BoundedPriorityMailbox(comparator, capacity, pushTimeOut).create(None)
} }
} }

View file

@ -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 = final override def create(owner: Option[ActorContext]): MessageQueue =
new QueueBasedMessageQueue with UnboundedMessageQueueSemantics { new QueueBasedMessageQueue with UnboundedMessageQueueSemantics {
final val queue = new PriorityBlockingQueue[Envelope](11, cmp) 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 (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") if (pushTimeOut eq null) throw new IllegalArgumentException("The push time-out for BoundedMailbox can not be null")

View file

@ -120,10 +120,7 @@ object DispatcherDocSpec {
} }
// We create a new Priority dispatcher and seed it with the priority generator // We create a new Priority dispatcher and seed it with the priority generator
class PrioMailbox(config: Config) extends MailboxType { class PrioMailbox(config: Config) extends UnboundedPriorityMailbox(generator)
val priorityMailbox = UnboundedPriorityMailbox(generator)
def create(owner: Option[ActorContext]) = priorityMailbox.create(owner)
}
//#prio-mailbox //#prio-mailbox
class MyActor extends Actor { class MyActor extends Actor {