Skip to content

Instantly share code, notes, and snippets.

@juliano
Created October 21, 2013 20:05
Show Gist options
  • Save juliano/7090046 to your computer and use it in GitHub Desktop.
Save juliano/7090046 to your computer and use it in GitHub Desktop.
object GoogleService {
sealed trait Mensagem
case class Buscar(url: String) extends Mensagem
case class Resultado(conteudo: String) extends Mensagem
implicit val timeout = Timeout(2 seconds)
class Buscador extends Actor {
def buscar(url: String) = // crawleia a internet
def receive = {
case Buscar(url) => sender ! Resultado(buscar(url))
}
}
class Google(buscadores: Int, urls: List[String]) extends Actor {
val router = context.actorOf(
Props[Buscador].withRouter(RoundRobinRouter(buscadores)), name = "router")
def receive = {
case Buscar =>
urls.foreach(router ! Buscar(_))
case Resultado(conteudo) =>
// exibe na tela
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment