Class ShutdownService
java.lang.Object
org.eclipse.jetty.server.ShutdownService
- Direct Known Subclasses:
ShutdownMonitor
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 receiveStopped\r\nafter stop, and before exit. STOPEXIT- Will stop components by calling
LifeCycle.stop(),
(Each component that is aDestroyablewill also bedestroyed) followed bySystem.exit(0);at the end.
Will receiveStopped\r\nafter stop/destroy, and before exit. EXIT- Will simply call
System.exit(0);on JVM STATUS- Will return
OK\r\nto 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 Summary
FieldsModifier and TypeFieldDescriptionprotected final List<org.eclipse.jetty.util.component.LifeCycle> protected final org.eclipse.jetty.util.thread.AutoLock -
Constructor Summary
ConstructorsConstructorDescriptionShutdownService(String host, int port, String key, boolean exitVm) Create a new ShutdownService. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddComponent(org.eclipse.jetty.util.component.LifeCycle component) protected voidbound(ServerSocket serverSocket) Event triggered with the ServerSocket is bound.protected voidconfigure(ServerSocket serverSocket) Configure the ServerSocket before binding.getHost()getKey()intGet theServerSocket.getLocalPort()that this is listening on.intgetPort()Get the configured port.booleanhasComponent(org.eclipse.jetty.util.component.LifeCycle component) booleanisExitVm()booleanbooleanremoveComponent(org.eclipse.jetty.util.component.LifeCycle component) voidstart()voidstop()toString()
-
Field Details
-
lock
protected final org.eclipse.jetty.util.thread.AutoLock lock -
components
-
-
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 hostport- the portkey- the key that must be passed to allow a shutdownexitVm- flag to exit vm on successful shutdown
-
-
Method Details
-
addComponent
public void addComponent(org.eclipse.jetty.util.component.LifeCycle component) -
removeComponent
public boolean removeComponent(org.eclipse.jetty.util.component.LifeCycle component) -
hasComponent
public boolean hasComponent(org.eclipse.jetty.util.component.LifeCycle component) -
start
-
stop
public void stop() -
isExitVm
public boolean isExitVm() -
getHost
-
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 theServerSocket.getLocalPort()that this is listening on.- Returns:
- the port that the server socket is listening on.
-
isListening
public boolean isListening() -
configure
Configure the ServerSocket before binding.- Parameters:
serverSocket- the server socket.- Throws:
SocketException
-
bound
Event triggered with the ServerSocket is bound.- Parameters:
serverSocket- the bound server socket.
-
toString
-