[英]Find Actor Status Akka Scala
目前,我有rest-endpoint-api-playframework,其中包含主要角色,以运行n个进行批量插入的辅助角色。 而在此过程中,我很乐意获取当前的插入过程,比如说100/1000。 为了做到这一点,很明显,我将让参与者向发件人报告流程的状态。
class Application (implicit inj : Injector) extends Controller with Injectable {
implicit val timeout = Timeout(5 seconds)
val mainActor = system.actorOf(RoundRobinPool(100).props(Props(new SupervisorActor(0))), name = "helloactor")
val future = mainActor ? ProcessBatch
val workerFuture = mainActor ? CurrentProcessedItem
result = Await.result(workerFuture, timeout.duration).asInstanceOf[String]
Ok(Json.obj("return"->result.toString))
}
以上,我希望是helloActor ? ProcessBatch
helloActor ? ProcessBatch
已完成,然后我将返回过程已完成,否则我将运行mainActor ? CurrentProcessedItem
mainActor ? CurrentProcessedItem
,它返回currentProcessedItem
的未来。
所以基本上我将需要指标mainActor ? ProcessBatch
mainActor ? ProcessBatch
是否已完成。 可能吗?
“询问”返回您是Future
。 因此, onComplete
您可以做任何您想做的事情:
val future = helloActor ? ProcessBatch
future.onComplete {
case Success(result) => // Do stuff
}
但是,我宁愿运行helloActor ? ProcessBatch
mainActor
helloActor ? ProcessBatch
并将结果“管道”到mainActor
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.