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

EJBModuleLoader

public class EJBModuleLoader extends AbstractLoader
EJB loader loads and unloads stand alone ejb module.
author
Mahesh Kannan
author
Nazrul Islam
since
JDK1.4

Fields Summary
static Logger
_logger
Constructors Summary
EJBModuleLoader(String modID, ClassLoader parentClassLoader, com.sun.enterprise.instance.EjbModulesManager ejbModulesManager)
EJBModuleLoaderer loads one module.

param
modID the name of the ejb module
param
parentClassLoader the parent class loader
param
ejbModulesManager the ejb module mgr for this VS


                                                   
       
              

        super(modID, parentClassLoader, ejbModulesManager);
        boolean createClassLoader = true;
        try {
            application = ejbModulesManager.getRegisteredDescriptor(modID);

            //application object would be null if this is during server
            //startup or deployment to remote instance
            if (application == null) {
                application= (Application) 
                    ejbModulesManager.getDescriptor(modID, 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.getModuleClasspath(
                        modID, null, ejbModulesManager).toArray(new String[0]);
                initializeLoader(classPath, ejbModulesManager.getLocation(modID), ModuleType.EJB);
                application.setClassLoader(this.ejbClassLoader);
                if (application.isVirtual()) { //better be
                    BundleDescriptor bd = 
                        application.getStandaloneBundleDescriptor();
                    bd.setClassLoader(ejbClassLoader);
                }
            } else {
                initializeLoader(application.getClassLoader());
            }
        } catch (Exception confEx) {
            //@@ i18n
            _logger.log(Level.SEVERE, "ERROR while loading application " + modID);
            _logger.log(Level.SEVERE,"loader.error_while_loading_app_desc",
                        confEx);
        }
    
Methods Summary
voidcreateLeafMBean(com.sun.enterprise.deployment.Descriptor descriptor)
Create jsr77 mBeans for ejbs within this module


        EjbDescriptor ejbDescriptor = null;
        try {
            ejbDescriptor = (EjbDescriptor) descriptor;
        } catch (Exception e) {
            throw new MBeanException(e);
        }

        Switch.getSwitch().getManagementObjectManager().createEJBMBean(ejbDescriptor,
                    this.configManager.getInstanceEnvironment().getName());
    
voidcreateLeafMBeans()
Create jsr77 mBeans for ejbs within this module


        java.util.Set ejbBundles = this.application.getEjbBundleDescriptors();

        for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) {

            EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next();

            Switch.getSwitch().getManagementObjectManager().createEJBMBeans(bundleDesc,
                    this.configManager.getInstanceEnvironment().getName());
        }
    
voidcreateRootMBean()
Create jsr77 root mBean


        EjbDeploymentDescriptorFile eddf = null;

        java.util.Set ejbBundles = this.application.getEjbBundleDescriptors();

        for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) {

            EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next();

	    try {
            	Switch.getSwitch().getManagementObjectManager().createEJBModuleMBean(
		    bundleDesc,
		    this.configManager.getInstanceEnvironment().getName(),
		    this.configManager.getLocation(this.id));
	    } catch (Exception e) {
	        throw new MBeanException(e);
	    }
        }
    
voiddeleteLeafAndRootMBeans()
Delete jsr77 mBeans for the module and its' components

        deleteLeafMBeans();
        deleteRootMBean();
    
voiddeleteLeafMBean(com.sun.enterprise.deployment.Descriptor descriptor)
Delete jsr77 mBeans for ejbs within this module


        EjbDescriptor ejbDescriptor = null;
        try {
            ejbDescriptor = (EjbDescriptor) descriptor;
        } catch (Exception e) {
            throw new MBeanException(e);
        }
        Switch.getSwitch().getManagementObjectManager().deleteEJBMBean(ejbDescriptor,
                    this.configManager.getInstanceEnvironment().getName());
    
voiddeleteLeafMBeans()
Delete jsr77 mBeans for ejbs within this module


        java.util.Set ejbBundles = this.application.getEjbBundleDescriptors();

        for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) {

            EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next();

            Switch.getSwitch().getManagementObjectManager().deleteEJBMBeans(bundleDesc,
                    this.configManager.getInstanceEnvironment().getName());
        }
    
voiddeleteRootMBean()
Delete jsr77 root mBean


        java.util.Set ejbBundles = this.application.getEjbBundleDescriptors();

        for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) {

            EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next();

            Switch.getSwitch().getManagementObjectManager().deleteEJBModuleMBean(bundleDesc,
                    this.configManager.getInstanceEnvironment().getName());
        }
    
booleandoLoad(boolean jsr77)
Loads all the beans in this stand alone ejb module. This routine creates the EJB and MDB container.

param
jsr77 create jsr77 mBeans if true
return
true if all ejbs loaded properly

	//Note: Application.isVirtual will be true for stand-alone module
	notifyAppEvent(ApplicationEvent.BEFORE_APPLICATION_LOAD);
        boolean pusLoaded = false;
        if(application.isVirtual()) { // standalone ejb jar
            // load persistence units for standalone ejb jars only
            // because for embedded ejb-jars, AppliationLoader loads them.
            if(!loadPersistenceUnits()) {
                return false; // abort loading at this point.
            } else {
                pusLoaded = true;
            }
        }
        boolean status = loadEjbs(jsr77);

	if (status == true) {
	    notifyAppEvent(ApplicationEvent.AFTER_APPLICATION_LOAD);
            loadWebserviceEndpoints(jsr77);
	} else {
            if(pusLoaded) { // unload iff we have loaded.
                unloadPersistenceUnits();
            }
        }

	return status;
    
voidsetState(int state)
Set state for the root mBean


        java.util.Set ejbBundles = this.application.getEjbBundleDescriptors();

        for(Iterator it=ejbBundles.iterator(); it.hasNext(); ) {

            EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor)it.next();

            Switch.getSwitch().getManagementObjectManager().setEJBModuleState(state, bundleDesc,
                this.configManager.getInstanceEnvironment().getName());
        }
    
booleanunload(boolean jsr77)
Unloads the beans in this stand alone ejb module.

param
jsr77 delete jsr77 mBeans if true
return
true if removed successful

        // undeploy the ejb modules

	//Note: Application.isVirtual will be true for stand-alone module
	notifyAppEvent(ApplicationEvent.BEFORE_APPLICATION_UNLOAD);

        boolean result = unloadEjbs(jsr77);
        unloadWebserviceEndpoints(jsr77);

        if(application.isVirtual()) { // standalone jar
            // unload persistence units for standalone ejb jars only
            // because for embedded ejb jar, AppliationLoader unloads them.
            result &= unloadPersistenceUnits();
        }

        configManager.unregisterDescriptor(id);

	notifyAppEvent(ApplicationEvent.AFTER_APPLICATION_UNLOAD);

        // helps garbage collector
        done();
        return result;