Created
October 21, 2013 20:05
-
-
Save juliano/7090046 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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