Я пытаюсь понять, как использовать Актеры в Play Framework 2.5. Я в основном добавил пример для сайта, но у меня проблемы с моим конструктором. Я уверен, что это базовая c ошибка, связанная с неправильным указанием чего-либо, но я этого не вижу. Я чувствую, что это с publi c StreamingControl (система ActorSystem), но это то, что в примере.
В моем build.sbt:
routesGenerator := InjectedRoutesGenerator
Мои маршруты:
GET /streaming/controlRoom/:id controllers.StreamingControl.controlRoom(id: Long)
POST /streaming/controlRoom/:id/changeScene controllers.StreamingControl.changeScene(id: Long)
Тогда мой класс контроллера:
package controllers;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import exceptions.StreamingException;
import logic.Logger;
import models.StreamingEvent;
import models.UserTask;
import play.mvc.Controller;
import play.mvc.Result;
import scala.compat.java8.FutureConverters;
import streamingControl.StreamingEventControlActor;
import streamingControl.StreamingEventControlProtocol;
import javax.inject.Inject;
import javax.inject.Singleton;
import static akka.pattern.Patterns.ask;
@Singleton
@Check(UserTask.BASIC)
public class StreamingControl extends Controller {
final ActorRef controllerRef;
@Inject
public StreamingControl(ActorSystem system) {
controllerRef = system.actorOf(StreamingEventControlActor.props);
}
@Check(UserTask.BASIC)
public Result controlRoom(Long id){
StreamingEvent item = StreamingEvent.findById(id);
if(item == null) return notFound();
return ok(views.html.streaming.controlRoomView.render(item));
}
@Check(UserTask.BASIC)
public Result changeScene(Long id) {
StreamingEvent item = StreamingEvent.findById(id);
try {
return FutureConverters.toJava(ask(controllerRef, new StreamingEventControlProtocol.StreamingEventControl("test"), 1000))
.thenApply(response -> ok((String) response)).toCompletableFuture().get();
} catch (StreamingException e) {
Logger.warn("Problem: " + e.getMessage(), e);
return ok("Problem: " + e.getMessage() + " (" + e.getStatus() + ")");
} catch (Exception e) {
Logger.warn("Problem: " + e.getMessage(), e);
return ok("Problem: " + e.getMessage());
}
}
}
Ошибка :
ProvisionException: Unable to provision, see the following errors:
1) Error injecting constructor, java.lang.ExceptionInInitializerError
at controllers.StreamingControl.<init>(StreamingControl.java:27)
at controllers.StreamingControl.class(StreamingControl.java:27)
while locating controllers.StreamingControl
for parameter 8 at router.Routes.<init>(Routes.scala:92)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:200)
while locating play.api.http.JavaCompatibleHttpRequestHandler
while locating play.api.http.HttpRequestHandler
for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221)
at play.api.DefaultApplication.class(Application.scala:221)
while locating play.api.DefaultApplication
while locating play.api.Application
1 error
No source available, here is the exception stack trace:
com.google.inject.ProvisionException: Unable to provision, see the following errors:
1) Error injecting constructor, java.lang.ExceptionInInitializerError
at controllers.StreamingControl.<init>(StreamingControl.java:27)
at controllers.StreamingControl.class(StreamingControl.java:27)
while locating controllers.StreamingControl
for parameter 8 at router.Routes.<init>(Routes.scala:92)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:200)
while locating play.api.http.JavaCompatibleHttpRequestHandler
while locating play.api.http.HttpRequestHandler
for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221)
at play.api.DefaultApplication.class(Application.scala:221)
while locating play.api.DefaultApplication
while locating play.api.Application
1 error
com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025)
com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:405)
play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:400)
play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:158)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:155)
play.utils.Threads$.withContextClassLoader(Threads.scala:21)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:155)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:126)
scala.Option.map(Option.scala:146)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:126)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:124)
scala.util.Success.flatMap(Try.scala:231)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:124)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:116)
scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)