[armedbear-devel] 20130823a Diffs for chemicalamba (Akka bridge in ABCL)

Mark Evenson evenson at panix.com
Thu Aug 22 19:15:14 UTC 2013


On 8/22/13 9:10 PM, Mark Evenson wrote:

> Another round of diffs against the ]chemicalambda master][git].  Still
> haven't finished refactoring the Java...

Attached, please find the correct patch.



-- 
"A screaming comes across the sky.  It has happened before, but there
is nothing to compare to it now."
-------------- next part --------------
# HG changeset patch
# Parent d100154f4a3e1ac8c5c727f1383456a8ec54be81
Initial patches to get chemicalambda to work.

Move Java source to standard location where Maven can build it.

Start to refactor Java Akka classes.

diff --git a/AkkaApi.java b/AkkaApi.java
deleted file mode 100644
--- a/AkkaApi.java
+++ /dev/null
@@ -1,74 +0,0 @@
-import java.util.Map;
-
-import org.armedbear.lisp.JavaObject;
-import org.armedbear.lisp.LispObject;
-
-import akka.actor.UntypedActor;
-import akka.actor.ActorRef;
-import akka.event.Logging;
-import akka.event.LoggingAdapter;
-import akka.actor.Props;
-import akka.japi.Creator;
-import akka.actor.ActorSystem;
-
-public class AkkaApi {
-    static ActorSystem system = ActorSystem.create();
-
-    public static void main(String[] args) {
-        ActorRef a = AkkaApi.createActor();
-        System.out.println("It worked!");
-    }
-
-    public static ActorRef createActor() {
-        ActorRef toReturn = system.actorOf(Props.create(AkkaActorUntyped.class));
-        return toReturn;
-    }
-}
-
-class AkkaActorUntyped extends UntypedActor {
-    protected Class<?> objectType;
-    protected LispObject closure;
-    protected Map<Object, Object> dependencies;
-
-    LoggingAdapter log = Logging.getLogger(getContext().system(), this);
-
-    // public static Props mkProps(String name) {
-    //     return Props.create(AkkaActorUntyped.class);
-    // }
-
-    public void onReceive(Object message) throws Exception {
-        if (message instanceof String) {
-            log.info("Received String message: {}", message);
-            getSender().tell(message, getSelf());
-        } else
-            unhandled(message);
-    }
-    //
-    public void preStart() {
-    }
- 
-    public void preRestart(Throwable reason, scala.Option<Object> message) {
-        for (ActorRef each : getContext().getChildren()) {
-            getContext().unwatch(each);
-            getContext().stop(each);
-        }
-        postStop();
-    }
- 
-    public void postRestart(Throwable reason) {
-        preStart();
-    }
- 
-    public void postStop() {
-    }
-    //
-    public void LispFactory(LispObject closure, Class<?> objectType) {
-        this.objectType = objectType;
-        this.closure = closure;
-    }
-    
-    protected Object createInstance() throws Exception {
-        return closure.execute(JavaObject.getInstance(this)).javaInstance();
-    }
-}
-
diff --git a/src/main/java/org/abcl/akka/AkkaActorUntyped.java b/src/main/java/org/abcl/akka/AkkaActorUntyped.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/org/abcl/akka/AkkaActorUntyped.java
@@ -0,0 +1,58 @@
+package org.abcl.akka;
+
+import akka.actor.ActorRef;
+import akka.actor.Props;
+import akka.actor.UntypedActor;
+import akka.event.Logging;
+import akka.event.LoggingAdapter;
+import java.util.Map;
+import org.armedbear.lisp.JavaObject;
+import org.armedbear.lisp.LispObject;
+
+public class AkkaActorUntyped extends UntypedActor {
+    protected Class<?> objectType;
+    protected LispObject closure;
+    protected Map<Object, Object> dependencies;
+
+    public static Props mkProps() {
+        return Props.create(AkkaActorUntyped.class);
+    }
+
+    LoggingAdapter log = Logging.getLogger(getContext().system(), this);
+
+    public void onReceive(Object message) throws Exception {
+        if (message instanceof String) {
+            log.info("Received String message: {}", message);
+            getSender().tell(message, getSelf());
+        } else
+            unhandled(message);
+    }
+    //
+    public void preStart() {
+    }
+ 
+    public void preRestart(Throwable reason, scala.Option<Object> message) {
+        for (ActorRef each : getContext().getChildren()) {
+            getContext().unwatch(each);
+            getContext().stop(each);
+        }
+        postStop();
+    }
+ 
+    public void postRestart(Throwable reason) {
+        preStart();
+    }
+ 
+    public void postStop() {
+    }
+    //
+    public void LispFactory(LispObject closure, Class<?> objectType) {
+        this.objectType = objectType;
+        this.closure = closure;
+    }
+    
+    protected Object createInstance() throws Exception {
+        return closure.execute(JavaObject.getInstance(this)).javaInstance();
+    }
+}
+
diff --git a/src/main/java/org/abcl/akka/AkkaApi.java b/src/main/java/org/abcl/akka/AkkaApi.java
--- a/src/main/java/org/abcl/akka/AkkaApi.java
+++ b/src/main/java/org/abcl/akka/AkkaApi.java
@@ -31,76 +31,4 @@
     }
 }
 
