use of org.apache.catalina.Lifecycle in project Payara by payara.
the class StandardContext method createWrapper.
/**
* Factory method to create and return a new Wrapper instance, of
* the Java implementation class appropriate for this Context
* implementation. The constructor of the instantiated Wrapper
* will have been called, but no properties will have been set.
* @return
*/
@Override
public Wrapper createWrapper() {
Wrapper wrapper = new StandardWrapper();
synchronized (instanceListeners) {
for (String instanceListener : instanceListeners) {
try {
Class clazz = Class.forName(instanceListener);
wrapper.addInstanceListener((InstanceListener) clazz.newInstance());
} catch (Throwable t) {
String msg = MessageFormat.format(rb.getString(LogFacade.CREATING_INSTANCE_LISTENER_EXCEPTION), instanceListener);
log.log(Level.SEVERE, msg, t);
return (null);
}
}
}
synchronized (instanceListenerInstances) {
for (InstanceListener instanceListenerInstance : instanceListenerInstances) {
wrapper.addInstanceListener(instanceListenerInstance);
}
}
Iterator<String> i = wrapperLifecycles.iterator();
while (i.hasNext()) {
String wrapperLifecycle = i.next();
try {
Class clazz = Class.forName(wrapperLifecycle);
if (wrapper instanceof Lifecycle) {
((Lifecycle) wrapper).addLifecycleListener((LifecycleListener) clazz.newInstance());
}
} catch (Throwable t) {
String msg = MessageFormat.format(rb.getString(LogFacade.CREATING_LIFECYCLE_LISTENER_EXCEPTION), wrapperLifecycle);
log.log(Level.SEVERE, msg, t);
return (null);
}
}
i = wrapperListeners.iterator();
while (i.hasNext()) {
String wrapperListener = i.next();
try {
Class clazz = Class.forName(wrapperListener);
wrapper.addContainerListener((ContainerListener) clazz.newInstance());
} catch (Throwable t) {
String msg = MessageFormat.format(rb.getString(LogFacade.CREATING_CONTAINER_LISTENER_EXCEPTION), wrapperListener);
log.log(Level.SEVERE, msg, t);
return (null);
}
}
return (wrapper);
}
use of org.apache.catalina.Lifecycle in project Payara by payara.
the class StandardContext method start.
/**
* Start this Context component.
*
* @exception LifecycleException if a startup error occurs
*/
@Override
public synchronized void start() throws LifecycleException {
if (started) {
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO, LogFacade.CONTAINER_ALREADY_STARTED_EXCEPTION, logName());
}
return;
}
long startupTimeStart = System.currentTimeMillis();
if (!initialized) {
try {
init();
} catch (Exception ex) {
throw new LifecycleException("Error initializaing ", ex);
}
}
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Starting " + ("".equals(getName()) ? "ROOT" : getName()));
}
// Set JMX object name for proper pipeline registration
preRegisterJMX();
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
setAvailable(false);
setConfigured(false);
// Add missing components as necessary
if (webappResources == null) {
// (1) Required by Loader
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Configuring default Resources");
}
try {
if ((docBase != null) && (docBase.endsWith(".war")) && (!(new File(docBase).isDirectory())))
setResources(new WARDirContext());
else
setResources(new WebDirContext());
} catch (IllegalArgumentException e) {
throw new LifecycleException(rb.getString(LogFacade.INIT_RESOURCES_EXCEPTION), e);
}
}
resourcesStart();
// Add alternate resources
if (alternateDocBases != null && !alternateDocBases.isEmpty()) {
for (AlternateDocBase alternateDocBase : alternateDocBases) {
String docBase = alternateDocBase.getDocBase();
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Configuring alternate resources");
}
try {
if (docBase != null && docBase.endsWith(".war") && (!(new File(docBase).isDirectory()))) {
setAlternateResources(alternateDocBase, new WARDirContext());
} else {
setAlternateResources(alternateDocBase, new FileDirContext());
}
} catch (IllegalArgumentException e) {
throw new LifecycleException(rb.getString(LogFacade.INIT_RESOURCES_EXCEPTION), e);
}
}
alternateResourcesStart();
}
if (getLoader() == null) {
createLoader();
}
// Initialize character set mapper
getCharsetMapper();
// Post work directory
postWorkDirectory();
// Validate required extensions
try {
ExtensionValidator.validateApplication(getResources(), this);
} catch (IOException ioe) {
String msg = MessageFormat.format(rb.getString(LogFacade.DEPENDENCY_CHECK_EXCEPTION), this);
throw new LifecycleException(msg, ioe);
}
// Reading the "catalina.useNaming" environment variable
String useNamingProperty = System.getProperty("catalina.useNaming");
if ((useNamingProperty != null) && ("false".equals(useNamingProperty))) {
useNaming = false;
}
if (isUseNaming()) {
if (namingContextListener == null) {
namingContextListener = new NamingContextListener();
namingContextListener.setDebug(getDebug());
namingContextListener.setName(getNamingContextName());
addLifecycleListener(namingContextListener);
}
}
// Binding thread
// START OF SJSAS 8.1 6174179
// ClassLoader oldCCL = bindThread();
ClassLoader oldCCL = null;
try {
started = true;
// Start our subordinate components, if any
if ((loader != null) && (loader instanceof Lifecycle))
((Lifecycle) loader).start();
if ((logger != null) && (logger instanceof Lifecycle))
((Lifecycle) logger).start();
// Unbinding thread
// START OF SJSAS 8.1 6174179
// unbindThread(oldCCL);
// END OF SJSAS 8.1 6174179
// Binding thread
oldCCL = bindThread();
if ((realm != null) && (realm instanceof Lifecycle))
((Lifecycle) realm).start();
if ((resources != null) && (resources instanceof Lifecycle))
((Lifecycle) resources).start();
// Start our child containers, if any
for (Container child : findChildren()) {
if (child instanceof Lifecycle) {
((Lifecycle) child).start();
}
}
// if any
if (pipeline instanceof Lifecycle)
((Lifecycle) pipeline).start();
// START SJSAS 8.1 5049111
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(START_EVENT, null);
// END SJSAS 8.1 5049111
} catch (Throwable t) {
throw new LifecycleException(t);
} finally {
// Unbinding thread
unbindThread(oldCCL);
}
if (!getConfigured()) {
String msg = MessageFormat.format(rb.getString(LogFacade.STARTUP_CONTEXT_FAILED_EXCEPTION), getName());
throw new LifecycleException(msg);
}
// Store some required info as ServletContext attributes
postResources();
if (orderedLibs != null && !orderedLibs.isEmpty()) {
getServletContext().setAttribute(ServletContext.ORDERED_LIBS, orderedLibs);
context.setAttributeReadOnly(ServletContext.ORDERED_LIBS);
}
// Initialize associated mapper
mapper.setContext(getPath(), welcomeFiles, ContextsAdapterUtility.wrap(resources));
// Binding thread
oldCCL = bindThread();
try {
// Set up the context init params
mergeParameters();
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
// Support for pluggability : this has to be done before
// listener events are fired
callServletContainerInitializers();
// Configure and call application event listeners
contextListenerStart();
// Start manager
if ((manager != null) && (manager instanceof Lifecycle)) {
((Lifecycle) getManager()).start();
}
// Start ContainerBackgroundProcessor thread
super.threadStart();
// Configure and call application filters
filterStart();
// Load and initialize all "load on startup" servlets
loadOnStartup(findChildren());
} catch (Throwable t) {
log.log(Level.SEVERE, LogFacade.STARTUP_CONTEXT_FAILED_EXCEPTION, getName());
try {
stop();
} catch (Throwable tt) {
log.log(Level.SEVERE, LogFacade.CLEANUP_FAILED_EXCEPTION, tt);
}
throw new LifecycleException(t);
} finally {
// Unbinding thread
unbindThread(oldCCL);
}
// Set available status depending upon startup success
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, "Startup successfully completed");
}
setAvailable(true);
// JMX registration
registerJMX();
startTimeMillis = System.currentTimeMillis();
startupTime = startTimeMillis - startupTimeStart;
// Send j2ee.state.running notification
if (getObjectName() != null) {
Notification notification = new Notification("j2ee.state.running", this, sequenceNumber++);
sendNotification(notification);
}
// of files on startup
if (getLoader() instanceof WebappLoader) {
((WebappLoader) getLoader()).closeJARs(true);
}
}
use of org.apache.catalina.Lifecycle in project Payara by payara.
the class StandardContext method stop.
/**
* Stop this Context component.
*
* @param isShutdown true if this Context is being stopped as part
* of a domain shutdown (as opposed to an undeployment), and false otherwise
* @exception LifecycleException if a shutdown error occurs
*/
public synchronized void stop(boolean isShutdown) throws LifecycleException {
// Validate and update our current component state
if (!started) {
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO, LogFacade.CONTAINER_NOT_STARTED_EXCEPTION, logName());
}
return;
}
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);
// Send j2ee.state.stopping notification
if (this.getObjectName() != null) {
Notification notification = new Notification("j2ee.state.stopping", this, sequenceNumber++);
sendNotification(notification);
}
// Mark this application as unavailable while we shut down
setAvailable(false);
// Binding thread
ClassLoader oldCCL = bindThread();
try {
// Stop our child containers, if any
for (Container child : findChildren()) {
if (child instanceof Lifecycle) {
((Lifecycle) child).stop();
}
}
// Stop our filters
filterStop();
// Stop ContainerBackgroundProcessor thread
super.threadStop();
if ((manager != null) && (manager instanceof Lifecycle)) {
if (manager instanceof StandardManager) {
((StandardManager) manager).stop(isShutdown);
} else {
((Lifecycle) manager).stop();
}
}
/*
* Stop all ServletContextListeners. It is important that they
* are passed a ServletContext to their contextDestroyed() method
* that still has all its attributes set. In other words, it is
* important that we invoke these listeners before calling
* context.clearAttributes()
*/
contextListenerStop();
sessionListenerStop();
// Clear all application-originated servlet context attributes
if (context != null) {
context.clearAttributes();
}
/*
* Stop all event listeners, including those of type
* ServletContextAttributeListener. For the latter, it is
* important that we invoke them after calling
* context.clearAttributes, so that they receive the corresponding
* attribute removal events
*/
eventListenerStop();
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
// Stop the Valves in our pipeline (including the basic), if any
if (pipeline instanceof Lifecycle) {
((Lifecycle) pipeline).stop();
}
// Finalize our character set mapper
setCharsetMapper(null);
// Stop resources
resourcesStop();
alternateResourcesStop();
if ((realm != null) && (realm instanceof Lifecycle)) {
((Lifecycle) realm).stop();
}
if ((logger != null) && (logger instanceof Lifecycle)) {
((Lifecycle) logger).stop();
}
/* SJSAS 6347606
if ((loader != null) && (loader instanceof Lifecycle)) {
((Lifecycle) loader).stop();
}
*/
} catch (Throwable t) {
// if START_EVENT is processed successfully.
if (started) {
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else if (t instanceof LifecycleException) {
throw (LifecycleException) t;
} else {
throw new LifecycleException(t);
}
} finally {
// Unbinding thread
unbindThread(oldCCL);
/*
* Delay the stopping of the webapp classloader until this point,
* because unbindThread() calls the security-checked
* Thread.setContextClassLoader(), which may ask the current thread
* context classloader (i.e., the webapp classloader) to load
* Principal classes specified in the security policy file
*/
if ((loader != null) && (loader instanceof Lifecycle)) {
((Lifecycle) loader).stop();
}
// END SJSAS 6347606
}
// Send j2ee.state.stopped notification
if (this.getObjectName() != null) {
Notification notification = new Notification("j2ee.state.stopped", this, sequenceNumber++);
sendNotification(notification);
}
// Reset application context
context = null;
// This object will no longer be visible or used.
try {
resetContext();
} catch (Exception ex) {
String msg = MessageFormat.format(rb.getString(LogFacade.RESETTING_CONTEXT_EXCEPTION), this);
log.log(Level.SEVERE, msg, ex);
}
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);
if (log.isLoggable(Level.FINE))
log.log(Level.FINE, "Stopping complete");
if (oname != null) {
// Send j2ee.object.deleted notification
Notification notification = new Notification("j2ee.object.deleted", this, sequenceNumber++);
sendNotification(notification);
}
}
use of org.apache.catalina.Lifecycle in project Payara by payara.
the class SetParentClassLoaderRule method load.
/**
* Start a new server instance.
*/
public void load() {
initDirs();
// Before digester - it may be needed
initNaming();
// Create and execute our Digester
Digester digester = createStartDigester();
long t1 = System.currentTimeMillis();
Exception ex = null;
InputSource inputSource = null;
InputStream inputStream = null;
File file = null;
try {
file = configFile();
inputStream = new FileInputStream(file);
inputSource = new InputSource("file://" + file.getAbsolutePath());
} catch (Exception e) {
;
}
if (inputStream == null) {
try {
inputStream = getClass().getClassLoader().getResourceAsStream(getConfigFile());
inputSource = new InputSource(getClass().getClassLoader().getResource(getConfigFile()).toString());
} catch (Exception e) {
;
}
}
// Alternative: don't bother with xml, just create it manually.
if (inputStream == null) {
try {
inputStream = getClass().getClassLoader().getResourceAsStream("server-embed.xml");
inputSource = new InputSource(getClass().getClassLoader().getResource("server-embed.xml").toString());
} catch (Exception e) {
;
}
}
if (inputStream == null && file != null) {
String msg = MessageFormat.format(rb.getString(LogFacade.CANNOT_LOAD_SERVER_XML_EXCEPTION), file.getAbsolutePath());
log.log(Level.WARNING, msg);
return;
}
if (inputStream != null) {
try {
inputSource.setByteStream(inputStream);
digester.push(this);
digester.parse(inputSource);
} catch (Exception e) {
log.log(Level.WARNING, LogFacade.CATALINA_START_WARNING_EXCEPTION, e);
return;
} finally {
try {
inputStream.close();
} catch (IOException ioe) {
}
}
}
// Start the new server
if (server instanceof Lifecycle) {
try {
server.initialize();
} catch (LifecycleException e) {
log.log(Level.SEVERE, LogFacade.CATALINA_START_SEVERE_EXCEPTION, e);
}
}
if (log.isLoggable(Level.INFO)) {
long t2 = System.currentTimeMillis();
String msg = MessageFormat.format(rb.getString(LogFacade.INIT_PROCESSED_EXCEPTION), (t2 - t1));
log.log(Level.INFO, msg);
}
}
Aggregations