diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index 6e5050d0883..63c0ed46413 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; + import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -46,6 +47,7 @@ import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.HandlerWrapper; +import org.eclipse.jetty.server.handler.StatisticsHandler; import org.eclipse.jetty.util.Attributes; import org.eclipse.jetty.util.AttributesMap; import org.eclipse.jetty.util.Jetty; @@ -142,6 +144,19 @@ public class Server extends HandlerWrapper implements Attributes return _stopAtShutdown; } + /* ------------------------------------------------------------ */ + /** + * Set a graceful stop time. + * The {@link StatisticsHandler} must be configured so that open connections can + * be tracked for a graceful shutdown. + * @see org.eclipse.jetty.util.component.ContainerLifeCycle#setStopTimeout(long) + */ + @Override + public void setStopTimeout(long stopTimeout) + { + super.setStopTimeout(stopTimeout); + } + /* ------------------------------------------------------------ */ public void setStopAtShutdown(boolean stop) { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java index 2794cfb1f9a..01ef24fecd5 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java @@ -79,6 +79,35 @@ public class GracefulStopTest Assert.assertThat(out,Matchers.containsString("200 OK")); } } + + @Test + public void testGracefulTimout() throws Exception + { + server.setStopTimeout(100); + new Thread() + { + @Override + public void run() + { + try + { + TimeUnit.SECONDS.sleep(1); + server.stop(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + }.start(); + + try(Socket socket = new Socket("localhost",server.getBean(NetworkConnector.class).getLocalPort());) + { + socket.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.ISO_8859_1)); + String out = IO.toString(socket.getInputStream()); + Assert.assertEquals("",out); + } + } private static class TestHandler extends AbstractHandler {