// code in controller
LegacyWebSocket tt = WebSocket.withActor(ChatNode::props);
// ...
// chatnode actor code
public class ChatNode extends UntypedActor {
public static Props props(ActorRef out) {
return Props.create(ChatNode.class, out);
}
private final ActorRef out;
private String username;
public ChatNode(ActorRef out, String username) {
this.out = out;
this.username = username;
}
这是使用actor处理websockets的默认方式(根据Play文档)。我的问题是: 如何将参数传递给绑定到套接字的新创建的actor,即我想从控制器发送一些信息作为参数发送到ChatNode的构造函数?
答案 0 :(得分:0)
你可以使用lambda,这是一个简单的例子:
public LegacyWebSocket<String> socket(String token) {
return WebSocket.withActor(actorRef -> WSActor.props(actorRef,token));
}