use of org.apache.catalina.Lifecycle in project Payara by payara.
the class ContainerBase method setManager.
/**
* Set the Manager with which this Container is associated.
*
* @param manager The newly associated Manager
*/
@Override
public void setManager(Manager manager) {
Manager oldManager;
try {
writeLock.lock();
// Change components if necessary
oldManager = this.manager;
if (oldManager == manager)
return;
this.manager = manager;
// Stop the old component if necessary
if (started && (oldManager != null) && (oldManager instanceof Lifecycle)) {
try {
((Lifecycle) oldManager).stop();
} catch (LifecycleException e) {
log.log(Level.SEVERE, LogFacade.CONTAINER_BASE_SET_MANAGER_STOP, e);
}
}
// Start the new component if necessary
if (manager != null)
manager.setContainer(this);
if (started && (manager != null) && (manager instanceof Lifecycle)) {
try {
((Lifecycle) manager).start();
} catch (LifecycleException e) {
log.log(Level.SEVERE, LogFacade.CONTAINER_BASE_SET_MANAGER_START, e);
}
}
} finally {
writeLock.unlock();
}
// Report this property change to interested listeners
support.firePropertyChange("manager", oldManager, this.manager);
}
use of org.apache.catalina.Lifecycle in project Payara by payara.
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) {
Loader oldLoader;
try {
writeLock.lock();
// Change components if necessary
oldLoader = this.loader;
if (oldLoader == loader)
return;
this.loader = loader;
// Stop the old component if necessary
if (started && (oldLoader != null) && (oldLoader instanceof Lifecycle)) {
try {
((Lifecycle) oldLoader).stop();
} catch (LifecycleException e) {
log.log(Level.SEVERE, LogFacade.CONTAINER_BASE_SET_LOADER_STOP, e);
}
}
// Start the new component if necessary
if (loader != null)
loader.setContainer(this);
if (started && (loader != null) && (loader instanceof Lifecycle)) {
try {
((Lifecycle) loader).start();
} catch (LifecycleException e) {
log.log(Level.SEVERE, LogFacade.CONTAINER_BASE_SET_LOADER_START, e);
}
}
} finally {
writeLock.unlock();
}
// Report this property change to interested listeners
support.firePropertyChange("loader", oldLoader, this.loader);
}
use of org.apache.catalina.Lifecycle in project Payara by payara.
the class LifecycleListenerRule method begin.
// --------------------------------------------------------- Public Methods
/**
* Handle the beginning of an XML element.
*
* @param attributes The attributes of this element
*
* @exception Exception if a processing error occurs
*/
public void begin(Attributes attributes) throws Exception {
// Instantiate a new LifecyleListener implementation object
String className = listenerClass;
if (attributeName != null) {
String value = attributes.getValue(attributeName);
if (value != null)
className = value;
}
Class clazz = Class.forName(className);
LifecycleListener listener = (LifecycleListener) clazz.newInstance();
// Add this LifecycleListener to our associated component
Lifecycle lifecycle = (Lifecycle) digester.peek();
lifecycle.addLifecycleListener(listener);
}
use of org.apache.catalina.Lifecycle in project Payara by payara.
the class StandardContext method alternateResourcesStop.
/**
* Stops this context's alternate doc base resources.
*/
public boolean alternateResourcesStop() {
boolean ok = true;
if (alternateDocBases == null || alternateDocBases.isEmpty()) {
return ok;
}
for (AlternateDocBase alternateDocBase : alternateDocBases) {
final DirContext alternateResources = ContextsAdapterUtility.unwrap(alternateDocBase.getResources());
if (alternateResources instanceof Lifecycle) {
try {
((Lifecycle) alternateResources).stop();
} catch (Throwable t) {
log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
ok = false;
}
}
final DirContext alternateWebappResources = ContextsAdapterUtility.unwrap(alternateDocBase.getWebappResources());
if (alternateWebappResources instanceof BaseDirContext) {
try {
((BaseDirContext) alternateWebappResources).release();
} catch (Throwable t) {
log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
ok = false;
}
}
}
this.alternateDocBases = null;
return (ok);
}
use of org.apache.catalina.Lifecycle in project tomcat 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<>();
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
Realm realm = getRealmInternal();
if (realm instanceof Lifecycle) {
((Lifecycle) realm).stop();
}
Cluster cluster = getClusterInternal();
if (cluster instanceof Lifecycle) {
((Lifecycle) cluster).stop();
}
}
Aggregations