FileDocCategorySizeDatePackage
StandAloneAppClientModulesManager.javaAPI DocGlassfish v2 API11854Fri May 04 22:35:42 BST 2007com.sun.enterprise.server

StandAloneAppClientModulesManager

public class StandAloneAppClientModulesManager extends AbstractManager implements com.sun.enterprise.admin.event.ModuleDeployEventListener
AppClientModules Manager acts as a listener for the deployment events.
author
Sreenivas Munnangi
since
JDK1.4

Fields Summary
static Logger
_logger
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
StandAloneAppClientModulesManager(com.sun.enterprise.instance.AppclientModulesManager acModuleManager, ClassLoader sharedCL)
Application Client Modules Manager


             
    
	    

	super(sharedCL, acModuleManager);

        AdminEventListenerRegistry.addModuleDeployEventListener(this);

        /* Make sure the manager is alive to receive all start-up load events. */
        AppclientJWSSupportManager.getInstance();

    
Methods Summary
protected AbstractLoadergetLoader(java.lang.String moduleId)
Returns loader

	return new ApplicationClientModuleLoader(
			moduleId, 
			this.parentClassLoader, 
			(AppclientModulesManager) this.configManager);
    
public synchronized voidmoduleDeployed(com.sun.enterprise.admin.event.ModuleDeployEvent event)
Invoked when a standalone application client module is deployed.



        boolean jsr77 = false;

        if (_logger.isLoggable(Level.FINEST)) {
            _logger.log(Level.FINEST,
                "In StandAloneAppClientModulesManager moduleDeployed");
            _logger.log(Level.FINEST, "ModuleType=" + event.getModuleType());
        }

        if (event.getModuleType().equals(event.TYPE_APPCLIENT)) {

            DeployEventListenerHelper.getDeployEventListenerHelper().synchronize(event);

            String modID = event.getModuleName();

            if (_logger.isLoggable(Level.FINEST)) {
                _logger.log(Level.FINEST, "modID=" + modID);
            }

            try {
                // refreshes the config context with the context from this event
                this.configManager.refreshConfigContext(event.getConfigContext());

                // set jsr77 flag
                // which is used to signify if the event is deploy or undeploy
                // to create or delete jsr77 mBeans
                String action = event.getAction();
                if ((action.equals(BaseDeployEvent.DEPLOY)) ||
                        (action.equals(BaseDeployEvent.REDEPLOY))) {
                    jsr77 = true;
                }

                if (!moduleDeployed(jsr77, modID, event.getConfigContext())) {

                    // throw an exception if load fails
                    String msg = localStrings.getString("appClientModule deploy failed",
                            modID);
                    throw new AdminEventListenerException(msg);
                }
            } catch (ConfigException ce) {
                throw new AdminEventListenerException(ce.getMessage());
            }
        }
    
private booleanmoduleDeployed(boolean jsr77, java.lang.String modID, com.sun.enterprise.config.ConfigContext dynamicConfigContext)
Deployed event handling


	boolean result = false;
        boolean loadJSR77 = jsr77 || loadJSR77(modID, DeployableObjectType.CAR);
	try {
            AbstractLoader modLoader = getLoader(modID);

            // create root mBean for this module
            if (loadJSR77) {
                try {
                    modLoader.createRootMBean();
                } catch (MBeanException mbe) {
                    _logger.log(Level.WARNING,
                        "core.error_while_creating_jsr77_root_mbean",mbe);
                }
            }

            modLoader.setConfigContext(dynamicConfigContext);
            result = modLoader.load(loadJSR77);
            if (result) {
                this.id2loader.put(modID, modLoader);
            }
	} catch (Exception ce) {
            _logger.log(Level.WARNING,
                "core.error_while_loading_application_client_module",ce);
            result = false;
	}

        return result;
    
public synchronized voidmoduleDisabled(com.sun.enterprise.admin.event.ModuleDeployEvent event)
Invoked when a standalone application client module is disabled.


        if (_logger.isLoggable(Level.FINEST)) {
            _logger.log(Level.FINEST,
                "In StandAloneAppClientModulesManager moduleDisabled");
        }

	// for an application client module
	// the operations enable/disable or start/stop do not make sense

	return;
    
public synchronized voidmoduleEnabled(com.sun.enterprise.admin.event.ModuleDeployEvent event)
Invoked when a standalone application client module is enabled.


        if (_logger.isLoggable(Level.FINEST)) {
            _logger.log(Level.FINEST,
                "In StandAloneAppClientModulesManager moduleEnabled");
        }

	// for an application client module
	// the operations enable/disable or start/stop do not make sense

	return;
    
public synchronized voidmoduleRedeployed(com.sun.enterprise.admin.event.ModuleDeployEvent event)
Invoked when a standalone application client module is redeployed.


        if (_logger.isLoggable(Level.FINEST)) {
            _logger.log(Level.FINEST,
                "In StandAloneAppClientModulesManager moduleRedeployed");
        }

        if (event.getModuleType().equals(event.TYPE_APPCLIENT)) {

            String modID = event.getModuleName();

            if (_logger.isLoggable(Level.FINEST)) {
                _logger.log(Level.FINEST, "ReDeploying module: " + modID);
            }

            moduleUndeployed(event);
            moduleDeployed(event);
        }
    
public voidmoduleReferenceAdded(com.sun.enterprise.admin.event.ModuleDeployEvent event)
Invoked when a reference is created from a server instance (or cluster) to a particular module.

throws
AdminEventListenerException when the listener is unable to process the event.

                
public voidmoduleReferenceRemoved(com.sun.enterprise.admin.event.ModuleDeployEvent event)
Invoked when a reference is removed from a server instance (or cluster) to a particular module.

throws
AdminEventListenerException when the listener is unable to process the event.

                
    
public synchronized voidmoduleUndeployed(com.sun.enterprise.admin.event.ModuleDeployEvent event)
Invoked when a standalone application client module is undeployed.


        boolean jsr77 = false;

        if (_logger.isLoggable(Level.FINEST)) {
            _logger.log(Level.FINEST,
                "In StandAloneAppClientModulesManager moduleUndeployed");
        }

        String action = event.getAction();

        if ((action.equals(BaseDeployEvent.UNDEPLOY)) ||
                (action.equals(BaseDeployEvent.REDEPLOY))) {
            jsr77 = true;
        }

        try {
            if (event.getModuleType().equals(event.TYPE_APPCLIENT)) {
                String modID = event.getModuleName();

                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, "UnDeploying module: " + modID);
                }

                // unload and throw exception if it fails
                if (!moduleUndeployed(jsr77, modID)) {
                    String msg = localStrings.getString("appclient.appclient_undeployed_failed",
                            modID);
                    throw new AdminEventListenerException(msg);
                }

            }
        } catch (Exception e) {
            throw new AdminEventListenerException(e.getMessage());
        }

    
private booleanmoduleUndeployed(boolean jsr77, java.lang.String modID)
Undeployed event handling


	boolean result = false;
        try {
            ApplicationClientModuleLoader modLoader =
                (ApplicationClientModuleLoader) this.id2loader.remove(modID);

            if (modLoader == null) {
                return true;
            }

            // delete root mBean for this module
            if (jsr77) {
                try {
                    modLoader.deleteRootMBean();
                } catch (MBeanException mbe) {
                    _logger.log(Level.WARNING,
                        "core.error_while_deleting_jsr77_root_mbean",mbe);
                    }
            }

            result = modLoader.unload(jsr77);

        } catch (Exception ce) {
            _logger.log(Level.WARNING,
                    "core.error_while_unloading_application_client_module",ce);
            result = false;
	}

        return result;