question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AkkaGuiceSupport missing type info for custom mailboxes

See original GitHub issue

Play Version (2.5.x / etc)

Play 2.5.12 Scala 2.11.8

API (Scala / Java / Neither / Both)

Doesn’t work on Java, works on Scala

Operating System

Darwin akllap010-4.local 16.3.0 Darwin Kernel Version 16.3.0: Thu Nov 17 20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

java version “1.8.0_45” Java™ SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot™ 64-Bit Server VM (build 25.45-b02, mixed mode)

Library Dependencies

Play 2.5.12 Akka 2.4.16

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

  1. Define persistent actor with factory public class MyActor extends AbstractPersistentActor { ... }
  2. Bind it in factory bindActorFactory[MyActor, MyActor.Factory] in your java or scala module
  3. Use the factory in some actor
public class ParentActor extends UntypedActor implements InjectedActorSupport {
    @Inject
    public ParentActor(final MyActor.Factory factory) {
    injectedChild(factory::create, "child");
   }
  1. Bind parent in Guice module (therefore instantiating it as early singleton) bindActor[ParentActor]("parent")

  2. Start

Actual Behavior

  1. exception on startup:
Caused by: akka.actor.ActorInitializationException: akka://application/user/parent/child: 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"
  }

NOT working JAVA example


import akka.actor.Actor;
import akka.persistence.AbstractPersistentActor;
import scala.PartialFunction;
import scala.runtime.BoxedUnit;

public class ChildPersistent extends AbstractPersistentActor {

    public interface Factory {
        Actor create();
    }

    @Override
    public String persistenceId() {
        return null;
    }

    @Override
    public PartialFunction<Object, BoxedUnit> receiveRecover() {
        return null;
    }

    @Override
    public PartialFunction<Object, BoxedUnit> receiveCommand() {
        return null;
    }

}

import akka.actor.Actor;
import akka.actor.UntypedActor;

public class ChildNonPersistent extends UntypedActor {
    public interface Factory {
        Actor create();
    }

    @Override
    public void onReceive(Object message) throws Throwable {

    }
}

public class Parent extends UntypedActor implements InjectedActorSupport {

    @Inject
    public Parent(ChildPersistent.Factory factoryPersistent,
                  ChildNonPersistent.Factory factoryNonPersistent) {
        injectedChild(factoryNonPersistent::create, "child-non-persistent"); // works
        injectedChild(factoryPersistent::create, "child-persistent"); // doesn't work
    }

    @Override
    public void onReceive(Object message) throws Throwable {
    }
}
class AkkaModule extends AbstractModule with AkkaGuiceSupport {
  override def configure(): Unit = {
    bindActorFactory[ChildPersistent, ChildPersistent.Factory]
    bindActorFactory[ChildNonPersistent, ChildNonPersistent.Factory] 
    bindActor[Parent]("parent")
  }

Working SCALA example

class ChildPersistent extends PersistentActor {
  override def receiveRecover: Receive = ???
  override def receiveCommand: Receive = ???
  override def persistenceId: String = ???
}

object ChildPersistent {
  trait Factory {
    def create(): Actor
  }
}

class ChildNonPersistent extends Actor {
  override def receive: Receive = ???
}

object ChildNonPersistent {
  trait Factory {
    def create(): Actor
  }
}


class Parent @Inject() (factoryPersistent: ChildPersistent.Factory,
                        factoryNonPersistent: ChildNonPersistent.Factory) extends Actor with InjectedActorSupport{

  injectedChild(factoryNonPersistent.create(), "child-non-persistent") // works
  injectedChild(factoryPersistent.create(), "child-persistent") // works

  override def receive: Receive = ???
}

class AkkaModule extends AbstractModule with AkkaGuiceSupport {
  override def configure(): Unit = {
    bindActorFactory[ChildPersistent, ChildPersistent.Factory]
    bindActorFactory[ChildNonPersistent, ChildNonPersistent.Factory]
    bindActor[Parent]("parent")
  }
}

Possibly related

https://groups.google.com/forum/#!topic/akka-user/IM9MmwP9Uas https://groups.google.com/forum/#!topic/akka-user/GlMqBJeWP0s

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
haglcommented, May 8, 2017

You can define a mailbox type in application.conf:

deque-mailbox { mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox" }

and then explicitly specify it when creating the Actor:

injectedChild(factoryPersistent.create(), "child-persistent", p => p.withMailbox("deque-mailbox"))

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mailboxes - Documentation - Akka
Custom Mailbox type ​​ The best way to show how to create your own Mailbox type is by example: Scala. copy source //...
Read more >
Understanding Play features with DI support | by Rahul Kumar
To use DI with actor we would implement `AkkaGuiceSupport` which provides us the wand of bindActor which binds an actor class with a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found