Commit 94adf390 authored by Dominik Charousset's avatar Dominik Charousset

let AkkaSupervisor spawn worker and master

parent 47b6cbc9
...@@ -166,9 +166,7 @@ class AkkaChainLink(next: AkkaActorRef) extends AkkaActor { ...@@ -166,9 +166,7 @@ class AkkaChainLink(next: AkkaActorRef) extends AkkaActor {
} }
} }
class AkkaChainMaster(supervisor: AkkaActorRef, system: ActorSystem) extends AkkaActor { class AkkaChainMaster(supervisor: AkkaActorRef, worker: AkkaActorRef) extends AkkaActor {
val worker = system.actorOf(Props(new AkkaWorker(supervisor)))
@tailrec final def newRing(next: AkkaActorRef, rsize: Int): AkkaActorRef = { @tailrec final def newRing(next: AkkaActorRef, rsize: Int): AkkaActorRef = {
if (rsize == 0) next if (rsize == 0) next
...@@ -213,6 +211,12 @@ class AkkaSupervisor(numMessages: Int) extends AkkaActor { ...@@ -213,6 +211,12 @@ class AkkaSupervisor(numMessages: Int) extends AkkaActor {
def receive = { def receive = {
case Factors(f) => global.checkFactors(f); inc case Factors(f) => global.checkFactors(f); inc
case MasterExited => inc case MasterExited => inc
case Init(numRings, iterations, repetitions) =>
val initMsg = Init(numRings, iterations, repetitions)
for (_ <- 0 until numRings) {
val worker = context.actorOf(Props(new AkkaWorker(self)))
context.actorOf(Props(new AkkaChainMaster(self, worker))) ! initMsg
}
} }
} }
...@@ -232,8 +236,7 @@ class MixedCase(numRings: Int, ringSize: Int, initToken: Int, reps: Int) { ...@@ -232,8 +236,7 @@ class MixedCase(numRings: Int, ringSize: Int, initToken: Int, reps: Int) {
def runAkka() { def runAkka() {
val system = ActorSystem(); val system = ActorSystem();
val s = system.actorOf(Props(new AkkaSupervisor(numMessages))) val s = system.actorOf(Props(new AkkaSupervisor(numMessages)))
for (_ <- 0 until numRings) s ! initMsg
system.actorOf(Props(new AkkaChainMaster(s, system))) ! initMsg
global.latch.await global.latch.await
system.shutdown system.shutdown
System.exit(0) System.exit(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment