Created
October 18, 2016 18:53
-
-
Save akkida746/536345cba65d1feab1f9c262c07b5b7f to your computer and use it in GitHub Desktop.
Scala Actor Demo
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.Actor | |
import akka.event.Logging | |
import akka.actor.{Props, ActorSystem} | |
object ActorDemo { | |
def main(args: Array[String]): Unit = { | |
val system = ActorSystem("drinks-system") | |
val props = Props[DrinkActor] | |
val drinkActor = system.actorOf(props, "drinkActor-1") | |
drinkActor ! "tea" | |
drinkActor ! "coffee" | |
drinkActor ! "water" | |
system.terminate() | |
} | |
} | |
class DrinkActor extends Actor { | |
val log = Logging(context.system, this) | |
def receive = { | |
case "tea" => log.info("Tea time!") | |
case "coffee" => log.info("Coffee time!") | |
case _ => log.info("Hmmm...") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment