【发布时间】:2016-08-16 06:35:06
【问题描述】:
我正在尝试关注JavaWebSocket Tutorial on the official docs。
有这个演员:
import akka.actor.*;
public class MyWebSocketActor extends UntypedActor {
public static Props props(ActorRef out) {
return Props.create(MyWebSocketActor.class, out);
}
private final ActorRef out;
public MyWebSocketActor(ActorRef out) {
this.out = out;
}
public void onReceive(Object message) throws Exception {
if (message instanceof String) {
out.tell("I received your message: " + message, self());
}
}
}
这是网络套接字:
public static LegacyWebSocket<String> socket() {
return WebSocket.withActor(MyWebSocketActor::props);
}
这是我的控制器:
@Singleton
public class MessagesController extends BaseController implements CurrentUser {
private UserProvider userProvider;
private ActorSystem actorSystem;
private Materializer materializer;
private Configuration configuration;
ActorRef websocketactor;
@Inject
public MessagesController(final UserProvider userProvider,
ActorSystem actorSystem,
Materializer materializer,
Configuration configuration
) {
this.userProvider = userProvider;
this.actorSystem = actorSystem;
this.materializer = materializer;
this.configuration = configuration;
this.websocketactor = actorSystem.actorOf(); // What goes in here ?
}
在初始化过程之后,我想从控制器方法向actor发送消息。
this.websocketactor = actorSystem.actorOf(MyWebSocketActor.props()); // this line is giving me errors because I don't know what goes in there.
可能是 ActorRef out,这是我的 websocket,但我该如何指定呢?
【问题讨论】:
-
你用的是哪个播放版本?
标签: java playframework akka