Class ShutdownHandler

  • All Implemented Interfaces:
    Handler, HandlerContainer, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle

    @Deprecated(since="2021-05-27")
    public class ShutdownHandler
    extends HandlerWrapper
    Deprecated.
    The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.
    A handler that shuts the server down on a valid request. Used to do "soft" restarts from Java. If _exitJvm is set to true a hard System.exit() call is being made. If _sendShutdownAtStart is set to true, starting the server will try to shut down an existing server at the same port. If _sendShutdownAtStart is set to true, make an http call to "http://localhost:" + port + "/shutdown?token=" + shutdownCookie in order to shut down the server. This handler is a contribution from Johannes Brodwall: https://bugs.eclipse.org/bugs/show_bug.cgi?id=357687 Usage:
      Server server = new Server(8080);
      HandlerList handlers = new HandlerList();
      handlers.setHandlers(new Handler[]
      { someOtherHandler, new ShutdownHandler("secret password", false, true) });
      server.setHandler(handlers);
      server.start();
      
      public static void attemptShutdown(int port, String shutdownCookie) {
      try {
      URL url = new URL("http://localhost:" + port + "/shutdown?token=" + shutdownCookie);
      HttpURLConnection connection = (HttpURLConnection)url.openConnection();
      connection.setRequestMethod("POST");
      connection.getResponseCode();
      logger.info("Shutting down " + url + ": " + connection.getResponseMessage());
      } catch (SocketException e) {
      logger.debug("Not running");
      // Okay - the server is not running
      } catch (IOException e) {
      throw new RuntimeException(e);
      }
      }
      
    • Constructor Detail

      • ShutdownHandler

        @Deprecated
        public ShutdownHandler​(Server server,
                               java.lang.String shutdownToken)
        Deprecated.
        Creates a listener that lets the server be shut down remotely (but only from localhost).
        Parameters:
        server - the Jetty instance that should be shut down
        shutdownToken - a secret password to avoid unauthorized shutdown attempts
      • ShutdownHandler

        public ShutdownHandler​(java.lang.String shutdownToken)
        Deprecated.
      • ShutdownHandler

        public ShutdownHandler​(java.lang.String shutdownToken,
                               boolean exitJVM,
                               boolean sendShutdownAtStart)
        Deprecated.
        Parameters:
        shutdownToken - a secret password to avoid unauthorized shutdown attempts
        exitJVM - If true, when the shutdown is executed, the handler class System.exit()
        sendShutdownAtStart - If true, a shutdown is sent as an HTTP post during startup, which will shutdown any previously running instances of this server with an identically configured ShutdownHandler
    • Method Detail

      • sendShutdown

        public void sendShutdown()
                          throws java.io.IOException
        Deprecated.
        Throws:
        java.io.IOException
      • setExitJvm

        public void setExitJvm​(boolean exitJvm)
        Deprecated.
      • isSendShutdownAtStart

        public boolean isSendShutdownAtStart()
        Deprecated.
      • setSendShutdownAtStart

        public void setSendShutdownAtStart​(boolean sendShutdownAtStart)
        Deprecated.
      • getShutdownToken

        public java.lang.String getShutdownToken()
        Deprecated.
      • isExitJvm

        public boolean isExitJvm()
        Deprecated.