Misc additions to, and rewrites and formatting of, the documentation.

Signed-off-by: Jonas Bonér <jonas@jonasboner.com>
This commit is contained in:
Jonas Bonér 2011-12-15 14:26:17 +01:00
parent b0e630a239
commit ce296b0481
29 changed files with 270 additions and 223 deletions

View file

@ -79,12 +79,11 @@ public class Pi {
public void onReceive(Object message) {
if (message instanceof Work) {
Work work = (Work) message;
double result = calculatePiFor(work.getStart(), work.getNrOfElements());
getSender().tell(new Result(result));
} else throw new IllegalArgumentException("Unknown message [" + message + "]");
} else {
throw new IllegalArgumentException("Unknown message [" + message + "]");
}
}
}
//#worker
@ -108,9 +107,9 @@ public class Pi {
this.latch = latch;
//#create-router
router = this.getContext().actorOf(new Props().withCreator(
Worker.class).withRouter(new RoundRobinRouter(nrOfWorkers)),
"pi");
router = this.getContext().actorOf(
new Props(Worker.class).withRouter(new RoundRobinRouter(nrOfWorkers)),
"pi");
//#create-router
}
@ -139,8 +138,8 @@ public class Pi {
@Override
public void postStop() {
System.out.println(String.format(
"\n\tPi estimate: \t\t%s\n\tCalculation time: \t%s millis",
pi, (System.currentTimeMillis() - start)));
"\n\tPi estimate: \t\t%s\n\tCalculation time: \t%s millis",
pi, (System.currentTimeMillis() - start)));
latch.countDown();
}
}

View file

@ -42,7 +42,8 @@ object Pi extends App {
//#worker
//#master
class Master(nrOfWorkers: Int, nrOfMessages: Int, nrOfElements: Int, latch: CountDownLatch)
class Master(
nrOfWorkers: Int, nrOfMessages: Int, nrOfElements: Int, latch: CountDownLatch)
extends Actor {
var pi: Double = _
@ -50,7 +51,8 @@ object Pi extends App {
var start: Long = _
//#create-router
val router = context.actorOf(Props[Worker].withRouter(RoundRobinRouter(nrOfWorkers)), "pi")
val router = context.actorOf(
Props[Worker].withRouter(RoundRobinRouter(nrOfWorkers)), "pi")
//#create-router
//#master-receive
@ -72,9 +74,8 @@ object Pi extends App {
}
override def postStop() {
println(
"\n\tPi estimate: \t\t%s\n\tCalculation time: \t%s millis"
.format(pi, (System.currentTimeMillis - start)))
println("\n\tPi estimate: \t\t%s\n\tCalculation time: \t%s millis"
.format(pi, (System.currentTimeMillis - start)))
latch.countDown()
}
}