Skip to content

Instantly share code, notes, and snippets.

@DuqueDeTuring
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save DuqueDeTuring/eab13c593cce0f9b6c51 to your computer and use it in GitHub Desktop.

Select an option

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/
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