@Override public boolean getAvailable(Context context) { return context.getState().isAvailable(); }
private void rethrowDeferredStartupExceptions() throws Exception { Container[] children = this.tomcat.getHost().findChildren(); for (Container container : children) { if (container instanceof TomcatEmbeddedContext) { TomcatStarter tomcatStarter = ((TomcatEmbeddedContext) container) .getStarter(); if (tomcatStarter != null) { Exception exception = tomcatStarter.getStartUpException(); if (exception != null) { throw exception; } } } if (!LifecycleState.STARTED.equals(container.getState())) { throw new IllegalStateException(container + " failed to start"); } } }
/** * Provides a mechanism for sub-classes to update the component state. * Calling this method will automatically fire any associated * {@link Lifecycle} event. * * @param state The new state for this component * @param data The data to pass to the associated {@link Lifecycle} event */ protected synchronized void setState(LifecycleState state, Object data) { if (log.isDebugEnabled()) { log.debug(sm.getString("lifecycleBase.setState", this, state)); } this.state = state; String lifecycleEvent = state.getLifecycleEvent(); if (lifecycleEvent != null) { fireLifecycleEvent(lifecycleEvent, data); } }
if (getState().isAvailable() && (oldLoader != null) && (oldLoader instanceof Lifecycle)) { try { ((Lifecycle) oldLoader).stop(); } catch (LifecycleException e) { log.error(sm.getString("standardContext.setLoader.stop"), e); if (getState().isAvailable() && (loader != null) && (loader instanceof Lifecycle)) { try { ((Lifecycle) loader).start(); } catch (LifecycleException e) { log.error(sm.getString("standardContext.setLoader.start"), e);
/** * Register host. */ private void registerHost(Host host) { String[] aliases = host.findAliases(); mapper.addHost(host.getName(), aliases, host); for (Container container : host.findChildren()) { if (container.getState().isAvailable()) { registerContext((Context) container); } } if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerHost", host.getName(), domain, service)); } }
private void addChildInternal(Container child) { if( log.isDebugEnabled() ) log.debug("Add child " + child + " " + this); synchronized(children) { if (children.get(child.getName()) != null) throw new IllegalArgumentException("addChild: Child name '" + child.getName() + "' is not unique"); child.setParent(this); // May throw IAE children.put(child.getName(), child); } // Start child // Don't do this inside sync block - start can be a slow process and // locking the children object can cause problems elsewhere if ((getState().isAvailable() || LifecycleState.STARTING_PREP.equals(getState())) && startChildren) { try { child.start(); } catch (LifecycleException e) { log.error("ContainerBase.addChild: start: ", e); throw new IllegalStateException ("ContainerBase.addChild: start: " + e); } } fireContainerEvent(ADD_CHILD_EVENT, child); }
@Override public Set<String> setServletSecurity(ServletSecurityElement constraint) { if (constraint == null) { throw new IllegalArgumentException(sm.getString( "applicationServletRegistration.setServletSecurity.iae", getName(), context.getName())); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString( "applicationServletRegistration.setServletSecurity.ise", getName(), context.getName())); } this.constraint = constraint; return context.addServletSecurity(this, constraint); }
@Override public void setRequestCharacterEncoding(String encoding) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException( sm.getString("applicationContext.setRequestEncoding.ise", getContextPath())); } context.setRequestCharacterEncoding(encoding); }
private void addChildInternal(Container child) { if( log.isDebugEnabled() ) log.debug("Add child " + child + " " + this); synchronized(children) { if (children.get(child.getName()) != null) throw new IllegalArgumentException( sm.getString("containerbase.child.notUnique", child.getName())); child.setParent(this); // May throw IAE children.put(child.getName(), child); } // Start child // Don't do this inside sync block - start can be a slow process and // locking the children object can cause problems elsewhere try { if ((getState().isAvailable() || LifecycleState.STARTING_PREP.equals(getState())) && startChildren) { child.start(); } } catch (LifecycleException e) { throw new IllegalStateException(sm.getString("containerbase.child.start"), e); } finally { fireContainerEvent(ADD_CHILD_EVENT, child); } }
private void reload(DeployedApplication app) { if(log.isInfoEnabled()) log.info(sm.getString("hostConfig.reload", app.name)); Context context = (Context) host.findChild(app.name); if (context.getState().isAvailable()) { // Reload catches and logs exceptions context.reload(); } else { // If the context was not started (for example an error // in web.xml) we'll still get to try to start try { context.start(); } catch (Exception e) { log.warn(sm.getString ("hostConfig.context.restart", app.name), e); } } }
/** * 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)); }
protected void checkStateForResourceLoading(String resource) throws IllegalStateException { // It is not permitted to load resources once the web application has // been stopped. if (!state.isAvailable()) { String msg = sm.getString("webappClassLoader.stopped", resource); IllegalStateException ise = new IllegalStateException(msg); log.info(msg, ise); throw ise; } }
if (getState().isAvailable()) { try { ((Lifecycle) valve).stop(); } catch (LifecycleException e) { log.error(sm.getString("standardPipeline.valve.stop"), e); ((Lifecycle) valve).destroy(); } catch (LifecycleException e) { log.error(sm.getString("standardPipeline.valve.destroy"), e); container.fireContainerEvent(Container.REMOVE_VALVE_EVENT, valve);
if (getState().isAvailable()) { if (valve instanceof Lifecycle) { try { ((Lifecycle) valve).start(); } catch (LifecycleException e) { log.error(sm.getString("standardPipeline.valve.start"), e); container.fireContainerEvent(Container.ADD_VALVE_EVENT, valve);
/** * Start the background thread that will periodically check for * session timeouts. */ protected void threadStart() { if (backgroundProcessorDelay > 0 && (getState().isAvailable() || LifecycleState.STARTING_PREP.equals(getState())) && (backgroundProcessorFuture == null || backgroundProcessorFuture.isDone())) { if (backgroundProcessorFuture != null && backgroundProcessorFuture.isDone()) { // There was an error executing the scheduled task, get it and log it try { backgroundProcessorFuture.get(); } catch (InterruptedException | ExecutionException e) { log.error(sm.getString("containerBase.backgroundProcess.error"), e); } } backgroundProcessorFuture = Container.getService(this).getServer().getUtilityExecutor() .scheduleWithFixedDelay(new ContainerBackgroundProcessor(), backgroundProcessorDelay, backgroundProcessorDelay, TimeUnit.SECONDS); } }
/** * Removes an executor from the service * @param ex Executor */ @Override public void removeExecutor(Executor ex) { synchronized (executors) { if ( executors.remove(ex) && getState().isAvailable() ) { try { ex.stop(); } catch (LifecycleException e) { log.error(sm.getString("standardService.executor.stop"), e); } } } }
private void writeDeployResult(PrintWriter writer, StringManager smClient, String name, String displayPath) { Context deployed = (Context) host.findChild(name); if (deployed != null && deployed.getConfigured() && deployed.getState().isAvailable()) { writer.println(smClient.getString( "managerServlet.deployed", displayPath)); } else if (deployed!=null && !deployed.getState().isAvailable()) { writer.println(smClient.getString( "managerServlet.deployedButNotStarted", displayPath)); } else { // Something failed writer.println(smClient.getString( "managerServlet.deployFailed", displayPath)); } }