AkkaGuiceSupport missing type info for custom mailboxes
See original GitHub issuePlay 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.
- Define persistent actor with factory
public class MyActor extends AbstractPersistentActor { ... }
- Bind it in factory
bindActorFactory[MyActor, MyActor.Factory]
in your java or scala module - Use the factory in some actor
public class ParentActor extends UntypedActor implements InjectedActorSupport {
@Inject
public ParentActor(final MyActor.Factory factory) {
injectedChild(factory::create, "child");
}
-
Bind parent in Guice module (therefore instantiating it as early singleton)
bindActor[ParentActor]("parent")
-
Start
Actual Behavior
- 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:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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"))
Something similar defined as http://www.pmatiello.me/2015/07/injecting-akka-routers-as-dependencies-in-a-play-application.html