package com.hypirion.beckon;

import sun.misc.Signal;
import sun.misc.SignalHandler;

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

public class SignalRegistererHelper {

    private static Map<String, SignalHandler> originalHandlers =
        new HashMap<String, SignalHandler>();

    /**
     * Registers the new list of functions to the signal name, and returns the
     * old SignalHandler.
     */
    private static SignalHandler reset_BANG_(String signame, List fns) {
        Signal sig = new Signal(signame);
        SignalFolder folder = new SignalFolder(fns);
        SignalHandler oldHandler = Signal.handle(sig, folder);
        return oldHandler;
    }

    static synchronized void register(String signame, List fns) {
        SignalHandler old = reset_BANG_(signame, fns);
        if (!originalHandlers.containsKey(signame)) {
            originalHandlers.put(signame, old);
        }
    }
}

@@ -190,16 +190,100 @@
 lper %7B%0A%0A
+    /**%0A     * A mapping of the signal name to the original signal handler.%0A     */%0A
     priv
@@ -282,24 +282,30 @@
     private 
+final 
 static Map%3CS
@@ -778,16 +778,544 @@
 %0A    %7D%0A%0A
+    /**%0A     * Registers the signal name to a List of Callables, where each callable%0A     * returns an Object. The signal handling is performed as follows: The first%0A     * callable is called, and if it returns a value equal to %3Ccode%3Efalse%3C/code%3E%0A     * or %3Ccode%3Enull%3C/code%3E it will stop. Otherwise it will repeat on the next%0A     * callable, until there are no more left.%0A     *%0A     * @param signame the signal name to register this list of callables on.%0A     * @param fns the list of Callables to (potentially) call.%0A     */%0A
     stat

Document and synchronize register method.