0

我正在使用ScatterGatherFirstCompletedRouter它返回第一个完成的演员的答案。这工作正常,但其他一些演员超时。即使我赶上了超时,这仍然是浪费时间和资源。我可以向Kill演员发送 a ,但这会发出不同的消息,并且仍然没有对时间做任何事情(出于某种原因)。处理这个问题的最佳方法是什么?

4

1 回答 1

0

与其让他们的直系子女完成工作,不如让ScatterGatherFirstCompletedRouter他们委托给另一个演员。请务必跟踪原始请求者,以便其他参与者可以向其发送响应。

也许它可以更清洁,但这是我得到的(ValidBoardActor与 一起使用的地方ScatterGatherFirstCompletedRouter):

class ValidBoardActor extends Actor {
  private implicit val timeout = Timeout(12.seconds)

  private lazy val generateBoardActor = context.actorFor(s"/user/${GenerateBoardActor.name}")

  private def stopProcessing: Receive = {
    case _ =>
  }

  private def processBoards(requester: ActorRef, piecesConfigSpec: Configuration.PiecesConfigSpec*): Receive = {
    case board: Board => {
      if (board.check) {
        requester ! board

        context.become(stopProcessing)
      } else {
        self ! GenerateBoard(piecesConfigSpec: _*)

        context.become(processRequests(requester))
      }
    }
  }

  private def processRequests(requester: ActorRef): Receive = {
    case GenerateBoard(configuration @ _*) => {
      generateBoardActor ! GenerateBoard(configuration: _*)

      context.become(processBoards(requester, configuration: _*))
    }
  }

  def receive = {
    case message => {
      self forward message

      context.become(processRequests(sender))
    }
  }
}
于 2013-07-17T14:24:34.173 回答