我有一个经常性的 Akka 作业,它从我在 Global.scala 中开始的外部 url 读取引号。像这样:
object Global extends GlobalSettings {
override def onStart(app: Application) {
val collector = Akka.system.actorOf(Props[QuoteCollector], "quoteCollector")
Akka.system.scheduler.schedule(0.seconds, 10.seconds, collector, "tick")
}
}
现在我想在有人查看 / 页面时访问演员的数据,所以我在控制器中执行此操作:
def index = Action {
val actor:ActorRef = Akka.system.actorFor("akka://application/user/quoteCollector")
val collector = actor.asInstanceOf[QuoteCollector]
val list: List = collector.quotes
Ok(views.html.index("hi"))
}
这是每次都会发生的事情:
error] application -
! @6e1hjmdbo - Internal server error, for (GET) [/] ->
play.api.Application$$anon$1: Execution exception[[ClassCastException: akka.actor.RepointableActorRef cannot be cast to actors.QuoteCollector]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.1]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$17$$anonfun$apply$24.apply(PlayDefaultUpstreamHandler.scala:326) [play_2.10.jar:2.1.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$17$$anonfun$apply$24.apply(PlayDefaultUpstreamHandler.scala:324) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
java.lang.ClassCastException: akka.actor.RepointableActorRef cannot be cast to actors.QuoteCollector
at controllers.Application$$anonfun$index$1.apply(Application.scala:22) ~[classes/:na]
at controllers.Application$$anonfun$index$1.apply(Application.scala:20) ~[classes/:na]
at play.api.mvc.ActionBuilder$$anonfun$apply$11.apply(Action.scala:254) ~[play_2.10.jar:2.1.1]
at play.api.mvc.ActionBuilder$$anonfun$apply$11.apply(Action.scala:254) ~[play_2.10.jar:2.1.1]
at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:217) ~[play_2.10.jar:2.1.1]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$6.apply(Action.scala:109) ~[play_2.10.jar:2.1.1]
欢迎任何关于刚刚发生的事情以及我应该如何解决它的指示。