-class AkkaActorUntyped extends UntypedActor {
-    protected Class<?> objectType;
-    protected LispObject closure;
-    protected Map<Object, Object> dependencies;
 
-    public static Props mkProps() {
-        return Props.create(AkkaActorUntyped.class);
-    }
-
-    LoggingAdapter log = Logging.getLogger(getContext().system(), this);
-
-    public void onReceive(Object message) throws Exception {
-        if (message instanceof String) {
-            log.info("Received String message: {}", message);
-            getSender().tell(message, getSelf());
-        } else
-            unhandled(message);
-    }
-    //
-    public void preStart() {
-    }
- 
-    public void preRestart(Throwable reason, scala.Option<Object> message) {
-        for (ActorRef each : getContext().getChildren()) {
-            getContext().unwatch(each);
-            getContext().stop(each);
-        }
-        postStop();
-    }
- 
-    public void postRestart(Throwable reason) {
-        preStart();
-    }
- 
-    public void postStop() {
-    }
-    //
-    public void LispFactory(LispObject closure, Class<?> objectType) {
-        this.objectType = objectType;
-        this.closure = closure;
-    }
-    
-    protected Object createInstance() throws Exception {
-        return closure.execute(JavaObject.getInstance(this)).javaInstance();
-    }
-}
-
-class AkkaSingleton {
-    private static AkkaSingleton instance = null;
-    static int x = 0;
-    ActorSystem system = null;
-
-    protected AkkaSingleton() {
-        system = ActorSystem.create(); //"0", ConfigFactory.load("/home/ubikation/src/lisp/chemicalambda/src/main/resources/application.conf")
-    }
-
-    public static AkkaSingleton getInstance() {
-        if(instance == null) {
-            instance = new AkkaSingleton();
-        }
-        return instance;
-    }
-
-    public static void stop() {
-        AkkaSingleton as = getInstance();
-        as.system.shutdown();
-    }
-
-    public static ActorRef createActor() {
-        AkkaSingleton as = getInstance();
-        return as.system.actorOf(AkkaActorUntyped.mkProps());
-    }
-}
diff --git a/AkkaApiSimple.java b/src/main/java/org/abcl/akka/AkkaApiSimple.java
rename from AkkaApiSimple.java
rename to src/main/java/org/abcl/akka/AkkaApiSimple.java
--- a/AkkaApiSimple.java
+++ b/src/main/java/org/abcl/akka/AkkaApiSimple.java
@@ -1,3 +1,5 @@
+package org.abcl.akka;
+
 import java.util.Map;
 
 import org.armedbear.lisp.JavaObject;
@@ -8,10 +10,8 @@
 import akka.event.Logging;
 import akka.event.LoggingAdapter;
 import akka.actor.Props;
-import akka.japi.Creator;
 import akka.actor.ActorSystem;
 
-
 public class AkkaApiSimple {
 
     public static void main(String[] args) {
@@ -27,10 +27,9 @@
         AkkaSingleton.stop();
         System.out.println("< AkkaApiSimple.test");
     }
-
 }
 
-class AkkaActorUntyped extends UntypedActor {
+class AkkaActorUntypedApiSimple extends UntypedActor {
     protected Class<?> objectType;
     protected LispObject closure;
     protected Map<Object, Object> dependencies;
@@ -75,31 +74,4 @@
     protected Object createInstance() throws Exception {
         return closure.execute(JavaObject.getInstance(this)).javaInstance();
     }
-}
-
-class AkkaSingleton {
-    private static AkkaSingleton instance = null;
-    static int x = 0;
-    ActorSystem system = null;
-
-    protected AkkaSingleton() {
-        system = ActorSystem.create();
-    }
-
-    public static AkkaSingleton getInstance() {
-        if(instance == null) {
-            instance = new AkkaSingleton();
-        }
-        return instance;
-    }
-
-    public static void stop() {
-        AkkaSingleton as = getInstance();
-        as.system.shutdown();
-    }
-
-    public static ActorRef createActor() {
-        AkkaSingleton as = getInstance();
-        return as.system.actorOf(AkkaActorUntyped.mkProps());
-    }
-}
+}
\ No newline at end of file
diff --git a/src/main/java/org/abcl/akka/AkkaSingleton.java b/src/main/java/org/abcl/akka/AkkaSingleton.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/org/abcl/akka/AkkaSingleton.java
@@ -0,0 +1,32 @@
+package org.abcl.akka;
+
+import akka.actor.ActorRef;
+import akka.actor.ActorSystem;
+
+
+public class AkkaSingleton {
+    private static AkkaSingleton instance = null;
+    static int x = 0;
+    ActorSystem system = null;
+
+    protected AkkaSingleton() {
+        system = ActorSystem.create(); //"0", ConfigFactory.load("/home/ubikation/src/lisp/chemicalambda/src/main/resources/application.conf")
+    }
+
+    public static AkkaSingleton getInstance() {
+        if(instance == null) {
+            instance = new AkkaSingleton();
+        }
+        return instance;
+    }
+
+    public static void stop() {
+        AkkaSingleton as = getInstance();
+        as.system.shutdown();
+    }
+
+    public static ActorRef createActor() {
+        AkkaSingleton as = getInstance();
+        return as.system.actorOf(AkkaActorUntyped.mkProps());
+    }
+}
diff --git a/src/main/java/org/abcl/akka/protocol/AkkaActorUntyped.java b/src/main/java/org/abcl/akka/protocol/AkkaActorUntyped.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/org/abcl/akka/protocol/AkkaActorUntyped.java
@@ -0,0 +1,6 @@
+package org.abcl.akka.protocol;
+
+public interface AkkaActorUntyped {
+    // marker type for implementors of AkkaActor
+    public Props mkProps(String name);
+}


More information about the armedbear-devel mailing list