Class ShutdownService

java.lang.Object
org.eclipse.jetty.server.ShutdownService
Direct Known Subclasses:
ShutdownMonitor

public class ShutdownService extends Object
Server Shutdown Service, which will listen to a configured Host / Port and handle commands to control the list of Jetty Component LifeCycle objects.

The commands you can send to this Server are always in US_ASCII with a CRLF (\r\n.

Supported commands:

FORCESTOP
Will stop components by calling LifeCycle.stop().
Will receive Stopped\r\n after stop, and before exit.
STOPEXIT
Will stop components by calling LifeCycle.stop(),
(Each component that is a Destroyable will also be destroyed) followed by System.exit(0); at the end.
Will receive Stopped\r\n after stop/destroy, and before exit.
EXIT
Will simply call System.exit(0); on JVM
STATUS
Will return OK\r\n to indicate ShutdownService is alive and ready to take commands.
PID
Will return PID of the running JVM from ProcessHandle.current().pid() on JVM
Since:
12.1.0
  • Field Details

  • Constructor Details

    • ShutdownService

      public ShutdownService(@Name("host") String host, @Name("port") int port, @Name("key") String key, @Name("exitVm") boolean exitVm)
      Create a new ShutdownService.
      Parameters:
      host - the host
      port - the port
      key - the key that must be passed to allow a shutdown
      exitVm - flag to exit vm on successful shutdown
  • Method Details

    • addComponent

      public void addComponent(LifeCycle component)
    • removeComponent

      public boolean removeComponent(LifeCycle component)
    • hasComponent

      public boolean hasComponent(LifeCycle component)
    • start

      public void start() throws Exception
      Throws:
      Exception
    • stop

      public void stop()
    • isExitVm

      public boolean isExitVm()
    • getHost

      public String getHost()
    • getKey

      public String getKey()
    • getPort

      public int getPort()
      Get the configured port.

      If configured for port 0, then the automatically allocated port is available on getLocalPort()

      Returns:
      the configured port
    • getLocalPort

      public int getLocalPort()
      Get the ServerSocket.getLocalPort() that this is listening on.
      Returns:
      the port that the server socket is listening on.
    • isListening

      public boolean isListening()
    • configure

      protected void configure(ServerSocket serverSocket) throws SocketException
      Configure the ServerSocket before binding.
      Parameters:
      serverSocket - the server socket.
      Throws:
      SocketException
    • bound

      protected void bound(ServerSocket serverSocket)
      Event triggered with the ServerSocket is bound.
      Parameters:
      serverSocket - the bound server socket.
    • toString

      public String toString()
      Overrides:
      toString in class Object