package com.hypirion.beckon;

import java.util.Map;
import java.util.HashMap;

import clojure.lang.Atom;
import clojure.lang.PersistentHashMap;
import clojure.lang.Keyword;

public class SignalAtoms {
    private static final Map<String, Atom> atoms = new HashMap<String, Atom>();
    public static final Keyword SIGNAL = Keyword.intern("signal");

    static final synchronized Atom getSignalAtom(String signame) {
        if (!atoms.containsKey(signame)) {
            Object list = SignalRegistererHelper.getHandlerList(signame);
            PersistentHashMap metadata = PersistentHashMap.create(SIGNAL, signame);
            Atom atm = new Atom(list, metadata);
            atoms.put(signame, atm);
        }
        return atoms.get(signame);
    }
}

@@ -23,16 +23,39 @@
 eckon;%0A%0A
+import java.util.List;%0A
 import j
@@ -95,16 +95,55 @@
 shMap;%0A%0A
+import java.util.concurrent.Callable;%0A%0A
 import c
@@ -227,16 +227,66 @@
 Keyword;
+%0Aimport clojure.lang.AFn;%0Aimport clojure.lang.IFn;
 %0A%0Apublic
@@ -452,16 +452,95 @@
 ignal%22);
+%0A    public static final IFn SIGNAL_ATOM_VALIDATOR = new SignalAtomValidator();
 %0A%0A    st
@@ -850,16 +850,69 @@
 adata);%0A
+            atm.setValidator(SIGNAL_ATOM_VALIDATOR);%0A
         
@@ -990,11 +990,607 @@
 );%0A    %7D
+%0A%0A    private static class SignalAtomValidator extends AFn %7B%0A        @Override%0A        public Object invoke(Object newVal) %7B%0A            if (newVal instanceof List) %7B%0A                List lst = (List) newVal;%0A                for (Object o : lst) %7B%0A                    if (!(newVal instanceof Callable)) %7B%0A                        throw new IllegalStateException(%22Invalid reference state%22);%0A                    %7D%0A                %7D%0A                return true;%0A            %7D%0A            else %7B%0A                throw new IllegalStateException(%22Invalid reference state%22);%0A            %7D%0A        %7D%0A    %7D
 %0A%7D%0A

Add in validator.