public class ShutdownHandler extends HandlerWrapper
Server server = new Server(8080);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]
{ someOtherHandler, new ShutdownHandler("secret password") });
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);
}
}
AbstractLifeCycle.AbstractLifeCycleListenerLifeCycle.ListenerContainer.InheritedListener, Container.Listener_handler| Constructor and Description |
|---|
ShutdownHandler(Server server,
String shutdownToken)
Deprecated.
|
ShutdownHandler(String shutdownToken) |
ShutdownHandler(String shutdownToken,
boolean exitJVM,
boolean sendShutdownAtStart) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
String |
getShutdownToken() |
void |
handle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
Handle a request.
|
boolean |
isExitJvm() |
boolean |
isSendShutdownAtStart() |
void |
sendShutdown() |
void |
setExitJvm(boolean exitJvm) |
void |
setSendShutdownAtStart(boolean sendShutdownAtStart) |
destroy, expandChildren, getHandler, getHandlers, setHandler, setServerexpandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClassdoStop, dumpThis, getServeraddBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBeansaddLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop@Deprecated public ShutdownHandler(Server server, String shutdownToken)
server - the Jetty instance that should be shut downshutdownToken - a secret password to avoid unauthorized shutdown attemptspublic ShutdownHandler(String shutdownToken)
public ShutdownHandler(String shutdownToken, boolean exitJVM, boolean sendShutdownAtStart)
shutdownToken - sendShutdownAtStart - If true, a shutdown is sent as a HTTP post
during startup, which will shutdown any previously running instances of
this server with an identically configured ShutdownHandlerpublic void sendShutdown()
throws IOException
IOExceptionprotected void doStart()
throws Exception
ContainerLifeCycledoStart in class AbstractHandlerExceptionpublic void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
Handlerhandle in interface Handlerhandle in class HandlerWrappertarget - The target of the request - either a URI or a name.baseRequest - The original unwrapped request object.request - The request either as the Request
object or a wrapper of that request. The HttpChannel.getCurrentHttpChannel()
method can be used access the Request object if required.response - The response as the Response
object or a wrapper of that request. The HttpChannel.getCurrentHttpChannel()
method can be used access the Response object if required.IOExceptionServletExceptionpublic void setExitJvm(boolean exitJvm)
public boolean isSendShutdownAtStart()
public void setSendShutdownAtStart(boolean sendShutdownAtStart)
public String getShutdownToken()
public boolean isExitJvm()
Copyright © 1995-2015 Webtide. All Rights Reserved.