Added javadoc with shutdown example

This commit is contained in:
Jesse McConnell 2011-10-06 15:59:14 -05:00
parent 15ae01d4b6
commit 4ca2828ace
1 changed files with 24 additions and 7 deletions

View File

@ -34,13 +34,30 @@ import org.eclipse.jetty.util.log.Logger;
* Usage: * Usage:
* *
* <pre> * <pre>
* Server server = new Server(8080); Server server = new Server(8080);
* HandlerList handlers = new HandlerList(); HandlerList handlers = new HandlerList();
* handlers.setHandlers(new Handler[] handlers.setHandlers(new Handler[]
* { someOtherHandler, new ShutdownHandler(server,&quot;secret password&quot;) }); { someOtherHandler, new ShutdownHandler(server,&quot;secret password&quot;) });
* server.setHandler(handlers); server.setHandler(handlers);
* server.start(); server.start();
* </pre> </pre>
*
<pre>
public static void attemptShutdown(int port, String shutdownCookie) {
try {
URL url = new URL("http://localhost:" + port + "/shutdown?cookie=" + 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);
}
}
</pre>
*/ */
public class ShutdownHandler extends AbstractHandler public class ShutdownHandler extends AbstractHandler
{ {