@Override
 public void stop() {
   LOG.debug("stop server");
   final LifecycleState state = m_server.getServer().getState();
   if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0
       && LifecycleState.DESTROYED.compareTo(state) >= 0) {
     throw new IllegalStateException("stop already called!");
   } else {
     try {
       m_server.stop();
       m_server.destroy();
     } catch (final Throwable e) {
       // throw new ServerStopException(
       // m_server.getServer().getInfo(), e );
       LOG.error("LifecycleException caught {}", e);
     }
   }
 }
Пример #2
0
  /** Stop an existing server instance. */
  public void stop() {

    try {
      // Remove the ShutdownHook first so that server.stop()
      // doesn't get invoked twice
      if (useShutdownHook) {
        Runtime.getRuntime().removeShutdownHook(shutdownHook);

        // If JULI is being used, re-enable JULI's shutdown to ensure
        // log messages are not lost
        LogManager logManager = LogManager.getLogManager();
        if (logManager instanceof ClassLoaderLogManager) {
          ((ClassLoaderLogManager) logManager).setUseShutdownHook(true);
        }
      }
    } catch (Throwable t) {
      ExceptionUtils.handleThrowable(t);
      // This will fail on JDK 1.2. Ignoring, as Tomcat can run
      // fine without the shutdown hook.
    }

    // Shut down the server
    try {
      Server s = getServer();
      LifecycleState state = s.getState();
      if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0
          && LifecycleState.DESTROYED.compareTo(state) >= 0) {
        // Nothing to do. stop() was already called
      } else {
        s.stop();
        s.destroy();
      }
    } catch (LifecycleException e) {
      log.error("Catalina.stop", e);
    }
  }