AbstractManagerpublic abstract class AbstractManager extends Object implements MonitorListenerBase manager class for J2ee applications. A manager manages all
j2ee application and stand alone modules for a server instance.
It also acts as a listener for the deployment events.
This manager object loads all the deployed applications
or stand alone modules.
Code Example:
AbstractManager mgr = new SubClassOfAbstractManager(loader, baseMgr);
// loads the deployed apps returned by the base mgr
mgr.load();
|
Fields Summary |
---|
protected ClassLoader | parentClassLoaderparent class loader for the j2ee applications | protected ApplicationRegistry | registryapplication registry | protected com.sun.enterprise.instance.BaseManager | configManagerencapsulates all application related info | protected Hashtable | id2loaderapplication id vs application loaders | protected ReloadMonitor | reloadMonitormonitors the time stamp of the RELOAD_FILE | protected boolean | systemAppsLoadedIndicates whether system apps of this manager are already loaded | static Logger | _loggerlogger to log core messages |
Constructors Summary |
---|
AbstractManager(ClassLoader parentClassLoader, com.sun.enterprise.instance.BaseManager configMgr)Inintializes the variables and constructs the application registry.
this.id2loader = new Hashtable();
this.parentClassLoader = parentClassLoader;
this.configManager = configMgr;
// initializes the application registry
this.registry = ApplicationRegistry.getInstance();
// initializes the reload monitor if dynamic reload is enabled
boolean monitor = this.configManager.isDynamicReloadEnabled();
if (monitor) {
this.reloadMonitor = ReloadMonitor.getInstance(
this.configManager.getReloadPollIntervalInMillis());
}
|
Methods Summary |
---|
protected void | addToReloadMonitor(java.lang.String id)Adds the given application or stand alone module to reload monitor.
// adds the reload file to monitor the time stamp
if (this.reloadMonitor != null && !(this.configManager.isSystem(id))) {
String mPath = this.configManager.getLocation(id)
+ File.separator + ReloadMonitor.RELOAD_FILE;
MonitorableEntry entry =
new MonitorableEntry(id, new File(mPath), this);
this.reloadMonitor.addMonitorableEntry(entry);
}
| public boolean | deploy(MonitorableEntry entry, java.io.File archive)No-op. Subclasses should implement this methods if they want to handle
the auto deploy callbacks.
return false;
| protected abstract AbstractLoader | getLoader(java.lang.String id)Returns the loader for this type of manager and the given id.
| java.lang.ClassLoader | getParentClassLoader()Returns the parent class loader (of ejb modules) used by this manager.
return this.parentClassLoader;
| protected boolean | isEnabled(com.sun.enterprise.config.ConfigContext config, java.lang.String moduleName)Whether or not a component (either an application or a module) should be
enabled is defined by the "enable" attribute on both the
application/module element and the application-ref element.
try {
ConfigBean app = ApplicationHelper.findApplication(config, moduleName);
Server server = ServerBeansFactory.getServerBean(config);
ApplicationRef appRef = server.getApplicationRefByRef(moduleName);
return ((app != null && app.isEnabled()) &&
(appRef != null && appRef.isEnabled()));
} catch (ConfigException e) {
AdminEventListenerException ex = new AdminEventListenerException();
ex.initCause(e);
_logger.log(Level.FINE, "Error in finding " + moduleName, e);
//If there is anything wrong, do not enable the module
return false;
}
| public boolean | isRegistered(java.lang.String id)This method is used to determine if an app or a module is already
registered.
return this.configManager.isRegistered(id);
| void | load()Loads the deployed and enabled applications and/or stand alone modules.
The list and the type (application vs stand alone module) is determined
from the associated config manager object.
// Set the thread context classloader
final ClassLoader connCL = this.parentClassLoader;
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
Thread.currentThread().setContextClassLoader(connCL);
return null;
}
}
);
//loadSystem();
// deployed application list from config
List appList = null;
try {
appList = this.configManager.listIds();
} catch (ConfigException confEx) {
_logger.log(Level.WARNING,
"core.error_while_getting_deployed_applist", confEx);
return;
}
// set jsr77 to true
boolean jsr77 = true;
// loads all the deployed applications
for (int i=0; i<appList.size(); i++) {
// registration name of this app
String id = (String) appList.get(i);
try {
if (this.configManager.isSystem(id)) {
continue;
}
} catch (ConfigException confEx) {
_logger.log(Level.WARNING,
"core.error_while_loading_app", confEx);
}
try {
// loader for this app
AbstractLoader loader = getLoader(id);
// create jsr77 root mBean
loader.createRootMBean();
// if app is enabled
ConfigContext ctx = configManager.getConfigContext();
if (isEnabled(ctx, id)) {
// set jsr77 root mBean state to STARTING
try {
loader.setState(StateManageable.STARTING_STATE);
} catch (MBeanException mbe) {
_logger.log(Level.WARNING,
"core.error_while_setting_jsr77_state",mbe);
}
/**
*Add the loader to the map so it can be cleaned up later
*even if the load fails.
*/
id2loader.put(id, loader);
// if loader was able to load successfully
if (loader.load(jsr77) == true) {
// set jsr77 root mBean state to RUNNING
try {
loader.setState(StateManageable.RUNNING_STATE);
} catch (MBeanException mbe) {
_logger.log(Level.WARNING,
"core.error_while_setting_jsr77_state",mbe);
}
} else {
// set jsr77 root mBean state to FAILED
try {
loader.setState(StateManageable.FAILED_STATE);
} catch (MBeanException mbe) {
_logger.log(Level.WARNING,
"core.error_while_setting_jsr77_state",mbe);
}
_logger.log(Level.WARNING,
"core.application_not_loaded", id);
}
// adds this app to be monitored if ON
addToReloadMonitor(id);
} else if (! isEnabled(ctx, id)) {
// if app is not enabled
// set jsr77 root mBean state to STOPPED
try {
loader.setState(StateManageable.STOPPED_STATE);
loader.createLeafMBeans();
} catch (MBeanException mbe) {
_logger.log(Level.WARNING,
"core.error_while_setting_jsr77_state",mbe);
}
}
} catch (ConfigException confEx) {
_logger.log(Level.WARNING,
"core.error_while_loading_app", confEx);
} catch (Throwable t) {
_logger.log(Level.WARNING,
"core.unexpected_error_occured_while_loading_app", t);
}
}
| protected boolean | loadJSR77(java.lang.String appName, com.sun.enterprise.deployment.backend.DeployableObjectType type)
ObjectName jsr77mBeanObjectName = null;
try {
String domainName = null;
AdminService adminService = AdminService.getAdminService();
if (adminService != null) {
domainName = adminService.getAdminContext().getDomainName();
} else {
return false;
}
//We do not load JSR77 MBeans for web modules
//web modules are loaded by the Tomcat container
String j2eeType = null;
if (type.isAPP()) {
j2eeType = "J2EEApplication";
} else if (type.isEJB()) {
j2eeType = "EJBModule";
} else if (type.isCONN()) {
j2eeType = "ResourceAdapterModule";
} else if (type.isCAR()) {
j2eeType = "AppClientModule";
} else if (type.isWEB()) {
return false;
}
String instanceName =
ApplicationServer.getServerContext().getInstanceName();
//form query
StringBuffer sb = new StringBuffer("");
sb.append(domainName + ":");
sb.append("j2eeType=" + j2eeType + ",");
sb.append("name=" + appName + ",");
if (!type.isAPP()) {
sb.append("J2EEApplication=null" + ",");
}
sb.append("J2EEServer=" + instanceName + "," + "*");
// perform query
MBeanServer mbs = adminService.getAdminContext().getMBeanServer();
ObjectName objNamePattern = new ObjectName(sb.toString());
java.util.Set s = mbs.queryNames(objNamePattern, null);
if (s != null && s.size()>0) {
ObjectName [] objNameArr =
(ObjectName[]) s.toArray( new ObjectName[s.size()]);
if (objNameArr.length>0) {
jsr77mBeanObjectName = objNameArr[0];
}
}
} catch (Exception ex) {
//Ignore on purpose.
}
return jsr77mBeanObjectName == null;
| public void | loadOneSystemApp(java.lang.String id, boolean jsr77)
// Set the thread context classloader
final ClassLoader connCL = this.parentClassLoader;
final ClassLoader cl = (ClassLoader)
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(connCL);
return cloader;
}
}
);
try {
// if app is enabled
ConfigContext ctx = configManager.getConfigContext();
if (ResourcesUtil.createInstance().belongToSystemRar(id) ||
(this.configManager.isSystem(id)
&& isEnabled(ctx, id))) {
// loader for this app
AbstractLoader loader = getLoader(id);
// create jsr77 root mBean
loader.createRootMBean();
/*
*Add the loader to the map so it can be cleaned up later
*even if the load fails.
*/
id2loader.put(id, loader);
// if loader was able to load successfully
if ( ! loader.load(jsr77) ) {
_logger.log(Level.WARNING,
"core.application_not_loaded", id);
}
}
} catch (ConfigException confEx) {
_logger.log(Level.SEVERE,
"core.error_while_loading_system_app", confEx);
} catch (Throwable t) {
_logger.log(Level.SEVERE,
"core.unexpected_error_occured_while_loading_system_app", t);
}
if (cl != connCL) {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
Thread.currentThread().setContextClassLoader(cl);
return null;
}
}
);
}
| void | loadSystem()Loads the deployed and enabled system applications and/or stand alone modules.
The list and the type (application vs stand alone module) is determined
from the associated config manager object.
// set jsr77 to true
boolean jsr77 = true;
if(systemAppsLoaded)
return;
// deployed application list from config
List appList = null;
try {
appList = this.configManager.listIds();
} catch (ConfigException confEx) {
_logger.log(Level.WARNING,
"core.error_while_getting_deployed_applist", confEx);
return;
}
// loads all the deployed applications
ArrayList<SystemAppStarter> systemAppStarters = new ArrayList<SystemAppStarter>();
long systemAppLoadStartTime = System.currentTimeMillis();
boolean isSystemAppLoadLoggingOn = _logger.isLoggable(Level.FINE);
for (int i=0; i<appList.size(); i++) {
// registration name of this app
String id = (String) appList.get(i);
/**
* The system app controlled by on-demand framework should not be
* loaded from this path. All appserver system apps are managed by
* On-demand system app loader. Any system app inserted by addons
* will be loaded in this path.
*/
if (OnDemandServer.isOnDemandOff() ||
!OnDemandServer.getSystemAppLoader().isOnDemandSystemApp(id)) {
/*
*For each system app of this manager's type create a starter
*object and submit it for concurrent execution. Keep
*track of all such objects to wait for their completion and
*to query their success.
*/
try {
if (configManager.isSystem(id)) {
SystemAppStarter starter = new SystemAppStarter(id, jsr77);
systemAppStarters.add(starter); //loadOneSystemApp(id, jsr77);
starter.submit();
if (isSystemAppLoadLoggingOn) {
_logger.fine(getClass().getName() + " submitted system app load request for " + id);
}
}
} catch (ConfigException ce) {
// Ignore this - it would come from the isSystem invocation.
}
}
}
/*
* Wait for the system apps to complete their start-up. Errors will be
* thrown, and therefore logged, from the thread doing the work. Wait for
* all to complete before aborting the startup if any failed.
*/
boolean systemAppsStartedOK = true;
for (SystemAppStarter starter : systemAppStarters) {
if (isSystemAppLoadLoggingOn) {
_logger.fine("About to wait for completion of load request for " + starter.getID());
}
boolean ok = starter.waitDone() == null;
systemAppsStartedOK &= ok;
if (isSystemAppLoadLoggingOn) {
_logger.fine("Completion received for " + starter.getID() + " reports " + (ok ? "success" : "failure"));
}
}
if ( ! systemAppsStartedOK) {
throw new RuntimeException(
_logger.getResourceBundle().getString("core.unexpected_error_occured_while_loading_app"));
} else if (isSystemAppLoadLoggingOn) {
_logger.fine(getClass().getName() + " has started its system apps successfully after " +
(System.currentTimeMillis() - systemAppLoadStartTime) + " ms");
}
systemAppsLoaded = true;
| protected void | registerException(com.sun.enterprise.admin.event.BaseDeployEvent event, java.lang.String msg)
AdminEventResult result = AdminEventResult.getAdminEventResult(event);
result.setResultCode(AdminEventResult.SUCCESS);
result.addException(event.getEffectiveDestination(),
new AdminEventListenerException(msg));
| public boolean | reload(MonitorableEntry entry)No-op. Subclasses should implement this methods if they want to handle
the dynamic reload callbacks.
return false;
| protected void | removeFromReloadMonitor(java.lang.String id)Removes the given application or stand alone module from reload monitor.
// 4925582 bnevins 10-1-03
// If the user makes some tiny error and does a touch .reload -- they couldn't fix
// it and try again. Now -- we don't remove it from the monitor list. So they can try again and
// a regular first-time deployment will be attempted. They can keep trying until a server restart.
// After a restart, they'll have to deploy from scratch again.
/*
if (this.reloadMonitor != null) {
//this.reloadMonitor.removeMonitoredEntry(id);
}
*/
| void | shutdown()Shutsdown the reload monitor. The bean container shutdown
activity is handled from the ApplicationLifeCycle module.
try {
// shuts down the dynamic reload monitor
if (this.reloadMonitor != null) {
this.reloadMonitor.stop();
}
} catch (Throwable t) {
_logger.log(Level.WARNING,
"core.unexpected_error_occured_while_app_shutdown", t);
}
|
|