Skip to content

Instantly share code, notes, and snippets.

@worthlesscog
Created May 13, 2012 19:37
Show Gist options
  • Save worthlesscog/2689887 to your computer and use it in GitHub Desktop.
Save worthlesscog/2689887 to your computer and use it in GitHub Desktop.
Convert numbered 3 digit chunks and stack them for later
import scala.actors.Actor.self
import scala.actors.remote.RemoteActor.{ select, register, alive }
import scala.actors.remote.Node
import scala.actors.Actor
import scala.collection.mutable.Map
import NumberText1.conv
object Mapper {
def main(args: Array[String]) {
println("Mapper running")
val actor = new Actor {
def act {
alive(System.getProperty("port").toInt)
register('mapper, self)
val map = Map[Int, String]()
val reducer = select(Node("localhost", System.getProperty("reducer").toInt), 'reducer)
loop {
receive {
case (k: Int, n: Int) ⇒ println("Received " + n); map += (k -> conv(n))
case "Done" ⇒ println("Sending " + map); reducer ! map; exit
}
}
}
}
actor.start
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment