4
I have a Ator
that would be the Root
and this actor Root
has a router with 5 instances, and this same router also has a router with 5 instances. How can I stop ArquivoParaProcessar
and warn the Root
that all instances of arquivoRouter
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
Thanks for the help, I’ll try that way and I’ll answer here as it turned out.
– Diego Gusava