예제 #1
0
  /** Stops Jetty. */
  private void stopJetty() {
    // Jetty does not really stop the server if port is busy.
    try {
      if (httpSrv != null) {
        // If server was successfully started, deregister ports.
        if (httpSrv.isStarted()) ctx.ports().deregisterPorts(getClass());

        // Record current interrupted status of calling thread.
        boolean interrupted = Thread.interrupted();

        try {
          httpSrv.stop();
        } finally {
          // Reset interrupted flag on calling thread.
          if (interrupted) Thread.currentThread().interrupt();
        }
      }
    } catch (InterruptedException ignored) {
      if (log.isDebugEnabled()) log.debug("Thread has been interrupted.");

      Thread.currentThread().interrupt();
    } catch (Exception e) {
      U.error(log, "Failed to stop Jetty HTTP server.", e);
    }
  }
예제 #2
0
  /**
   * @throws GridException If failed.
   * @return {@code True} if Jetty started.
   */
  @SuppressWarnings("IfMayBeConditional")
  private boolean startJetty() throws GridException {
    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 (SocketException ignore) {
      if (log.isDebugEnabled()) log.debug("Failed to bind HTTP server to configured port.");

      stopJetty();

      return false;
    } catch (MultiException e) {
      if (log.isDebugEnabled()) log.debug("Caught multi exception: " + e);

      for (Object obj : e.getThrowables())
        if (!(obj instanceof SocketException))
          throw new GridException("Failed to start Jetty HTTP server.", e);

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

      stopJetty();

      return false;
    } catch (Exception e) {
      throw new GridException("Failed to start Jetty HTTP server.", e);
    }
  }