Пример #1
0
  /**
   * Starts the <code>HttpServer</code>.
   *
   * @throws IOException if an error occurs while attempting to start the server.
   */
  public synchronized void start() throws IOException {

    if (state == State.RUNNING) {
      return;
    } else if (state == State.STOPPING) {
      throw new IllegalStateException(
          "The server is currently in pending"
              + " shutdown state. You have to either wait for shutdown to"
              + " complete or force it by calling shutdownNow()");
    }
    state = State.RUNNING;
    shutdownFuture = null;

    configureAuxThreadPool();

    delayedExecutor = new DelayedExecutor(auxExecutorService);
    delayedExecutor.start();

    for (final NetworkListener listener : listeners.values()) {
      configureListener(listener);
    }

    if (serverConfig.isJmxEnabled()) {
      enableJMX();
    }

    for (final NetworkListener listener : listeners.values()) {
      try {
        listener.start();
      } catch (IOException ioe) {
        if (LOGGER.isLoggable(Level.FINEST)) {
          LOGGER.log(
              Level.FINEST,
              "Failed to start listener [{0}] : {1}",
              new Object[] {listener.toString(), ioe.toString()});
          LOGGER.log(Level.FINEST, ioe.toString(), ioe);
        }

        throw ioe;
      }
    }

    setupHttpHandler();

    if (serverConfig.isJmxEnabled()) {
      for (final JmxEventListener l : serverConfig.getJmxEventListeners()) {
        l.jmxEnabled();
      }
    }

    if (LOGGER.isLoggable(Level.INFO)) {
      LOGGER.log(Level.INFO, "[{0}] Started.", getServerConfiguration().getName());
    }
  }
 protected void startDelayedExecutor() {
   if (delayedExecutor != null) {
     delayedExecutor.start();
   }
 }