Make MailboxType implementation configurable. See #1484

* Added mailboxType property to dispatcher config
* Changed durable mailboxes to use this
* Updated docs for durable mailboxes
This commit is contained in:
Patrik Nordwall 2011-12-19 20:36:06 +01:00
parent 6e3c2cb682
commit 61813c6635
10 changed files with 183 additions and 119 deletions

View file

@ -10,6 +10,8 @@ import akka.actor.{ ActorCell, ActorRef }
import java.util.concurrent._
import annotation.tailrec
import akka.event.Logging.Error
import com.typesafe.config.Config
import java.lang.reflect.InvocationTargetException
class MessageQueueAppendFailedException(message: String, cause: Throwable = null) extends AkkaException(message, cause)
@ -361,3 +363,31 @@ case class BoundedPriorityMailbox( final val cmp: Comparator[Envelope], final va
}
}
class CustomMailboxType(mailboxFQN: String) extends MailboxType {
def create(receiver: ActorCell): Mailbox = {
val constructorSignature = Array[Class[_]](classOf[ActorCell])
ReflectiveAccess.createInstance[AnyRef](mailboxClass, constructorSignature, Array[AnyRef](receiver)) match {
case Right(instance) instance.asInstanceOf[Mailbox]
case Left(exception)
val cause = exception match {
case i: InvocationTargetException i.getTargetException
case _ exception
}
throw new IllegalArgumentException("Cannot instantiate mailbox [%s] due to: %s".
format(mailboxClass.getName, cause.toString))
}
}
private def mailboxClass: Class[_] = ReflectiveAccess.getClassFor(mailboxFQN, classOf[ActorCell].getClassLoader) match {
case Right(clazz) clazz
case Left(exception)
val cause = exception match {
case i: InvocationTargetException i.getTargetException
case _ exception
}
throw new IllegalArgumentException("Cannot find mailbox class [%s] due to: %s".
format(mailboxFQN, cause.toString))
}
}