Last active
August 29, 2015 14:20
-
-
Save DuqueDeTuring/eab13c593cce0f9b6c51 to your computer and use it in GitHub Desktop.
Simple ejemplo de uso de Akka (Scala) basado en código de http://akka.io/
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
| import akka.actor.{Terminated, Props, ActorLogging, Actor, ActorSystem} | |
| case class Greeting(who: String) | |
| case class WAT() | |
| case class HastaLaVista() | |
| class AdiosActor extends Actor with ActorLogging { | |
| def receive = { | |
| case HastaLaVista() ⇒ log.info("Hasta la vista") | |
| } | |
| } | |
| class GreetingActor extends Actor with ActorLogging { | |
| val despedidas = context.actorOf(Props[AdiosActor], name = "despedidas") | |
| context.watch(despedidas) | |
| def receive = { | |
| case Greeting(who) ⇒ log.info("Hello " + who) | |
| case WAT() ⇒ log.info("WAT?") | |
| case HastaLaVista() ⇒ despedidas ! HastaLaVista() | |
| case Terminated(`despedidas`) => log.info("FIN") | |
| } | |
| } | |
| object blah { | |
| def main(args: Array[String]) { | |
| val system = ActorSystem("MySystem") | |
| val greeter = system.actorOf(Props[GreetingActor], name = "greeter") | |
| greeter ! Greeting("Charlie Parker 1") | |
| greeter ! Greeting("Charlie Parker 2") | |
| greeter ! WAT() | |
| greeter ! HastaLaVista() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment