我使用这样的代码:
用户角色首先在代码中的某处创建,如下所示:
TypedActor.get(actorSystem).typedActorOf(new TypedProps<UserActor>(IUserActor.class, new Creator<UserActor>() {
@Override
public UserActor create() throws Exception {
return new UserActor(userId);
}
}), userId);
之后,我试图获取它的一个实例(就像 UntypedActors 的 actorFor 一样):
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);
但是一旦我在 userActor 上调用一个方法,我就会得到
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)
...
我究竟做错了什么?谢谢