org.eclipse.jetty.util.MultiException Java Examples

The following examples show how to use org.eclipse.jetty.util.MultiException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommonStarter.java    From nem.deploy with MIT License 6 votes vote down vote up
private void startServer(final Server server, final URL stopURL) throws Exception {
	try {
		server.start();
	} catch (final MultiException e) {
		final long bindExceptions = e.getThrowables().stream().filter(t -> t instanceof BindException).count();

		if (bindExceptions > 0) {
			LOGGER.log(Level.WARNING, "Port already used, trying to shutdown other instance");
			// We assume it is already running?
			// Kill the old one
			this.stopOtherInstance(stopURL);

			// One more try
			LOGGER.log(Level.WARNING, "Re-trying to start server.");
			server.start();
		} else {
			LOGGER.log(Level.SEVERE, "Could not start server.", e);
			return;
		}
	}
	LOGGER.info(String.format("%s is ready to serve. URL is \"%s\".", CommonStarter.META_DATA.getAppName(), server.getURI()));
}
 
Example #2
Source File: GridJettyRestProtocol.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws IgniteCheckedException If failed.
 * @return {@code True} if Jetty started.
 */
private boolean startJetty() throws IgniteCheckedException {
    try {
        httpSrv.start();

        if (httpSrv.isStarted()) {
            for (Connector con : httpSrv.getConnectors()) {
                int connPort = ((NetworkConnector)con).getPort();

                if (connPort > 0)
                    ctx.ports().registerPort(connPort, TCP, getClass());
            }

            return true;
        }

        return false;
    }
    catch (Exception e) {
        boolean failedToBind = e instanceof SocketException;

        if (e instanceof MultiException) {
            if (log.isDebugEnabled())
                log.debug("Caught multi exception: " + e);

            failedToBind = true;

            for (Object obj : ((MultiException)e).getThrowables())
                if (!(obj instanceof SocketException))
                    failedToBind = false;
        }

        if (e instanceof IOException && X.hasCause(e, SocketException.class))
            failedToBind = true;

        if (failedToBind) {
            if (log.isDebugEnabled())
                log.debug("Failed to bind HTTP server to configured port.");

            stopJetty();
        }
        else
            throw new IgniteCheckedException("Failed to start Jetty HTTP server.", e);

        return false;
    }
}