Merge pull request #1563 from t-tsutsumi/pr/fix-graceful-shutdown

Graceful shutdown on Jetty requires StatisticsHandler
This commit is contained in:
Naoki Takezoe
2017-04-30 01:37:32 +09:00
committed by GitHub

View File

@@ -1,4 +1,6 @@
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import java.io.File; import java.io.File;
@@ -93,7 +95,9 @@ public class JettyLauncher {
context.setInitParameter("org.scalatra.ForceHttps", "true"); context.setInitParameter("org.scalatra.ForceHttps", "true");
} }
server.setHandler(context); Handler handler = addStatisticsHandler(context);
server.setHandler(handler);
server.setStopAtShutdown(true); server.setStopAtShutdown(true);
server.setStopTimeout(7_000); server.setStopTimeout(7_000);
server.start(); server.start();
@@ -122,4 +126,12 @@ public class JettyLauncher {
} }
dir.delete(); dir.delete();
} }
private static Handler addStatisticsHandler(Handler handler) {
// The graceful shutdown is implemented via the statistics handler.
// See the following: https://bugs.eclipse.org/bugs/show_bug.cgi?id=420142
final StatisticsHandler statisticsHandler = new StatisticsHandler();
statisticsHandler.setHandler(handler);
return statisticsHandler;
}
} }