ApplicationLifecyclepublic class ApplicationLifecycle extends Object implements com.sun.appserv.server.ServerLifecycleThis class implements the lifecycle methods used by the J2EE applications.
It is responsible for loading and shutting down the applications. |
Fields Summary |
---|
protected com.sun.enterprise.server.ServerContext | _context | protected ApplicationManager | _applicationMgr | protected StandAloneEJBModulesManager | _ejbMgr | protected StandAloneConnectorModulesManager | _connMgr | protected ConnectorResourcesLoader | _connectorResLoader | protected StandAloneAppClientModulesManager | _acMgr | protected DummyWebModuleManager | _webMgr | protected static Logger | _logger |
Methods Summary |
---|
public void | onInitialization(com.sun.enterprise.server.ServerContext sc)Server is initializing subsystems and setting up the runtime environment.
Prepare for the beginning of active use of the public methods of this
subsystem. This method is called before any of the public methods of
this subsystem are utilized.
// set system environment variables here
this._context = sc;
try {
// ---- J2EE APPLICATIONS ----------------------------------
// instance environment of this server instance
/*
InstanceEnvironment iEnv = sc.getInstanceEnvironment();
// shared class loader is used as the parent for the applications
ClassLoader sharedCL = sc.getSharedClassLoader();
AppsManager appsManager =
InstanceFactory.createAppsManager(iEnv, false);
*/
// manager for the j2ee applications
//this._applicationMgr = new ApplicationManager(appsManager,sharedCL);
this._applicationMgr = ManagerFactory.getApplicationManager();
// ---- STAND ALONE EJB MODULES --------------------------------
/*
// config manager for stand alone ejb modules
EjbModulesManager ejbModuleManager =
InstanceFactory.createEjbModuleManager(iEnv, false);
// manager for stand alone ejb modules
this._ejbMgr =
new StandAloneEJBModulesManager(ejbModuleManager, sharedCL);
*/
this._ejbMgr = ManagerFactory.getSAEJBModulesManager();
// ---- STAND ALONE Web MODULES --------------------------------
this._webMgr = ManagerFactory.getSAWebModulesManager();
// ---- STAND ALONE RAR MODULES --------------------------------
/*
// config manager for stand alone connector modules
ConnectorModulesManager connModuleManager =
InstanceFactory.createConnectorModuleManager(iEnv, false);
// manager for stand alone connector modules
this._connMgr = new StandAloneConnectorModulesManager(
connModuleManager, sharedCL);
*/
this._connMgr = ManagerFactory.getSAConnectorModulesManager();
this._connectorResLoader = new ConnectorResourcesLoader();
// ---- STAND ALONE APPLICATION CLIENT MODULES ----------------------
// manager for stand alone application client modules
this._acMgr = ManagerFactory.getSAACModulesManager();
} catch (ConfigException confEx) {
_logger.log(Level.SEVERE,
"core.config_exception_while_app_loading", confEx);
} catch (Throwable th) {
_logger.log(Level.SEVERE,
"core.unexpected_error_occured_while_app_loading", th);
}
| public void | onReady(com.sun.enterprise.server.ServerContext sc)Server has complted loading the applications and is ready to serve
requests.
try {
ApplicationRegistry registry = ApplicationRegistry.getInstance();
Collection containers = null;
if (registry != null) {
containers = registry.getAllEjbContainers();
}
// call onReady on all the ejb bean containers available
// in this server instance
if (containers != null) {
Iterator iter = containers.iterator();
while (iter.hasNext()) {
Container container = (Container) iter.next();
if (container != null) {
container.onReady();
}
}
}
_logger.log(Level.FINE, "core.application_onReady_complete");
} catch (Throwable th) {
_logger.log(Level.SEVERE,
"core.unexpected_error_occured_while_app_onready", th);
}
// Starts the dynamic reload monitor thread. This thread monitors the
// $APP_ROOT/.reload file of every applicatons and stand alone ejb
// module. If the time stamp of these files are updated, this thread
// sends a callback to the listeners for a dynamic reload.
//
// <p> Also starts the auto deploy monitor thread. This monitors the
// $INSTANCE/autodeploy directory for new archives to be deployed.
// server configuration context
ConfigContext configCtx = sc.getConfigContext();
// applicatons node from server configuration
Applications applicationsBean = null;
DasConfig dasConfig = null;
// flag used to turn on/off the dynamic monitor thread
boolean monitor = false;
try {
//ROB: config changes
//applicationsBean =
//(Applications)ConfigBeansFactory.getConfigBeanByXPath(configCtx,
// ServerXPathHelper.XPATH_APPLICATIONS);
dasConfig = ServerBeansFactory.getDasConfigBean(configCtx);
//monitor = applicationsBean.isDynamicReloadEnabled();
monitor = dasConfig.isDynamicReloadEnabled();
} catch (ConfigException ce) {
_logger.log(Level.SEVERE,
"core.config_exception_while_dynamic_reloading", ce);
monitor = false;
}
// starts the dynamic reload monitor thread only if it is on
if (monitor) {
// reload monitor is initialized in application loader
ReloadMonitor reloadMonitor = ReloadMonitor.getInstance(2000l);
reloadMonitor.start();
}
/* Nazrul: Auto Deploy will be included in a subsequent release
// FIXME: get it from the applicationsBean
//boolean autoDeploy = false;
boolean autoDeploy = true;
// start the auto deploy monitor is turned ON in server configuration
if (autoDeploy) {
// FIXME: get it from the applicationsBean
long monitorIntv = 2000l;
// monitors the auto deploy directory
AutoDeployMonitor adm = AutoDeployMonitor.getInstance(monitorIntv);
// instance environment for this server
InstanceEnvironment env = this.context.getInstanceEnvironment();
// auto deploy directory
File autoDeployDir = new File(env.getAutoDeployDirPath());
// handles auto deploy callbacks
AutoDeployer autoDeployer = new AutoDeployer();
// monitor entry for the auto deploy dir
MonitorableEntry entry =
new MonitorableEntry(autoDeployDir, autoDeployer);
adm.addMonitorableEntry(entry);
// starts auto deploy monitor
adm.start();
}
*/
ContainerFactory cf = Switch.getSwitch().getContainerFactory();
try {
cf.restoreEJBTimers();
} catch (Exception ex) {
_logger.log(Level.SEVERE,
"ApplicationLifeCycle.onReady():: exception when calling " +
"restoreEJBTimers()", ex);
}
| public void | onShutdown()Server is shutting down applications
if (this._applicationMgr == null) {
// not initialized
return;
}
try {
_logger.log(Level.INFO, "core.shutting_down_applications");
// first shuts down the dynamic reload monitor if running
this._applicationMgr.shutdown();
// application registry for this server instance
ApplicationRegistry registry = ApplicationRegistry.getInstance();
Collection containers = null;
if (registry != null) {
containers = registry.getAllEjbContainers();
}
// shuts down all the ejb bean containers available
// in this server instance
if (containers != null) {
Iterator iter = containers.iterator();
while (iter.hasNext()) {
Container container = (Container) iter.next();
if (container != null) {
container.onShutdown();
}
}
}
// After the applicationmanager shutdown, call stop method
// of all J2EE Connector 1.5 specification compliant, inbound and
// outbound resource adapters.
// This call to stop() of all deployed candidate connector modules
// is implemented in a concurrent fashion and this call times-out
// based on the shutdown-timeout-in-seconds attribute in domain.xml
_logger.log(Level.INFO, "core.shutting_down_resource_adapters");
this._connectorResLoader.stopActiveResourceAdapters();
_logger.log(Level.INFO, "core.ra_shutdown_complete");
_logger.log(Level.INFO, "core.application_shutdown_complete");
} catch (Throwable th) {
_logger.log(Level.SEVERE,
"core.unexpected_error_occured_while_app_shutdown", th);
}
| public void | onStartup(com.sun.enterprise.server.ServerContext sc)Server is starting up applications
try {
// Loads the ResourceAdapter Configurations
this._connectorResLoader.loadRAConfigs();
// loads all deployed stand alone connector modules
// stand alone connectors are loaded first since
// their class paths gets added to the the shared
// class loader. Any application acceessing these
// rar modules otherwise will not be able them.
this._connMgr.load();
// Loads connector resources belonging to standalone rars.
// Skip the resources belonging to embedded rars
// Do not reload RAConfigs, they are loaded above
this._connectorResLoader.
loadConnectorResources();
// Now do recovery
ResourceInstaller installer =
Switch.getSwitch().getResourceInstaller();
installer.recoverXAResources();
// loads all deployed stand alone application client modules
this._acMgr.load();
// loads all deployed stand alone ejb modules
this._ejbMgr.load();
// loads all deployed stand alone web modules
this._webMgr.load();
// loads all deployed j2ee applications
this._applicationMgr.load();
// Loads connector resources belonging to embedded rars.
// Resources belonging to stand alone rars are already loaded
//this._connectorResLoader.load(!standAloneRarsResources);
} catch (Throwable th) {
_logger.log(Level.SEVERE,
"core.unexpected_error_occured_while_app_loading", th);
}
| public void | onTermination()Server is terminating the subsystems and the runtime environment.
Gracefully terminate the active use of the public methods of this
subsystem. This method should be the last one called on a given
instance of this subsystem.
try {
// application registry for this server instance
ApplicationRegistry registry = ApplicationRegistry.getInstance();
Collection containers = null;
if (registry != null) {
containers = registry.getAllEjbContainers();
}
// final shut down call to all ejb containers
if (containers != null) {
Iterator iter = containers.iterator();
while (iter.hasNext()) {
Container container = (Container) iter.next();
if (container != null) {
container.onTermination();
}
}
}
} catch (Throwable th) {
_logger.log(Level.SEVERE,
"core.unexpected_error_occured_while_app_terminate", th);
}
|
|