//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package com.threerings.presents.server;

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

import com.samskivert.util.RunAnywhere;

import static com.threerings.presents.Log.log;

/**
 * Handles signals using Sun's undocumented Signal class.
 */
public class SunSignalHandler extends AbstractSignalHandler
    implements SignalHandler
{
    // from interface SignalHandler
    public void handle (Signal sig)
    {
        SignalHandler chain = null;
        if (sig.getName().equals("INT")) {
            intReceived();
        } else if (sig.getName().equals("HUP")) {
            hupReceived();
        } else {
            log.warning("Received unknown signal '" + sig.getName() + "'.");
        }
    }

    protected boolean registerHandlers ()
    {
        // we don't track and call the chained handlers for INT and HUP because those exit the JVM
        // which we do not want to do
        Signal.handle(new Signal("INT"), this);
        if (!RunAnywhere.isWindows()) {
            Signal.handle(new Signal("HUP"), this);
        }
        return true;
    }
}

@@ -967,56 +967,40 @@
 ort 
-sun.misc.Signal;%0Aimport sun.misc.SignalHandler;%0A
+com.samskivert.util.RunAnywhere;
 %0Aimp
@@ -1023,27 +1023,26 @@
 rt.util.
-RunAnywhere
+SignalUtil
 ;%0A%0Aimpor
@@ -1214,269 +1214,197 @@
 ler%0A
+%7B%0A
     
-implements SignalHandler%0A%7B%0A    // from interface SignalHandler%0A    public void handle (Signal sig)%0A    %7B%0A        SignalHandler chain = null;%0A        if (sig.getName().equals(%22INT%22)) %7B%0A            intReceived();%0A        %7D else if (sig.getName().equals(%22HUP%22)
+protected boolean registerHandlers ()%0A    %7B%0A        SignalUtil.register(SignalUtil.Number.INT, new SignalUtil.Handler() %7B%0A            public void signalReceived (SignalUtil.Number sig
 ) %7B%0A
@@ -1419,11 +1419,15 @@
     
-hup
+    int
 Rece
@@ -1446,93 +1446,65 @@
     
-%7D else %7B%0A            log.warning(%22Received unknown signal '%22 + sig.getName() + %22'.%22);
+    %7D%0A        %7D);%0A        if (!RunAnywhere.isWindows()) %7B
 %0A   
@@ -1512,73 +1512,95 @@
     
-%7D%0A
     
-%7D%0A%0A    protected boolean register
+SignalUtil.register(SignalUtil.Number.HUP, new SignalUtil.
 Handler
-s ()%0A
+() %7B%0A 
     
-%7B%0A
         
 // w
@@ -1599,274 +1599,130 @@
     
-// we don't track and call the chained handlers for INT and HUP because those exit the JVM%0A        // which we do not want to do%0A        Signal.handle(new Signal(%22INT%22), this);%0A        if (!RunAnywhere.isWindows()) %7B%0A
+   public void signalReceived (SignalUtil.Number sig) %7B%0A                    hupReceived();%0A         
       
+ %7D%0A
       
-Signal.handle(new Signal(%22HUP%22), this
+      %7D
 );%0A 

Use samskivert signal wrapper.