Skip to content

Instantly share code, notes, and snippets.

@worthlesscog
Created May 13, 2012 19:51
Show Gist options
  • Save worthlesscog/2689928 to your computer and use it in GitHub Desktop.
Save worthlesscog/2689928 to your computer and use it in GitHub Desktop.
Collect the numbered chunks for reassembly
import scala.actors.Actor.self
import scala.actors.remote.RemoteActor.{ register, alive }
import scala.actors.Actor
import scala.collection.immutable.TreeMap
import scala.collection.mutable.Map
object Reducer {
def main(args: Array[String]) {
println("Reducer running")
val actor = new Actor {
def act {
alive(System.getProperty("port").toInt)
register('reducer, self)
var results = System.getProperty("results").toInt
println("Expecting " + results + " result(s)")
var map = TreeMap[Int, String]()
while (results > 0) {
receive {
case m: Map[Int, String] ⇒ println("Received " + m); map ++= m; results -= 1
}
}
println("Results " + map)
}
}
actor.start
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment