Question

I have an actor that depends on stashing. Stashing requires UnboundedDequeBasedMailbox. Is it possible to use stashing together with Bounded mailbox ?

As Arnaud pointed out, my setup is :

Actor with UnrestrictedStash with RequiresMessageQueue[BoundedDequeBasedMessageQueueSemantics]

and configuration :

akka {

    loggers = ["akka.event.slf4j.Slf4jLogger"]
    loglevel = INFO
    daemonic = on

    actor {
            mailbox {
                bounded-deque-based {
                    mailbox-type = "akka.dispatch.BoundedDequeBasedMailbox"
                    mailbox-capacity = 2000
                    mailbox-push-timeout-time = 5s
                }
                requirements {
                  "akka.dispatch.BoundedDequeBasedMessageQueueSemantics" = akka.actor.mailbox.bounded-deque-based
                }
            }
    }
}

And the error is :

[ERROR] 2013/12/06 14:03:58.268 [r-4] a.a.OneForOneStrategy - DequeBasedMailbox required, got: akka.dispatch.UnboundedMailbox$MessageQueue
An (unbounded) deque-based mailbox can be configured as follows:
  my-custom-mailbox {
    mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox"
  }

akka.actor.ActorInitializationException: exception during creation
    at akka.actor.ActorInitializationException$.apply(Actor.scala:218) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.create(ActorCell.scala:578) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:425) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:447) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:262) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.dispatch.Mailbox.run(Mailbox.scala:218) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) [akka-actor_2.10-2.2.0.jar:2.2.0]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.2.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.2.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.2.jar:na]
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.2.jar:na]
Caused by: akka.actor.ActorInitializationException: DequeBasedMailbox required, got: akka.dispatch.UnboundedMailbox$MessageQueue
An (unbounded) deque-based mailbox can be configured as follows:
  my-custom-mailbox {
    mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox"
  }

    at akka.actor.ActorInitializationException$.apply(Actor.scala:218) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.UnrestrictedStash$class.$init$(Stash.scala:82) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at com.fg.mail.smtp.index.Indexer.<init>(Indexer.scala:38) ~[classes/:na]
    at com.fg.mail.smtp.Supervisor$$anonfun$preStart$1.apply(Supervisor.scala:20) ~[classes/:na]
    at com.fg.mail.smtp.Supervisor$$anonfun$preStart$1.apply(Supervisor.scala:20) ~[classes/:na]
    at akka.actor.CreatorFunctionConsumer.produce(Props.scala:369) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.Props.newActor(Props.scala:323) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.newActor(ActorCell.scala:534) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.create(ActorCell.scala:560) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    ... 9 common frames omitted

If I do Props.withMailbox("bounded-deque-based") then I get

Caused by: akka.ConfigurationException: Mailbox Type [bounded-deque-based] not configured

ANSWER : thanks to Arnaud : The problem was the configuration, bounded-deque-based config block should be at the same level as akka config block. Documentation is totally misleading in this case...

akka {

    loggers = ["akka.event.slf4j.Slf4jLogger"]
    loglevel = INFO
    daemonic = on

    actor {
        mailbox {
            requirements {
                    "akka.dispatch.BoundedDequeBasedMessageQueueSemantics" = akka.actor.mailbox.bounded-deque-based
                  }
        }
    }
}

bounded-deque-based {
    mailbox-type = "akka.dispatch.BoundedDequeBasedMailbox"
    mailbox-capacity = 2000
    mailbox-push-timeout-time = 5s
}
Was it helpful?

Solution

According the official Akka stash doc you can decide to use a Stash trait that does not enforce any mailbox type see UnrestrictedStash.

If you use UnrestrictedStash you can configure manually the proper mailbox as long as it extends the akka.dispatch.DequeBasedMessageQueueSemantics marker trait.

You can manually configure your BoundedMailbox mailbox following the mailboxes doc with something like :

bounded-mailbox {
  mailbox-type = "akka.dispatch.BoundedDequeBasedMailbox"
  mailbox-capacity = 1000
  mailbox-push-timeout-time = 10s
}

akka.actor.mailbox.requirements {
  "akka.dispatch.BoundedDequeBasedMessageQueueSemantics" = bounded-mailbox
}

I did not try it myself but it should work.

Edit : what version of Akka are you using? Looks like the stash trait definition changed with the version 2.2.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top