439067 Javadoc for graceful server stop

This commit is contained in:
Greg Wilkins 2014-07-17 12:58:27 +10:00
parent 182436301b
commit 94ac37f8c2
2 changed files with 44 additions and 0 deletions

View File

@ -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)
{

View File

@ -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
{