Created
May 8, 2010 21:06
-
-
Save tjweir/394776 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
| import se.scalablesolutions.akka.actor.Actor._ | |
| import se.scalablesolutions.akka.patterns.Patterns._ | |
| import se.scalablesolutions.akka.patterns.CyclicIterator | |
| //Our message types | |
| case object Ping | |
| case object Pong | |
| //Two actors, one named Pinger and one named Ponger | |
| //The actor(pf) method creates an anonymous actor and starts it | |
| val pinger = actor { case x => println("Pinger: " + x) } | |
| val ponger = actor { case x => println("Ponger: " + x) } | |
| //A load balancer that given a sequence of actors dispatches them accordingly | |
| //a CyclicIterator works in a round-robin-fashion | |
| val d = loadBalancerActor( new CyclicIterator( List(pinger,ponger) ) ) | |
| d ! Pong //Prints "Pinger: Pong" | |
| d ! Pong //Prints "Ponger: Pong" | |
| d ! Ping //Prints "Pinger: Ping" | |
| d ! Ping //Prints "Ponger: Ping" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment