Misc improvements of ActorRoutedRef. Implemented a scatterer gatherer router. Enabled router related tests. See #1440.

This commit is contained in:
Henrik Engstrom 2011-12-12 15:06:40 +01:00
parent a7886abdf0
commit 192f84df71
9 changed files with 203 additions and 308 deletions

View file

@ -6,13 +6,12 @@ package akka.tutorial.first.java;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.InternalActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.actor.UntypedActorFactory;
import akka.japi.Creator;
import akka.routing.*;
import akka.routing.RoundRobinRouter;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
public class Pi {
@ -105,23 +104,8 @@ public class Pi {
this.nrOfMessages = nrOfMessages;
this.nrOfElements = nrOfElements;
this.latch = latch;
Creator<Router> routerCreator = new Creator<Router>() {
public Router create() {
// TODO (HE) : implement
//return new RoundRobinRouter(getContext().dispatcher(), new akka.actor.Timeout(-1));
return null;
}
};
LinkedList<ActorRef> actors = new LinkedList<ActorRef>() {
{
for (int i = 0; i < nrOfWorkers; i++) add(getContext().actorOf(Worker.class));
}
};
// FIXME routers are intended to be used like this
// TODO (HE): implement
//RoutedProps props = new RoutedProps(routerCreator, new LocalConnectionManager(actors), new akka.actor.Timeout(-1), true);
//router = new RoutedActorRef(getContext().system(), props, (InternalActorRef) getSelf(), "pi");
router = this.getContext().actorOf(new Props().withCreator(Worker.class).withRouting(new RoundRobinRouter(5)), "pi");
}
// message handler
@ -170,7 +154,7 @@ public class Pi {
final CountDownLatch latch = new CountDownLatch(1);
// create the master
ActorRef master = system.actorOf(new UntypedActorFactory() {
ActorRef master = system.actorOf(new akka.actor.UntypedActorFactory() {
public UntypedActor create() {
return new Master(nrOfWorkers, nrOfMessages, nrOfElements, latch);
}

View file

@ -53,12 +53,8 @@ object Pi extends App {
var nrOfResults: Int = _
var start: Long = _
// create the workers
val workers = Vector.fill(nrOfWorkers)(context.actorOf[Worker])
// create a round robin router for the workers
val router = context.actorOf(Props(new Worker).withRouting(RoundRobinRouter(nrOfInstances = 5)), "pi")
//val router = context.actorOf(Props(new Worker).withRouting(RoundRobinRouter(nrOfInstances = 3, targets = Seq(workers.head, workers.tail.head))), "pi")
// message handler
def receive = {
@ -91,7 +87,7 @@ object Pi extends App {
// ===== Run it =====
// ==================
def calculate(nrOfWorkers: Int, nrOfElements: Int, nrOfMessages: Int) {
val system = ActorSystem("PiSystem", ConfigFactory.load("akka.conf"))
val system = ActorSystem()
// this latch is only plumbing to know when the calculation is completed
val latch = new CountDownLatch(1)