I have Ator
that would be Root
and this actor Root
has a router with 5 instances, and that same router also has a router with 5 instances. How can I stop ArquivoParaProcessar
and tell Root
that all instances of arquivoRouter
have stopped?
class Root extends Actor {
val arquivoRouter = context.actorOf(Props(new ArquivoParaProcessar(agregadorDeLinha)).withRouter(RoundRobinRouter(nrOfInstances = 5)))
override def receive: Actor.Receive = {
case "init" => {
context.watch(arquivoRouter)
arquivoRouter ! new Servidor(Servidor1)
arquivoRouter ! new Servidor(Servidor2)
arquivoRouter ! new Servidor(Servidor3)
arquivoRouter ! new Servidor(Servidor4)
}
case Terminated(corpse) => {
context.system.shutdown()
}
}
}
class ArquivoParaProcessar(agregadorDeLinha: ActorRef) extends Actor {
val linhaRouter = context.actorOf(Props(new LinhaActor(agregadorDeLinha)).withRouter(RoundRobinRouter(nrOfInstances = 5)))
context.watch(linhaRouter)
override def receive = {
case Servidor(caminho) => {
for {
arquivo <- new File(caminho).listFiles()
if (arquivo.isFile)
linha <- Source.fromFile(arquivo).getLines()
} yield linhaRouter ! new LinhaParaProcessar(linha)
linhaRouter ! PoisonPill
}
case Terminated(corpse) => {
println("terminou")
context stop self
}
}
class LinhaActor(agregadorLinha: ActorRef) extends Actor
//mais código