use of org.apache.catalina.LifecycleException in project tomcat70 by apache.
the class ContainerBase method stopInternal.
/**
* Stop this component and implement the requirements
* of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
*
* @exception LifecycleException if this component detects a fatal error
* that prevents this component from being used
*/
@Override
protected synchronized void stopInternal() throws LifecycleException {
// Stop our thread
threadStop();
setState(LifecycleState.STOPPING);
// Stop the Valves in our pipeline (including the basic), if any
if (pipeline instanceof Lifecycle && ((Lifecycle) pipeline).getState().isAvailable()) {
((Lifecycle) pipeline).stop();
}
// Stop our child containers, if any
Container[] children = findChildren();
List<Future<Void>> results = new ArrayList<Future<Void>>();
for (int i = 0; i < children.length; i++) {
results.add(startStopExecutor.submit(new StopChild(children[i])));
}
boolean fail = false;
for (Future<Void> result : results) {
try {
result.get();
} catch (Exception e) {
log.error(sm.getString("containerBase.threadedStopFailed"), e);
fail = true;
}
}
if (fail) {
throw new LifecycleException(sm.getString("containerBase.threadedStopFailed"));
}
// Stop our subordinate components, if any
DirContext resources = getResourcesInternal();
if ((resources != null) && (resources instanceof Lifecycle)) {
((Lifecycle) resources).stop();
}
Realm realm = getRealmInternal();
if ((realm != null) && (realm instanceof Lifecycle)) {
((Lifecycle) realm).stop();
}
Cluster cluster = getClusterInternal();
if ((cluster != null) && (cluster instanceof Lifecycle)) {
((Lifecycle) cluster).stop();
}
Manager manager = getManagerInternal();
if ((manager != null) && (manager instanceof Lifecycle) && ((Lifecycle) manager).getState().isAvailable()) {
((Lifecycle) manager).stop();
}
Loader loader = getLoaderInternal();
if ((loader != null) && (loader instanceof Lifecycle)) {
((Lifecycle) loader).stop();
}
}
use of org.apache.catalina.LifecycleException in project tomcat70 by apache.
the class ContainerBase method setLoader.
/**
* Set the Loader with which this Container is associated.
*
* @param loader The newly associated loader
*/
@Override
public void setLoader(Loader loader) {
Lock writeLock = loaderLock.writeLock();
writeLock.lock();
Loader oldLoader = null;
try {
// Change components if necessary
oldLoader = this.loader;
if (oldLoader == loader)
return;
this.loader = loader;
// Stop the old component if necessary
if (getState().isAvailable() && (oldLoader != null) && (oldLoader instanceof Lifecycle)) {
try {
((Lifecycle) oldLoader).stop();
} catch (LifecycleException e) {
log.error("ContainerBase.setLoader: stop: ", e);
}
}
// Start the new component if necessary
if (loader != null)
loader.setContainer(this);
if (getState().isAvailable() && (loader != null) && (loader instanceof Lifecycle)) {
try {
((Lifecycle) loader).start();
} catch (LifecycleException e) {
log.error("ContainerBase.setLoader: start: ", e);
}
}
} finally {
writeLock.unlock();
}
// Report this property change to interested listeners
support.firePropertyChange("loader", oldLoader, loader);
}
use of org.apache.catalina.LifecycleException in project tomcat70 by apache.
the class ContainerBase method setCluster.
/**
* Set the Cluster with which this Container is associated.
*
* @param cluster The newly associated Cluster
*/
@Override
public void setCluster(Cluster cluster) {
Cluster oldCluster = null;
Lock writeLock = clusterLock.writeLock();
writeLock.lock();
try {
// Change components if necessary
oldCluster = this.cluster;
if (oldCluster == cluster)
return;
this.cluster = cluster;
// Stop the old component if necessary
if (getState().isAvailable() && (oldCluster != null) && (oldCluster instanceof Lifecycle)) {
try {
((Lifecycle) oldCluster).stop();
} catch (LifecycleException e) {
log.error("ContainerBase.setCluster: stop: ", e);
}
}
// Start the new component if necessary
if (cluster != null)
cluster.setContainer(this);
if (getState().isAvailable() && (cluster != null) && (cluster instanceof Lifecycle)) {
try {
((Lifecycle) cluster).start();
} catch (LifecycleException e) {
log.error("ContainerBase.setCluster: start: ", e);
}
}
} finally {
writeLock.unlock();
}
// Report this property change to interested listeners
support.firePropertyChange("cluster", oldCluster, cluster);
}
use of org.apache.catalina.LifecycleException in project tomcat70 by apache.
the class TestStandardContext method testWebappListenerConfigureFail.
@Test
public void testWebappListenerConfigureFail() throws Exception {
// Test that if LifecycleListener on webapp fails during
// configure_start event and if the cause of the failure is gone,
// the context can be started without a need to redeploy it.
// Set up a container
Tomcat tomcat = getTomcatInstance();
tomcat.start();
// To not start Context automatically, as we have to configure it first
((ContainerBase) tomcat.getHost()).setStartChildren(false);
FailingLifecycleListener listener = new FailingLifecycleListener();
File root = new File("test/webapp-3.0");
Context context = tomcat.addWebapp("", root.getAbsolutePath());
context.addLifecycleListener(listener);
try {
context.start();
Assert.fail();
} catch (LifecycleException ex) {
// As expected
}
Assert.assertEquals(LifecycleState.FAILED, context.getState());
// The second attempt
listener.setFail(false);
context.start();
Assert.assertEquals(LifecycleState.STARTED, context.getState());
// Using a test from testBug49922() to check that the webapp is running
ByteChunk result = getUrl("http://localhost:" + getPort() + "/bug49922/target");
Assert.assertEquals("Target", result.toString());
}
use of org.apache.catalina.LifecycleException in project tomcat70 by apache.
the class TestStandardContext method testWebappLoaderStartFail.
@Test
public void testWebappLoaderStartFail() throws Exception {
// Test that if WebappLoader start() fails and if the cause of
// the failure is gone, the context can be started without
// a need to redeploy it.
// Set up a container
Tomcat tomcat = getTomcatInstance();
tomcat.start();
// To not start Context automatically, as we have to configure it first
((ContainerBase) tomcat.getHost()).setStartChildren(false);
FailingWebappLoader loader = new FailingWebappLoader();
File root = new File("test/webapp-3.0");
Context context = tomcat.addWebapp("", root.getAbsolutePath());
context.setLoader(loader);
try {
context.start();
Assert.fail();
} catch (LifecycleException ex) {
// As expected
}
Assert.assertEquals(LifecycleState.FAILED, context.getState());
// The second attempt
loader.setFail(false);
context.start();
Assert.assertEquals(LifecycleState.STARTED, context.getState());
// Using a test from testBug49922() to check that the webapp is running
ByteChunk result = getUrl("http://localhost:" + getPort() + "/bug49922/target");
Assert.assertEquals("Target", result.toString());
}
Aggregations