Merge branch 'master' of github.com:jboner/akka

This commit is contained in:
Jonas Bonér 2011-12-15 08:48:01 +01:00
commit f59b4c642f
43 changed files with 985 additions and 1584 deletions

View file

@ -101,13 +101,16 @@ public class Pi {
private ActorRef router;
public Master(final int nrOfWorkers, int nrOfMessages, int nrOfElements, CountDownLatch latch) {
public Master(final int nrOfWorkers, int nrOfMessages,
int nrOfElements, CountDownLatch latch) {
this.nrOfMessages = nrOfMessages;
this.nrOfElements = nrOfElements;
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().withCreator(
Worker.class).withRouter(new RoundRobinRouter(nrOfWorkers)),
"pi");
//#create-router
}
@ -144,8 +147,10 @@ public class Pi {
//#master
//#actors-and-messages
public void calculate(final int nrOfWorkers, final int nrOfElements, final int nrOfMessages)
throws Exception {
public void calculate(final int nrOfWorkers,
final int nrOfElements,
final int nrOfMessages)
throws Exception {
// Create an Akka system
final ActorSystem system = ActorSystem.create();

View file

@ -50,7 +50,8 @@ object Pi extends App {
var start: Long = _
//#create-router
val router = context.actorOf(Props(new Worker).withRouter(RoundRobinRouter(nrOfInstances = nrOfWorkers)), "pi")
val router = context.actorOf(Props(new Worker).withRouter(
RoundRobinRouter(nrOfInstances = nrOfWorkers)), "pi")
//#create-router
//#master-receive
@ -89,7 +90,9 @@ object Pi extends App {
val latch = new CountDownLatch(1)
// create the master
val master = system.actorOf(Props(new Master(nrOfWorkers, nrOfMessages, nrOfElements, latch)), "master")
val master = system.actorOf(Props(new Master(
nrOfWorkers, nrOfMessages, nrOfElements, latch)),
"master")
// start the calculation
master ! Calculate