Akka First Tutorial

Written by  on September 9, 2014

I found this tutorial:
http://doc.akka.io/docs/akka/2.0.2/intro/getting-started-first-java.html
very useful. But Akka 2.0.2 is pretty old at this point. There are only a few changes needed to update it to Akka 2.3.6. The following is a universal diff showing those differences.

--- pi/Pi.java  2014-09-09 12:49:36.988942607 -0700
+++ nbpi/pi/src/pi/Pi.java      2014-09-09 13:49:12.677146112 -0700
@@ -4,9 +4,8 @@
 import akka.actor.ActorSystem;
 import akka.actor.Props;
 import akka.actor.UntypedActor;
-import akka.actor.UntypedActorFactory;
 import akka.routing.RoundRobinRouter;
-import akka.util.Duration;
+import scala.concurrent.duration.Duration;
 import java.util.concurrent.TimeUnit;
 
 public class Pi {
@@ -47,8 +46,6 @@
 
   public static class Worker extends UntypedActor {
      
-    // calculatePiFor ...
-     
     public void onReceive(Object message) {
       if (message instanceof Work) {
         Work work = (Work) message;
@@ -85,14 +82,15 @@
       this.nrOfElements = nrOfElements;
       this.listener = listener;
      
-      workerRouter = this.getContext().actorOf(new Props(Worker.class).withRouter(new RoundRobinRouter(nrOfWorkers)),
+      workerRouter = this.getContext().actorOf(Props.create(Worker.class).withRouter(new RoundRobinRouter(nrOfWorkers)),
                                                "workerRouter");
+      
     }
      
     public void onReceive(Object message) {
       if (message instanceof Calculate) {
-        for (int start = 0; start < nrOfMessages; start++) {
-          workerRouter.tell(new Work(start, nrOfElements), getSelf());
+        for (int st = 0; st < nrOfMessages; st++) {
+          workerRouter.tell(new Work(st, nrOfElements), getSelf());
         }
       } else if (message instanceof Result) {
         Result result = (Result) message;
@@ -131,23 +129,19 @@
     ActorSystem system = ActorSystem.create("PiSystem");
      
     // create the result listener, which will print the result and shutdown the system
-    final ActorRef listener = system.actorOf(new Props(Listener.class), "listener");
+    final ActorRef listener = system.actorOf(Props.create(Listener.class), "listener");
      
     // create the master
-    ActorRef master = system.actorOf(new Props(new UntypedActorFactory() {
-        public UntypedActor create() {
-          return new Master(nrOfWorkers, nrOfMessages, nrOfElements, listener);
-        }
-      }), "master");
+    ActorRef master = system.actorOf(Props.create(Master.class, nrOfWorkers, nrOfMessages, nrOfElements, listener), "master");
      
     // start the calculation
-    master.tell(new Calculate());
+    master.tell(new Calculate(), ActorRef.noSender());
      
   } 
 }