Reputation: 643
An Akka Scala actor must extend akka.actor.Actor
An Akka Java actor must extend akka.actor.UntypedActor
Therefore, when defining a Scala actor with a non-default constructor and creating it from Java code, I run into this problem:
ActorRef myActor = system.actorOf(new Props(new UntypedActorFactory() {
public UntypedActor create() {
return new MyActor("...");
}
}), "myactor");
Of course, the UntypedActorFactory is expecting to create an object of type UntypedActor, but my actor is of type Actor.
What's the workaround ?
EDIT:
Following instructions from Viktor to use akka.japi.Creator, this works:
Props props1 = new Props();
Props props2 = props1.withCreator(new akka.japi.Creator() {
public Actor create() {
return new MyActor("...");
}
});
ActorRef actorRef = Main.appClient().actorOf(props2, "myactor");
Upvotes: 2
Views: 1370
Reputation: 26597
Pass in an akka.japi.Creator instead of the UntypedActorFactory in this case.
Also, at least in 2.0.1 and forward it doesn't require an UntypedActor:
trait UntypedActorFactory extends Creator[Actor] with Serializable
Upvotes: 7