Failed to construct a PriorityMailbox

179 views
Skip to first unread message

Bernd Johannes

unread,
Feb 18, 2012, 1:28:34 PM2/18/12
to akka...@googlegroups.com

Hello hAKKers,


trying to initialize a PriorityMailbox (like described in the docs) I could not get over a:


Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate MailboxType [de.bjos.mp3set.PlayerTest$PrioMailbox$1], defined in [guibridge], make sure it has constructor with a [com.typesafe.config.Config] parameter

at akka.dispatch.MessageDispatcherConfigurator.mailboxType(AbstractDispatcher.scala:375)


My naive analysis showed me that MessageDispatcherConfigurator tries to find in mailboxType() a constructor of the form:


val args = Seq(classOf[Config] -> config)


but the constructor of my custom mailbox has the constructor:


class PrioMailbox(config: com.typesafe.config.Config) extends UnboundedPriorityMailbox(generator)


which results in the signature:

de.bjos.mp3set.PlayerTest$PrioMailbox$1(com.typesafe.config.Config,akka.dispatch.PriorityGenerator)

because of the initialization parameter of the extended class.


So it is not found/accepted by the mailboxType construction code above.


I could only overcome this by "injecting" another "UnboundedPriorityMailbox2" into the akka.dispatch package which has the generator hard coded inside so that it doesn't need initialization parameter.


In the form

class PrioMailbox(config: com.typesafe.config.Config) extends UnboundedPriorityMailbox2

everything works as expected. But this solution is clearly a dirty hack to get things to work.


As I am very new to akka I don't know if I did something wrong, or if there's something amiss with the prioritymailbox.


Any suggestions?


Another remark:


case class UnboundedPriorityMailbox( final val cmp: Comparator[Envelope]) extends MailboxType


is the base of the own custom priority mailboxes. But it's a case class in itself. Isn't it deprecated in scala to extend case classes?


Greetings

Bernd


√iktor Ҡlang

unread,
Feb 18, 2012, 2:17:04 PM2/18/12
to akka...@googlegroups.com
Hi Bernd,

you shouldn't use inheritance to extend the MailboxTypes, just create your own and implement the create method.

This is the code for the unbounded priority one:

case class UnboundedPriorityMailbox( final val cmp: Comparator[Envelope]) extends MailboxType {
  final override def create(receiver: ActorContext): Mailbox =
    new Mailbox(receiver.asInstanceOf[ActorCell]) with QueueBasedMessageQueue with UnboundedMessageQueueSemantics with DefaultSystemMessageQueue {
      final val queue = new PriorityBlockingQueue[Envelope](11, cmp)
    }
}

Cheers,

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

Bernd Johannes

unread,
Feb 18, 2012, 4:37:03 PM2/18/12
to akka...@googlegroups.com, √iktor Ҡlang

Am Samstag, 18. Februar 2012, 20:17:04 schrieb √iktor Ҡlang:

> Hi Bernd,

>

> you shouldn't use inheritance to extend the MailboxTypes, just create your

> own and implement the create method.

>

> This is the code for the unbounded priority one:

>

> case class UnboundedPriorityMailbox( final val cmp: Comparator[Envelope])

> extends MailboxType {

> final override def create(receiver: ActorContext): Mailbox =

> new Mailbox(receiver.asInstanceOf[ActorCell]) with

> QueueBasedMessageQueue with UnboundedMessageQueueSemantics with

> DefaultSystemMessageQueue {

> final val queue = new PriorityBlockingQueue[Envelope](11, cmp)

> }

> }

>

> Cheers,

> √


Hi Victor, thanks for the advise.

But then I think the documentation is misleading because it exactly does this:


from akka 2.0 doku:

-----------------------

import akka.dispatch.PriorityGenerator

import akka.dispatch.UnboundedPriorityMailbox
import com.typesafe.config.Config

val generator = PriorityGenerator { // Create a new PriorityGenerator, lower prio means more important
  case 'highpriority ⇒ 0 // 'highpriority messages should be treated first if possible
  case 'lowpriority  ⇒ 100 // 'lowpriority messages should be treated last if possible
  case PoisonPill    ⇒ 1000 // PoisonPill when no other left
  case otherwise     ⇒ 50 // We default to 50
}

// We create a new Priority dispatcher and seed it with the priority generator
class PrioMailbox(config: Config) extends UnboundedPriorityMailbox(generator)
---------------------------

So I think the documentation should be updated.

Thank you & Greetings

Bernd



>

> On Sat, Feb 18, 2012 at 7:28 PM, Bernd Johannes <bjoh...@bacon.de> wrote:

> > **

√iktor Ҡlang

unread,
Feb 18, 2012, 5:15:16 PM2/18/12
to Bernd Johannes, akka...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages