Hi... i am newes in akk and scala and i can not find answer for my
problem.
How i can terminate akka actor in this examplу ?
import akka.actor.{Actor, ActorSystem, PoisonPill, Props, ActorLogging }
import scala.concurrent.{Await, Future}
import scala.util._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import akka.actor._
import org.jsoup.Jsoup
case class Scrap(url:String)
class Scrapper extends Actor with ActorLogging {
def getDoc(url:String):org.jsoup.nodes.Document={
val user_agent:String ="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0)
Gecko/20100101 Firefox/40.1"
val response =
Jsoup.connect(url).timeout(3000).ignoreContentType(true).userAgent(user_agent).execute()
val contentType: String = response.contentType
val doc = response.parse()
doc
}
override def postStop() = {
context.system.terminate
}
def receive = {
case Scrap(url)=>
println(s"scraping $url")
val content = Future{ getDoc(url) }
content onComplete {
case Success(content) =>
println(content.title)
//context.system.terminate()
case Failure(content) =>
println("some error")
context.system.terminate()
}
}
}
object main extends App{
val system = ActorSystem()
val supervisor = system.actorOf(Props(new Scrapper ))
for(i<-0 to 50 ) {
supervisor ! Scrap("http://football.ua")
}
Await.result(system.whenTerminated, Duration.Inf)
supervisor ! PoisonPill
system.terminate
}
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.