我有一个反复出现的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")
}
}
现在我想在有人查看/页面时访问actor的数据,所以我在控制器中执行此操作:
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]
任何有关刚刚发生的事情以及我应该如何修复它的指示都会受到欢迎。
答案 0 :(得分:2)
阿卡让你免受演员的伤害。您总是在处理地址(ActorRef
s)。因此,ActorRef
后面的 应该具有接受消息的逻辑(如case object GetQuotes
)和逻辑以发回您的引号列表(List[Quote]
)以及
另请查看文档的this part。