Changeset ad4d73ea


Ignore:
Timestamp:
Jan 9, 2012 11:59:58 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c6e6a9d
Parents:
352c6ba
Message:
  • Fix class error on wrapper 3.1.1
Location:
apps/routerconsole/java/src/net/i2p/router/web
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java

    r352c6ba rad4d73ea  
    99import net.i2p.router.RouterContext;
    1010import net.i2p.router.startup.ClientAppConfig;
    11 import net.i2p.util.Log;
     11import net.i2p.util.VersionComparator;
    1212
    1313import org.tanukisoftware.wrapper.WrapperManager;
    14 import org.tanukisoftware.wrapper.event.WrapperControlEvent;
    15 import org.tanukisoftware.wrapper.event.WrapperEvent;
    16 import org.tanukisoftware.wrapper.event.WrapperEventListener;
    1714
    1815/**
     
    2320public class ConfigServiceHandler extends FormHandler {
    2421   
    25     private static WrapperEventListener _signalHandler;
    26 
    27     private static final String PROP_GRACEFUL_HUP = "router.gracefulHUP";
     22    private static WrapperListener _wrapperListener;
     23
     24    private static final String LISTENER_AVAILABLE = "3.2.0";
    2825
    2926    /**
     
    138135    /**
    139136     *  Register a handler for signals,
    140      *  so we can handle HUP from the wrapper (non-Windows only)
     137     *  so we can handle HUP from the wrapper (non-Windows only, wrapper 3.2.0 or higher)
    141138     *
    142139     *  @since 0.8.13
    143140     */
    144141    synchronized static void registerSignalHandler(RouterContext ctx) {
    145         if (ctx.hasWrapper() && _signalHandler == null &&
     142        if (ctx.hasWrapper() && _wrapperListener == null &&
    146143            !System.getProperty("os.name").startsWith("Win")) {
    147            _signalHandler = new SignalHandler(ctx);
    148            long mask = WrapperEventListener.EVENT_FLAG_CONTROL;
    149            WrapperManager.addWrapperEventListener(_signalHandler, mask);
     144            String wv = System.getProperty("wrapper.version");
     145            if (wv != null && (new VersionComparator()).compare(wv, LISTENER_AVAILABLE) >= 0) {
     146                try {
     147                   _wrapperListener = new WrapperListener(ctx);
     148                } catch (Throwable t) {}
     149            }
    150150        }
    151151    }
     
    157157     */
    158158    public synchronized static void unregisterSignalHandler() {
    159         if (_signalHandler != null) {
    160            WrapperManager.removeWrapperEventListener(_signalHandler);
    161            _signalHandler = null;
    162         }
    163     }
    164 
    165     /**
    166      *  Catch signals.
    167      *  The wrapper will potentially forward HUP, USR1, and USR2.
    168      *  But USR1 and USR2 are used by the JVM GC and cannot be trapped.
    169      *  So we will only get HUP.
    170      *
    171      *  @since 0.8.13
    172      */
    173     private static class SignalHandler implements WrapperEventListener {
    174         private final RouterContext _ctxt;
    175 
    176         public SignalHandler(RouterContext ctx) {
    177             _ctxt = ctx;
    178         }
    179 
    180         public void fired(WrapperEvent event) {
    181             if (!(event instanceof WrapperControlEvent))
    182                 return;
    183             WrapperControlEvent wce = (WrapperControlEvent) event;
    184             Log log = _ctxt.logManager().getLog(ConfigServiceHandler.class);
    185             if (log.shouldLog(Log.WARN))
    186                 log.warn("Got signal: " + wce.getControlEventName());
    187             int sig = wce.getControlEvent();
    188             switch (sig) {
    189               case WrapperManager.WRAPPER_CTRL_HUP_EVENT:
    190                 if (_ctxt.getBooleanProperty(PROP_GRACEFUL_HUP)) {
    191                     wce.consume();
    192                     if (!(_ctxt.router().gracefulShutdownInProgress() ||
    193                           _ctxt.router().isFinalShutdownInProgress())) {
    194                         System.err.println("WARN: Graceful shutdown initiated by SIGHUP");
    195                         log.logAlways(Log.WARN, "Graceful shutdown initiated by SIGHUP");
    196                         registerWrapperNotifier(_ctxt, Router.EXIT_GRACEFUL, false);
    197                         _ctxt.router().shutdownGracefully();
    198                     }
    199                 } else {
    200                     log.log(Log.CRIT, "Hard shutdown initiated by SIGHUP");
    201                     // JVM will call ShutdownHook if we don't do it ourselves
    202                     //wce.consume();
    203                     //registerWrapperNotifier(_ctxt, Router.EXIT_HARD, false);
    204                     //_ctxt.router().shutdown(Router.EXIT_HARD);
    205                 }
    206                 break;
    207             }
     159        if (_wrapperListener != null) {
     160            _wrapperListener.unregister();
     161            _wrapperListener = null;
    208162        }
    209163    }
Note: See TracChangeset for help on using the changeset viewer.