Question

I use the code like this:

User actor is first created somewhere in the code like this:

TypedActor.get(actorSystem).typedActorOf(new TypedProps<UserActor>(IUserActor.class, new Creator<UserActor>() {
        @Override
        public UserActor create() throws Exception {
            return new UserActor(userId);
        }
    }), userId);

After that I'm trying to get an instance of it (just like actorFor for UntypedActors):

ActorRef userActorRef = actorSystem.actorFor("akka://actors/user/" + userId));
UserActor userActor = TypedActor.get(actorSystem).typedActorOf(new TypedProps<UserActor>(UserActor.class), userActorRef);

// exception is here:
userActor.gotRequest(msg);

but once I call a method on userActor I get

java.lang.ClassCastException: $Proxy5 cannot be cast to com.lutshe.akka.actors.UserActor
    at com.lutshe.akka.AkkaMessagesHandler.process(AkkaMessagesHandler.java:47)
    at com.lutshe.tcp.server.TestMessageHandler.messageReceived(TestMessageHandler.java:31)
    at com.lutshe.tcp.server.TestMessageHandler.messageReceived(TestMessageHandler.java:14)
    at io.netty.channel.ChannelInboundMessageHandlerAdapter.inboundBufferUpdated(ChannelInboundMessageHandlerAdapter.java:69)
 ...

What am I doing wrong? Thanks

Was it helpful?

Solution

Akka returns a Proxy of the interface, not the implementation, you should do:

 IUserActor userActor = TypedActor.get(actorSystem).typedActorOf(new TypedProps<IUserActor>(UserActor.class), userActorRef);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top