Reformat with scalariform

This commit is contained in:
Peter Vlugter 2011-07-26 18:33:59 +12:00
parent 6f2fcc91ed
commit 340ed11de5
75 changed files with 985 additions and 1012 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}
import akka.actor.{ Channel, Actor, PoisonPill }
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
@ -105,10 +105,10 @@ object Pi extends App {
//send calculate message
master.?(Calculate, Actor.Timeout(60000)).
await.resultOrException match {//wait for the result, with a 60 seconds timeout
case Some(pi) =>
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.")
}
}