use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.
the class Server method doStart.
/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception {
// Create an error handler if there is none
if (_errorHandler == null)
_errorHandler = getBean(ErrorHandler.class);
if (_errorHandler == null)
setErrorHandler(new ErrorHandler());
if (_errorHandler instanceof ErrorHandler.ErrorPageMapper)
LOG.warn("ErrorPageMapper not supported for Server level Error Handling");
//with the shutdown handler thread.
if (getStopAtShutdown())
ShutdownThread.register(this);
//Register the Server with the handler thread for receiving
//remote stop commands
ShutdownMonitor.register(this);
//Start a thread waiting to receive "stop" commands.
// initialize
ShutdownMonitor.getInstance().start();
LOG.info("jetty-" + getVersion());
if (!Jetty.STABLE) {
LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
LOG.warn("Download a stable release from http://download.eclipse.org/jetty/");
}
HttpGenerator.setJettyVersion(HttpConfiguration.SERVER_VERSION);
// Check that the thread pool size is enough.
SizedThreadPool pool = getBean(SizedThreadPool.class);
int max = pool == null ? -1 : pool.getMaxThreads();
int selectors = 0;
int acceptors = 0;
for (Connector connector : _connectors) {
if (connector instanceof AbstractConnector) {
AbstractConnector abstractConnector = (AbstractConnector) connector;
Executor connectorExecutor = connector.getExecutor();
if (connectorExecutor != pool) {
// the server level, because the connector uses a dedicated executor.
continue;
}
acceptors += abstractConnector.getAcceptors();
if (connector instanceof ServerConnector) {
// The SelectorManager uses 2 threads for each selector,
// one for the normal and one for the low priority strategies.
selectors += 2 * ((ServerConnector) connector).getSelectorManager().getSelectorCount();
}
}
}
int needed = 1 + selectors + acceptors;
if (max > 0 && needed > max)
throw new IllegalStateException(String.format("Insufficient threads: max=%d < needed(acceptors=%d + selectors=%d + request=1)", max, acceptors, selectors));
MultiException mex = new MultiException();
try {
super.doStart();
} catch (Throwable e) {
mex.add(e);
}
// start connectors last
for (Connector connector : _connectors) {
try {
connector.start();
} catch (Throwable e) {
mex.add(e);
}
}
if (isDumpAfterStart())
dumpStdErr();
mex.ifExceptionThrow();
LOG.info(String.format("Started @%dms", Uptime.getUptime()));
}
use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.
the class ContextHandler method stopContext.
/* ------------------------------------------------------------ */
protected void stopContext() throws Exception {
//stop all the handler hierarchy
super.doStop();
//Call the context listeners
ServletContextEvent event = new ServletContextEvent(_scontext);
Collections.reverse(_destroySerletContextListeners);
MultiException ex = new MultiException();
for (ServletContextListener listener : _destroySerletContextListeners) {
try {
callContextDestroyed(listener, event);
} catch (Exception x) {
ex.add(x);
}
}
ex.ifExceptionThrow();
}
use of org.eclipse.jetty.util.MultiException 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();
}
use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.
the class ServletHolderTest method testNoClassName.
@Test
public void testNoClassName() throws Exception {
try (StacklessLogging stackless = new StacklessLogging(ServletHandler.class, ContextHandler.class, ServletContextHandler.class)) {
ServletContextHandler context = new ServletContextHandler();
ServletHandler handler = context.getServletHandler();
ServletHolder holder = new ServletHolder();
holder.setName("foo");
holder.setForcedPath("/blah/");
handler.addServlet(holder);
handler.start();
Assert.fail("No class in ServletHolder");
} catch (UnavailableException e) {
Assert.assertTrue(e.getMessage().contains("foo"));
} catch (MultiException e) {
MultiException m = (MultiException) e;
Assert.assertTrue(m.getCause().getMessage().contains("foo"));
}
}
use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.
the class ServletHolderTest method testUnloadableClassName.
@Test
public void testUnloadableClassName() throws Exception {
try (StacklessLogging stackless = new StacklessLogging(BaseHolder.class, ServletHandler.class, ContextHandler.class, ServletContextHandler.class)) {
ServletContextHandler context = new ServletContextHandler();
ServletHandler handler = context.getServletHandler();
ServletHolder holder = new ServletHolder();
holder.setName("foo");
holder.setClassName("a.b.c.class");
handler.addServlet(holder);
handler.start();
Assert.fail("Unloadable class");
} catch (UnavailableException e) {
Assert.assertTrue(e.getMessage().contains("foo"));
} catch (MultiException e) {
MultiException m = (MultiException) e;
Assert.assertTrue(m.getCause().getMessage().contains("foo"));
}
}
Aggregations