diff options
author | Rich Hickey <richhickey@gmail.com> | 2007-12-02 16:17:12 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2007-12-02 16:17:12 +0000 |
commit | 340b89a20353fb118a923fcf0109b2feeeae88e0 (patch) | |
tree | 5ef2a7610e118fa6080a68ab07b3fe29c2a1952e /src | |
parent | 8779cee7968ca6479b572854afb4095a21e33f07 (diff) |
renamed Actor to IRef
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.clj | 18 | ||||
-rw-r--r-- | src/jvm/clojure/lang/IRef.java (renamed from src/jvm/clojure/lang/Actor.java) | 34 | ||||
-rw-r--r-- | src/jvm/clojure/lang/LockingTransaction.java | 8 | ||||
-rw-r--r-- | src/jvm/clojure/lang/RT.java | 2 |
4 files changed, 31 insertions, 31 deletions
diff --git a/src/boot.clj b/src/boot.clj index 9558d4b9..9f2347e6 100644 --- a/src/boot.clj +++ b/src/boot.clj @@ -44,19 +44,19 @@ (. x (withMeta m))) ;;;;;;;;;;;;;;;;;;;; actors ;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn actor [state] - (new clojure.lang.Actor state)) +(defn iref [state] + (new clojure.lang.IRef state)) -(defn actor-of [state] - (:actor ^state)) +(defn iref-of [state] + (:iref ^state)) -(defn ! [#^clojure.lang.Actor a f & args] - (. a (send f args))) +(defn ! [#^clojure.lang.IRef a f & args] + (. a (commute f args))) -(defn actor-errors [#^clojure.lang.Actor a] +(defn actor-errors [#^clojure.lang.IRef a] (. a (getErrors))) -(defn clear-actor-errors [#^clojure.lang.Actor a] +(defn clear-actor-errors [#^clojure.lang.IRef a] (. a (clearErrors))) ;;;;;;;;;;;;;;;;;;;; @@ -795,6 +795,6 @@ int long float double short byte boolean char aget aset aset-boolean aset-int aset-long aset-float aset-double aset-short aset-byte make-array - actor actor-of ! + iref iref-of ! )) diff --git a/src/jvm/clojure/lang/Actor.java b/src/jvm/clojure/lang/IRef.java index c959cee5..81d463d2 100644 --- a/src/jvm/clojure/lang/Actor.java +++ b/src/jvm/clojure/lang/IRef.java @@ -17,7 +17,7 @@ import java.util.LinkedList; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -public class Actor implements Ref{ +public class IRef implements Ref{ volatile Object state; final Queue q = new LinkedList(); boolean busy = false; @@ -31,13 +31,13 @@ final static ThreadLocal<PersistentVector> nested = new ThreadLocal<PersistentVe final static ThreadLocal inChange = new ThreadLocal(); static class Action implements Runnable{ - final Actor actor; + final IRef iref; final IFn fn; final ISeq args; - public Action(Actor actor, IFn fn, ISeq args){ - this.actor = actor; + public Action(IRef iref, IFn fn, ISeq args){ + this.iref = iref; this.args = args; this.fn = fn; } @@ -47,12 +47,12 @@ static class Action implements Runnable{ boolean hadError = false; try { - actor.doAlter(fn, args); + iref.doAlter(fn, args); } catch(Exception e) { //todo report/callback - actor.errors = RT.cons(e, actor.errors); + iref.errors = RT.cons(e, iref.errors); hadError = true; } @@ -61,19 +61,19 @@ static class Action implements Runnable{ for(ISeq s = nested.get().seq(); s != null; s = s.rest()) { Action a = (Action) s.first(); - a.actor.enqueue(a); + a.iref.enqueue(a); } } - synchronized(actor) + synchronized(iref) { - if(!actor.q.isEmpty()) + if(!iref.q.isEmpty()) { - executor.execute((Runnable) actor.q.remove()); + executor.execute((Runnable) iref.q.remove()); } else { - actor.busy = false; + iref.busy = false; } } @@ -81,7 +81,7 @@ static class Action implements Runnable{ } } -public Actor(Object state){ +public IRef(Object state){ setState(state); } @@ -89,9 +89,9 @@ void setState(Object newState){ if(newState instanceof IObj) { IObj o = (IObj) newState; - if(RT.get(o.meta(), RT.ACTOR_KEY) != this) + if(RT.get(o.meta(), RT.IREF_KEY) != this) { - newState = o.withMeta((IPersistentMap) RT.assoc(o.meta(), RT.ACTOR_KEY, this)); + newState = o.withMeta((IPersistentMap) RT.assoc(o.meta(), RT.IREF_KEY, this)); } } state = newState; @@ -124,14 +124,14 @@ synchronized void doAlter(IFn fn, ISeq args) throws Exception{ public Object alter(IFn fn, ISeq args) throws Exception{ if(errors != null) { - throw new Exception("Actor has errors", (Exception) RT.first(errors)); + throw new Exception("IRef has errors", (Exception) RT.first(errors)); } //Action action = new Action(this, fn, args); if(commuting) throw new Exception("Recursive change"); LockingTransaction trans = LockingTransaction.getRunning(); if(trans != null) - throw new Exception("Cannot change an Actor in a transaction"); + throw new Exception("Cannot change an IRef in a transaction"); if(inChange.get() != null) throw new Exception("Cannot nest changes, use send"); @@ -151,7 +151,7 @@ public Object alter(IFn fn, ISeq args) throws Exception{ public Object commute(IFn fn, ISeq args) throws Exception{ if(errors != null) { - throw new Exception("Actor has errors", (Exception) RT.first(errors)); + throw new Exception("IRef has errors", (Exception) RT.first(errors)); } Action action = new Action(this, fn, args); LockingTransaction trans = LockingTransaction.getRunning(); diff --git a/src/jvm/clojure/lang/LockingTransaction.java b/src/jvm/clojure/lang/LockingTransaction.java index c3e81e1a..b09f49ea 100644 --- a/src/jvm/clojure/lang/LockingTransaction.java +++ b/src/jvm/clojure/lang/LockingTransaction.java @@ -87,7 +87,7 @@ long readPoint; long startPoint; long startTime; final RetryException retryex = new RetryException(); -final ArrayList<Actor.Action> actions = new ArrayList<Actor.Action>(); +final ArrayList<IRef.Action> actions = new ArrayList<IRef.Action>(); final HashMap<TRef, Object> vals = new HashMap<TRef, Object>(); final HashSet<TRef> sets = new HashSet<TRef>(); final TreeMap<TRef, ArrayList<IFn>> commutes = new TreeMap<TRef, ArrayList<IFn>>(); @@ -260,9 +260,9 @@ Object run(IFn fn) throws Exception{ ref.tvals.msecs = msecs; } } - for(Actor.Action action : actions) + for(IRef.Action action : actions) { - action.actor.enqueue(action); + action.iref.enqueue(action); } done = true; info.status.set(COMMITTED); @@ -287,7 +287,7 @@ Object run(IFn fn) throws Exception{ return ret; } -public void enqueue(Actor.Action action){ +public void enqueue(IRef.Action action){ actions.add(action); } diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index 61d324a7..1c54b923 100644 --- a/src/jvm/clojure/lang/RT.java +++ b/src/jvm/clojure/lang/RT.java @@ -25,7 +25,7 @@ final static public Var IN = Var.intern(Symbol.create("clojure", "*in*"), new LineNumberingPushbackReader(new InputStreamReader(System.in))); final static Keyword TAG_KEY = Keyword.intern("clojure", "tag"); -final static Keyword ACTOR_KEY = Keyword.intern("clojure", "actor"); +final static Keyword IREF_KEY = Keyword.intern("clojure", "iref"); //final static public Var CURRENT_MODULE = Var.intern(Symbol.create("clojure", "current-module"), // Module.findOrCreateModule("clojure/user")); |