use of org.eclipse.jetty.util.component.Graceful in project jetty.project by eclipse.
the class Server method doStop.
/* ------------------------------------------------------------ */
@Override
protected void doStop() throws Exception {
if (isDumpBeforeStop())
dumpStdErr();
if (LOG.isDebugEnabled())
LOG.debug("doStop {}", this);
MultiException mex = new MultiException();
// list if graceful futures
List<Future<Void>> futures = new ArrayList<>();
// First close the network connectors to stop accepting new connections
for (Connector connector : _connectors) futures.add(connector.shutdown());
// Then tell the contexts that we are shutting down
Handler[] gracefuls = getChildHandlersByClass(Graceful.class);
for (Handler graceful : gracefuls) futures.add(((Graceful) graceful).shutdown());
// Shall we gracefully wait for zero connections?
long stopTimeout = getStopTimeout();
if (stopTimeout > 0) {
long stop_by = System.currentTimeMillis() + stopTimeout;
if (LOG.isDebugEnabled())
LOG.debug("Graceful shutdown {} by ", this, new Date(stop_by));
// Wait for shutdowns
for (Future<Void> future : futures) {
try {
if (!future.isDone())
future.get(Math.max(1L, stop_by - System.currentTimeMillis()), TimeUnit.MILLISECONDS);
} catch (Exception e) {
mex.add(e);
}
}
}
// Cancel any shutdowns not done
for (Future<Void> future : futures) if (!future.isDone())
future.cancel(true);
// Now stop the connectors (this will close existing connections)
for (Connector connector : _connectors) {
try {
connector.stop();
} catch (Throwable e) {
mex.add(e);
}
}
// And finally stop everything else
try {
super.doStop();
} catch (Throwable e) {
mex.add(e);
}
if (getStopAtShutdown())
ShutdownThread.deregister(this);
//Unregister the Server with the handler thread for receiving
//remote stop commands as we are stopped already
ShutdownMonitor.deregister(this);
mex.ifExceptionThrow();
}
Aggregations