Created
February 8, 2013 12:44
-
-
Save prassee/4738839 to your computer and use it in GitHub Desktop.
MyFirst Akka Actor written in Scala
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._ | |
import akka.pattern.ask | |
import akka.util.duration._ | |
import akka.util.Timeout | |
import akka.dispatch.Await | |
case class PlayerAddRequest(name: String) | |
class PlayerBuffer extends Actor { | |
var players = Set.empty[String] | |
def receive = { | |
case PlayerAddRequest(name) => { | |
if (players.size < 6) { | |
println("added " + name) | |
players = players.+(name) | |
println(players.size) | |
} else { | |
println("max players added") | |
System.exit(1) | |
} | |
} | |
} | |
} | |
object FirstAkkaRun extends App { | |
val as = ActorSystem("PlayerAddSystem") | |
val playerBuff = as.actorOf(Props[PlayerBuffer], "playert") | |
implicit val timeout = Timeout(5 minutes) | |
val future = playerBuff ? PlayerAddRequest("pras") | |
println(Await.result(future, timeout.duration).asInstanceOf[String]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment