私はJavaWebSocket Tutorial on the official docsに従おうとしています。コンストラクタパラメータを持つActorをPlayコントローラに挿入するにはどうすればよいですか?
この俳優があります:
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());
}
}
}
これはWebSocketのである:
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 ?
}
その後、initプロセスの後に、私は思いますコントローラーメソッドからアクターにメッセージを送信するのが好きです。
this.websocketactor = actorSystem.actorOf(MyWebSocketActor.props()); // this line is giving me errors because I don't know what goes in there.
それは私のWebSocketである、アウトおそらくActorRefですが、どのように私はそれを指定するのですか?
あなたがありますを使用して? – Salem
私は2.5.xです。Java –