Merge branch 'master' of github.com:jboner/akka
This commit is contained in:
commit
f59b4c642f
43 changed files with 985 additions and 1584 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue