FileDocCategorySizeDatePackage
ApplicationLoader.javaAPI DocGlassfish v2 API15666Fri May 04 22:35:40 BST 2007com.sun.enterprise.server

ApplicationLoader

public class ApplicationLoader extends AbstractLoader
Application loader loads and unloads an applicaton.
author
Mahesh Kannan
author
Nazrul Islam
since
JDK1.4

Fields Summary
static Logger
_logger
logger to log loader messages
private boolean
isForceDeploy
Indicates if the deployment being performed is a force Deploy
Constructors Summary
public ApplicationLoader(String appID, ClassLoader parentClassLoader, com.sun.enterprise.instance.AppsManager appsManager)
ApplicationLoader loads one application.

param
appID the name of the application
param
parentClassLoader parent class loader for this application
param
appsManager the AppsManager for this VS

    
                                                         
        
              

        super(appID, parentClassLoader, appsManager);
        boolean createClassLoader = true;
        try {
            application = appsManager.getRegisteredDescriptor(appID);
            //application object would be null if this is during server
            //startup or deployment to remote instance
            if (application==null) {
                application = appsManager.getAppDescriptor(appID, parentClassLoader);
                createClassLoader = false;
            } 
            //not null during deployment on DAS or in some case of 
            //remote serer start up where the clasloader is initialized
            //by the ResourceUtil
            else {
                try {
                    //the following check is to make sure we do not create
                    //a new classloader if one is already initialized and
                    //not void.  note that the classloader used in deployment
                    //is voided (done called) at this point.
                    ClassLoader clazzloader = application.getClassLoader();
                    if (clazzloader != null 
                        && (clazzloader instanceof EJBClassLoader)
                        && !((EJBClassLoader)clazzloader).isDone()) {
                        createClassLoader = false;
                    }
                } catch (Exception ex) {}
            }
            
            if (createClassLoader) {
                String[] classPath = (String[])
                EJBClassPathUtils.getAppClasspath(application, appsManager).toArray(new String[0]);
            
                initializeLoader(classPath, appsManager.getLocation(application.getRegistrationName()), 
                                      ModuleType.EAR);
                application.setClassLoader(this.ejbClassLoader);
            } else {
                initializeLoader(application.getClassLoader());
            }

        } catch (Exception confEx) {
            //@@ i18n
            _logger.log(Level.SEVERE, "ERROR while loading application " + appID);
            _logger.log(Level.SEVERE,"loader.error_while_loading_app_desc",
                        confEx);
        }
    
Methods Summary
voidcreateLeafMBean(Descriptor descriptor)
Create jsr77 mBean for the leaf object In case of application loader it will be a NO-OP

        if (descriptor instanceof EjbDescriptor) {
            EjbDescriptor ejbDescriptor = null;
            try {
                ejbDescriptor = (EjbDescriptor) descriptor;
            } catch (Exception e) {
                throw new MBeanException(e);
            }
            Switch.getSwitch().getManagementObjectManager().createEJBMBean(ejbDescriptor,
                this.configManager.getInstanceEnvironment().getName());
        } else if (descriptor instanceof ConnectorDescriptor) {
            ConnectorDescriptor cd = null;
            try {
                cd = (ConnectorDescriptor) descriptor;
            } catch (Exception e) {
                throw new MBeanException(e);
            }
            Switch.getSwitch().getManagementObjectManager().createRARMBean(cd,
                this.configManager.getInstanceEnvironment().getName());
        } 
    
voidcreateLeafMBeans()
Create jsr77 mBeans for all components within this application

	try {
            Switch.getSwitch().getManagementObjectManager().createAppMBeans(
		this.application,
            	this.configManager.getInstanceEnvironment().getName(),
		this.configManager.getLocation(this.id));
	} catch (Exception e) {
	    throw new MBeanException(e);
	}
    
voidcreateRootMBean()
Create jsr77 root mBean


	try {

            Switch.getSwitch().getManagementObjectManager().createAppMBean(
                this.application, 
                this.configManager.getInstanceEnvironment().getName(),
	        this.configManager.getLocation(this.id));

            Switch.getSwitch().getManagementObjectManager().createAppMBeanModules(
		this.application, 
            	this.configManager.getInstanceEnvironment().getName(),
		this.configManager.getLocation(this.id));

	} catch (Exception e) {
	    throw new MBeanException(e);
	}
    
voiddeleteLeafAndRootMBeans()
Delete jsr77 mBeans for the application and its' components

        deleteLeafMBeans();
        deleteRootMBean();
    
voiddeleteLeafMBean(Descriptor descriptor)
Delete jsr77 mBean for the leaf object In case of application loader it will be a NO-OP

        if (descriptor instanceof EjbDescriptor) {
            EjbDescriptor ejbDescriptor = null;
            try {
                ejbDescriptor = (EjbDescriptor) descriptor;
            } catch (Exception e) {
                throw new MBeanException(e);
            }
            Switch.getSwitch().getManagementObjectManager().deleteEJBMBean(ejbDescriptor,
                this.configManager.getInstanceEnvironment().getName());
        } else if (descriptor instanceof ConnectorDescriptor) {
            ConnectorDescriptor cd = null;
            try {
                cd = (ConnectorDescriptor) descriptor;
            } catch (Exception e) {
                throw new MBeanException(e);
            }
            Switch.getSwitch().getManagementObjectManager().deleteRARMBean(cd,
                this.configManager.getInstanceEnvironment().getName());
        }
    
voiddeleteLeafMBeans()
Delete jsr77 mBeans for all components within this application

        Switch.getSwitch().getManagementObjectManager().deleteAppMBeans(this.application,
            this.configManager.getInstanceEnvironment().getName());
    
voiddeleteRootMBean()
Delete jsr77 root mBean

        Switch.getSwitch().getManagementObjectManager().deleteAppMBean(this.application, 
            this.configManager.getInstanceEnvironment().getName());
    
protected booleandoLoad(boolean jsr77)
Called from ApplicationManager. Called to load an application. This routine creates the EJB and MDB container.

param
jsr77 create jsr77 mBeans if true
return
true if all modules were loaded successfully

        boolean allModulesDeployed = false;

        //  Possible values for loading:
        //  1. LOAD_ALL is for loading regular application
        //  2. LOAD_RAR is for loading the rar part of the embedded rar
        //  3. LOAD_REST is for loading the rest part of the embedded rar
        //  Embedded rar is loaded in two steps so we can create connector
        //  resources in between.

        //set default value
        if (loadUnloadAction == Constants.LOAD_UNSET) {
            loadUnloadAction = Constants.LOAD_ALL;
        }

        if (loadUnloadAction == Constants.LOAD_ALL || 
            loadUnloadAction == Constants.LOAD_RAR) { 
	    notifyAppEvent(ApplicationEvent.BEFORE_APPLICATION_LOAD);
            allModulesDeployed = loadRars(jsr77);
            if (loadUnloadAction == Constants.LOAD_RAR) {       
                return allModulesDeployed;
            }
        }

        // Now load the EJB 3.0 persistence entities.
        allModulesDeployed = loadPersistenceUnits();
        if(!allModulesDeployed) return false;

        if (allModulesDeployed) {
            allModulesDeployed = loadEjbs(jsr77); 
	    notifyAppEvent(ApplicationEvent.AFTER_APPLICATION_LOAD);
	}
        if (!allModulesDeployed) {
            // remove all loaded pars
            unloadPersistenceUnits();
            return allModulesDeployed;
        }
        loadWebserviceEndpoints(jsr77);

        // The web modules of this application are loaded from
        // J2EERunner.confPostInit() as part of the WebContainer start()
        // method

        return allModulesDeployed;
    
public booleanisForceDeploy()

        return this.isForceDeploy;
    
public voidsetForceDeploy(boolean isForceDeploy)

        this.isForceDeploy = isForceDeploy;
    
voidsetState(int state)
Set the state for the rootMBean

        if (application == null) {
            //the application object can be null if this is a redeployment
            //of an app that previously failed to load.  at the point of
            //failure we cleaned out the loaders, including the application
            //object.  therefore, if the application object is null, we
            //would log it and skip this step
            _logger.log(Level.FINE, 
            "Application descriptor is NULL. setState skipped");
        } else {
            Switch.getSwitch().getManagementObjectManager().setApplicationState(
                state, application, 
                configManager.getInstanceEnvironment().getName());
        }
    
protected booleanunload(boolean jsr77)
Unloads this application.

param
jsr77 delete jsr77 mBeans if true
return
true if all modules were removed successfully

        
        // Possible values for unloading:
        // 1. UNLOAD_ALL is for unloading regular application
        // 2. UNLOAD_RAR is for unloading the rar part of the embedded rar
        // 3. UNLOAD_REST is for unloading the rest part of the embedded rar
        // Embedded rar is unloaded in two steps so we can delete connector
        // resources in between.

        //set default value
        if (loadUnloadAction == Constants.LOAD_UNSET) {
            loadUnloadAction = Constants.UNLOAD_ALL;
        }

        boolean wsUnloaded = false;
        boolean ejbUnloaded = false;
        boolean pusUnloaded = false;

        if (loadUnloadAction == Constants.UNLOAD_ALL || 
            loadUnloadAction == Constants.UNLOAD_REST) {
	    notifyAppEvent(ApplicationEvent.BEFORE_APPLICATION_UNLOAD);
            wsUnloaded = unloadWebserviceEndpoints(jsr77); 

            // undeploy the ejb modules
            ejbUnloaded = unloadEjbs(jsr77);

            // Web modules are undeployed as part of the NSAPI reconfig
            // callback interface implemented in J2EERunner

            //undeploy persistence units
            pusUnloaded = unloadPersistenceUnits();
        
            if (loadUnloadAction == Constants.UNLOAD_REST) {
                // return true status if components were unloaded OK
                if (wsUnloaded && ejbUnloaded && pusUnloaded) {
                    return true;
                } else {
                    return false;
                }
            }
        }

        // undeploy rar module
        //START OF IASRI 4666595
        boolean rarUnloaded = unloadRars(jsr77);
        //END OF IASRI 4666595

        configManager.unregisterDescriptor(id);

        notifyAppEvent(ApplicationEvent.AFTER_APPLICATION_UNLOAD);

        // helps garbage collection
        done();

        if (loadUnloadAction == Constants.UNLOAD_RAR) {
            return rarUnloaded;
        } else {
            return (wsUnloaded && ejbUnloaded && pusUnloaded && rarUnloaded);
        }