diff options
author | Rich Hickey <richhickey@gmail.com> | 2007-11-26 00:56:01 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2007-11-26 00:56:01 +0000 |
commit | e40ebe81b7f21ba844c08e3411ce437557630a3f (patch) | |
tree | 185d2e37d6c82f6b3a8e704e55755fa5f4d74d20 /src | |
parent | e8d476806bc50753b3a72c11db1c6a10b3ad8d8c (diff) |
actor system
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.clj | 13 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Actor.java | 23 |
2 files changed, 26 insertions, 10 deletions
diff --git a/src/boot.clj b/src/boot.clj index 5a9b1c4d..e53d2b80 100644 --- a/src/boot.clj +++ b/src/boot.clj @@ -49,7 +49,16 @@ (defn actor-of [state] (:actor ^state)) - + +(defn ! [#^clojure.lang.Actor a f & args] + (. a (send f args))) + +(defn actor-errors [#^clojure.lang.Actor a] + (. a (getErrors))) + +(defn clear-actor-errors [#^clojure.lang.Actor a] + (. a (clearErrors))) + ;;;;;;;;;;;;;;;;;;;; (def defmacro (fn [name & args] (list 'do @@ -776,6 +785,6 @@ int long float double short byte boolean aget aset aset-boolean aset-int aset-long aset-float aset-double aset-short aset-byte make-array - actor actor-of + actor actor-of ! )) diff --git a/src/jvm/clojure/lang/Actor.java b/src/jvm/clojure/lang/Actor.java index b2475bca..6d17b2ce 100644 --- a/src/jvm/clojure/lang/Actor.java +++ b/src/jvm/clojure/lang/Actor.java @@ -18,12 +18,12 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; -public class Actor extends RestFn implements IRef{ +public class Actor implements IRef{ volatile Object state; final Queue q = new LinkedList(); boolean busy = false; -final public Queue<Exception> errors = new LinkedBlockingQueue<Exception>(); +volatile ISeq errors = null; //todo - make tuneable final static Executor executor = Executors.newFixedThreadPool(2 + Runtime.getRuntime().availableProcessors()); //final static Executor executor = Executors.newCachedThreadPool(); @@ -51,7 +51,7 @@ static class Action implements Runnable{ catch(Exception e) { //todo report/callback - actor.errors.add(e); + actor.errors = RT.cons(e, actor.errors); hadError = true; } @@ -81,7 +81,6 @@ static class Action implements Runnable{ } public Actor(Object state){ - super(1); setState(state); } @@ -101,12 +100,20 @@ public Object get(){ return state; } -public Object doInvoke(Object fn, Object args) throws Exception{ - if(!errors.isEmpty()) +public ISeq getErrors(){ + return errors; +} + +public void clearErrors(){ + errors = null; +} + +public Object send(IFn fn, ISeq args) throws Exception{ + if(errors != null) { - throw new Exception("Actor has errors", errors.peek()); + throw new Exception("Actor has errors", (Exception) RT.first(errors)); } - Action action = new Action(this, (IFn) fn, (ISeq) args); + Action action = new Action(this, fn, args); LockingTransaction trans = LockingTransaction.getRunning(); if(trans != null) trans.enqueue(action); |