Skip to content

Instantly share code, notes, and snippets.

@tjweir
Created May 8, 2010 21:06
Show Gist options
  • Select an option

  • Save tjweir/394776 to your computer and use it in GitHub Desktop.

Select an option

Save tjweir/394776 to your computer and use it in GitHub Desktop.
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