static TomcatService forConfig(TomcatServiceConfig config) { final Consumer<Connector> postStopTask = connector -> { final org.apache.catalina.Server server = connector.getService().getServer(); if (server.getState() == LifecycleState.STOPPED) { try { logger.info("Destroying an embedded Tomcat: {}", toString(server)); server.destroy(); } catch (Exception e) { logger.warn("Failed to destroy an embedded Tomcat: {}", toString(server), e); } } }; return new ManagedTomcatService(null, new ManagedConnectorFactory(config), postStopTask); }
void start() throws Exception { assert hostName() != null; started = false; connector = connectorFactory.apply(hostName()); final Service service = connector.getService(); final Engine engine = TomcatUtil.engine(service, hostName()); final String engineName = engine.getName(); if (activeEngines.contains(engineName)) { throw new TomcatServiceException("duplicate engine name: " + engineName); } server = service.getServer(); if (!TOMCAT_START_STATES.contains(server.getState())) { logger.info("Starting an embedded Tomcat: {}", toString(server)); server.start(); started = true; } else { throw new TomcatServiceException("Cannot manage already running server: " + engineName); } activeEngines.add(engineName); this.engineName = engineName; }
void terminate() { if (tomcat.getServer().getState().isAvailable()) { try { tomcat.stop(); tomcat.destroy(); } catch (Exception e) { Loggers.get(EmbeddedTomcat.class).error("Fail to stop web server", e); } } deleteQuietly(tomcatBasedir()); }
private void destroy(Tomcat tomcat) throws LifecycleException, InterruptedException { tomcat.destroy(); long deadline = System.currentTimeMillis() + 10000; do { switch(tomcat.getServer().getState()) { case DESTROYED: case FAILED: return; default : { } } Thread.sleep(10); } while(deadline > System.currentTimeMillis()); }
private void stop(Tomcat tomcat) throws LifecycleException, InterruptedException { tomcat.stop(); long deadline = System.currentTimeMillis() + 10000; do { switch(tomcat.getServer().getState()) { case STOPPED: case DESTROYING: case DESTROYED: case FAILED: return; default : { } } Thread.sleep(10); } while(deadline > System.currentTimeMillis()); }
/** * Wait for TOMCAT to stop. * * @throws LifecycleException life cycle exception occurred */ protected void waitForTomcatToStop() throws LifecycleException { int i = 0; while (tomcat.getServer().getState() != LifecycleState.STOPPED) { waitInterval(); if (i++ > 10) { throw new IllegalStateException("Timeout waiting for TOMCAT to stop"); } } }
private void start(Tomcat tomcat) throws InterruptedException, LifecycleException { tomcat.start(); long deadline = System.currentTimeMillis() + 10000; do { switch(tomcat.getServer().getState()) { case NEW: case INITIALIZING: case INITIALIZED: case STARTING_PREP: case STARTING: Thread.sleep(10); continue; default : break; } break; } while(deadline > System.currentTimeMillis()); }
/** * Wait for TOMCAT to start. * * @throws LifecycleException life cycle exception occurred */ protected void waitForTomcatToStart() throws LifecycleException { int i = 0; while (tomcat.getServer().getState() != LifecycleState.STARTED) { waitInterval(); if (i++ > 10) { tomcat.stop(); throw new IllegalStateException("Timeout waiting for TOMCAT to start"); } } }
private void waitForTomcatLifecycleState(LifecycleState s) throws InterruptedException { final Object mutex = new Object(); final LifecycleState state = s; tomcat.getServer().addLifecycleListener(new LifecycleListener() { @Override public void lifecycleEvent(LifecycleEvent event) { if (event.getLifecycle().getState() == state) { synchronized (mutex) { tomcat.getServer().removeLifecycleListener(this); mutex.notify(); } } } }); synchronized (mutex) { while (tomcat.getServer().getState() != state) mutex.wait(); } }
/** * Process a "destroy" event for this Context. */ protected synchronized void destroy() { // Called from StandardContext.destroy() if (log.isDebugEnabled()) log.debug(sm.getString("contextConfig.destroy")); // Skip clearing the work directory if Tomcat is being shutdown Server s = getServer(); if (s != null && !s.getState().isAvailable()) { return; } // Changed to getWorkPath per Bugzilla 35819. String workDir = ((StandardContext) context).getWorkPath(); if (workDir != null) ExpandWar.delete(new File(workDir)); }
/** * Process a "destroy" event for this Context. */ protected synchronized void destroy() { // Called from StandardContext.destroy() if (log.isDebugEnabled()) { log.debug(sm.getString("contextConfig.destroy")); } // Skip clearing the work directory if Tomcat is being shutdown Server s = getServer(); if (s != null && !s.getState().isAvailable()) { return; } // Changed to getWorkPath per Bugzilla 35819. if (context instanceof StandardContext) { String workDir = ((StandardContext) context).getWorkPath(); if (workDir != null) { ExpandWar.delete(new File(workDir)); } } }
LifecycleState state = s.getState(); if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0 && LifecycleState.DESTROYED.compareTo(state) >= 0) {
/** * Process a "destroy" event for this Context. */ protected synchronized void destroy() { // Called from StandardContext.destroy() if (log.isDebugEnabled()) { log.debug(sm.getString("contextConfig.destroy")); } // Skip clearing the work directory if Tomcat is being shutdown Server s = getServer(); if (s != null && !s.getState().isAvailable()) { return; } // Changed to getWorkPath per Bugzilla 35819. if (context instanceof StandardContext) { String workDir = ((StandardContext) context).getWorkPath(); if (workDir != null) { ExpandWar.delete(new File(workDir)); } } }
/** * Process a "destroy" event for this Context. */ protected synchronized void destroy() { // Called from StandardContext.destroy() if (log.isDebugEnabled()) { log.debug(sm.getString("contextConfig.destroy")); } // Skip clearing the work directory if Tomcat is being shutdown Server s = getServer(); if (s != null && !s.getState().isAvailable()) { return; } // Changed to getWorkPath per Bugzilla 35819. if (context instanceof StandardContext) { String workDir = ((StandardContext) context).getWorkPath(); if (workDir != null) { ExpandWar.delete(new File(workDir)); } } }
LifecycleState state = s.getState(); if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0 && LifecycleState.DESTROYED.compareTo(state) >= 0) {
/** * Process a "destroy" event for this Context. */ protected synchronized void destroy() { // Called from StandardContext.destroy() if (log.isDebugEnabled()) log.debug(sm.getString("contextConfig.destroy")); // Skip clearing the work directory if Tomcat is being shutdown Server s = getServer(); if (s != null && !s.getState().isAvailable()) { return; } // Changed to getWorkPath per Bugzilla 35819. if (context instanceof StandardContext) { String workDir = ((StandardContext) context).getWorkPath(); if (workDir != null) { ExpandWar.delete(new File(workDir)); } } }
void terminate() { if (tomcat.getServer().getState().isAvailable()) { try { tomcat.stop(); tomcat.destroy(); } catch (Exception e) { Loggers.get(EmbeddedTomcat.class).error("Fail to stop web server", e); } } deleteQuietly(tomcatBasedir()); }
private void stop(final Tomcat tomcat) throws LifecycleException { if (LifecycleState.STARTED.equals(tomcat.getServer().getState())) { tomcat.stop(); tomcat.destroy(); } }