您好我想实现路由器策略,在某些事件上会向路由器发送消息,但我不知道如何在策略实现中获取对路由器的引用。
这就是我要做的事情:
val router = system.actorOf(RoundRobinPool(5, supervisorStrategy = OneForOneStrategy(){
case _: ActorKilledException => Escalate
case _: ActorInitializationException => Escalate
case _ => self ! SomeMsg(); Restart
}).props(Props(classOf[MyClass])))
self应该是路由器ActorRef
,但在此上下文中无法识别self。
答案 0 :(得分:0)
我通常不会在路由器中创建案例但在
之外 val workerRouter: ActorRef = context.actorOf(
Props[Worker].withRouter(RoundRobinPool(nrOfWorkers)), name = "workerRouter")
val msgRouter: ActorRef = context.actorOf(
Props[Worker].withRouter(RoundRobinPool(nrOfWorkers)), name = "msgRouter")
然后在我的演员接收函数
def receive: PartialFunction[Any, Unit] = {
case RunWorkersMsg =>
workerRouter ! WorkMsg(i , numberOfElements)
case ResultMsg(value) =>
msgRouter ! WorkMsg()
}
在这里,您可以通过示例https://github.com/politrons/Akka
查看我的Akka项目