MCPcopy Index your code
hub / github.com/clojure/clojure / ARef

Class ARef

src/jvm/clojure/lang/ARef.java:17–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15import java.util.Map;
16
17public abstract class ARef extends AReference implements IRef{
18protected volatile IFn validator = null;
19private volatile IPersistentMap watches = PersistentHashMap.EMPTY;
20
21public ARef(){
22 super();
23}
24
25public ARef(IPersistentMap meta){
26 super(meta);
27}
28
29void validate(IFn vf, Object val){
30 try
31 {
32 if(vf != null && !RT.booleanCast(vf.invoke(val)))
33 throw new IllegalStateException("Invalid reference state");
34 }
35 catch(RuntimeException re)
36 {
37 throw re;
38 }
39 catch(Exception e)
40 {
41 throw new IllegalStateException("Invalid reference state", e);
42 }
43}
44
45void validate(Object val){
46 validate(validator, val);
47}
48
49public void setValidator(IFn vf){
50 validate(vf, deref());
51 validator = vf;
52}
53
54public IFn getValidator(){
55 return validator;
56}
57
58public IPersistentMap getWatches(){
59 return watches;
60}
61
62synchronized public IRef addWatch(Object key, IFn callback){
63 watches = watches.assoc(key, callback);
64 return this;
65}
66
67synchronized public IRef removeWatch(Object key){
68 watches = watches.without(key);
69 return this;
70}
71
72public void notifyWatches(Object oldval, Object newval){
73 IPersistentMap ws = watches;
74 if(ws.count() > 0)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…