Merge branch 'master' into wip-derekjw

Conflicts:
	akka-actor-tests/src/test/scala/akka/misc/SchedulerSpec.scala
	akka-actor/src/main/scala/akka/actor/ActorRef.scala
	akka-cluster/src/main/scala/akka/cluster/ClusterActorRef.scala
	akka-tutorials/akka-tutorial-second/src/main/scala/Pi.scala
	project/AkkaBuild.scala
This commit is contained in:
Derek Williams 2011-07-26 13:05:28 -06:00
commit 5b5d3cd892
95 changed files with 1365 additions and 1217 deletions

View file

@ -5,13 +5,13 @@
package akka.tutorial.second
import akka.actor.Actor._
import akka.routing.{Routing, CyclicIterator}
import akka.routing.{ Routing, CyclicIterator }
import Routing._
import akka.event.EventHandler
import akka.actor.{Channel, Actor, PoisonPill, Timeout}
import akka.dispatch.Future
import System.{currentTimeMillis => now}
import System.{ currentTimeMillis now }
object Pi extends App {
@ -30,16 +30,16 @@ object Pi extends App {
// ==================
class Worker() extends Actor {
// define the work
val calculatePiFor = (arg: Int, nrOfElements: Int) => {
val calculatePiFor = (arg: Int, nrOfElements: Int) {
val range = (arg * nrOfElements) to ((arg + 1) * nrOfElements - 1)
var acc = 0.0D
range foreach (i => acc += 4 * math.pow(-1, i) / (2 * i + 1))
range foreach (i acc += 4 * math.pow(-1, i) / (2 * i + 1))
acc
//range map (j => 4 * math.pow(-1, j) / (2 * j + 1)) sum
}
def receive = {
case Work(arg, nrOfElements) =>
case Work(arg, nrOfElements)
self reply Result(calculatePiFor(arg, nrOfElements)) // perform the work
}
}
@ -59,9 +59,9 @@ object Pi extends App {
// phase 1, can accept a Calculate message
def scatter: Receive = {
case Calculate =>
case Calculate
// schedule work
for (arg <- 0 until nrOfMessages) router ! Work(arg, nrOfElements)
for (arg 0 until nrOfMessages) router ! Work(arg, nrOfElements)
//Assume the gathering behavior
this become gather(self.channel)
@ -69,7 +69,7 @@ object Pi extends App {
// phase 2, aggregate the results of the Calculation
def gather(recipient: Channel[Any]): Receive = {
case Result(value) =>
case Result(value)
// handle result from the worker
pi += value
nrOfResults += 1
@ -108,7 +108,7 @@ object Pi extends App {
await.resultOrException match {//wait for the result, with a 60 seconds timeout
case Some(pi) =>
EventHandler.info(this, "\n\tPi estimate: \t\t%s\n\tCalculation time: \t%s millis".format(pi, (now - start)))
case None =>
case None
EventHandler.error(this, "Pi calculation did not complete within the timeout.")
}
}