FileDocCategorySizeDatePackage
ManagedJ2EEApplication.javaAPI DocGlassfish v2 API14834Fri May 04 22:33:56 BST 2007com.sun.enterprise.admin.server.core.mbean.config

ManagedJ2EEApplication

public class ManagedJ2EEApplication extends ConfigMBeanBase implements ConfigAttributeName.J2EEApplication
A class that represents any deployed J2EE application to a Server Instance. In other words it exposes all the parameters of an application that can be managed and all the operations that can be invoked on it. Whenever a J2EE application is deployed to a Server Instance, a corresponding instance of this class is registered in the MBeanServer. On removal of the application, the MBean will be deregistered.

There will be as many instances of this MBean as there are deployed J2EE applications in the Server Instance. Note that not all deployed applications are running (or enabled).

ObjectName of this MBean is: ias:type=J2EEApplication, name=, InstanceName=

Fields Summary
private static final String[]
MAPLIST
private static final String[]
ATTRIBUTES
private static final String[]
OPERATIONS
Constructors Summary
public ManagedJ2EEApplication()
Default constructor sets MBean description tables


                     
       
    
        this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS);
    
public ManagedJ2EEApplication(String instanceName, String appName)

        this(instanceName, appName, null);
    
public ManagedJ2EEApplication(String instanceName, String appName, com.sun.enterprise.admin.AdminContext adminContext)

        this(); //set description tables
        setAdminContext(adminContext);
        initialize(ObjectNames.kApplication, new String[]{instanceName, appName});
    
Methods Summary
public voiddisable()
Disables this application. The application should be enabled to begin with. There will be some time elapsed till the application is disabled. This method will return asynchronously. This is to exhibit the quiece capabilities.

throws
J2EEApplicationException if the application is already disabled or there is some error during disablement

        return; //FIXME: for RI only
/*        try
        {
            this.setAttribute(new Attribute(kEnabled, new Boolean(false)));
            super.getConfigContext().flush();
        }
        catch (Exception e)
        {
            sLogger.throwing(getClass().getName(), "disable", e);
            throw new J2EEApplicationException(e.getMessage());
        }
*/
    
public voidenable()
Enables this application. The application should be disabled to begin with. There will be some time elapsed till the application is enabled. This method will return asynchronously.

throws
J2EEApplicationException if the application is already enabled or there is some error during enablement

        return; //FIXME: for RI only
/*        try
        {
             this.setAttribute(new Attribute(kEnabled, new Boolean(true)));
            super.getConfigContext().flush();
        }
        catch (Exception e)
        {
            sLogger.throwing(getClass().getName(), "enable", e);
            throw new J2EEApplicationException(e.getMessage());
        }
*/
    
public java.lang.String[]getEjbModules()

        return getModulesByType(ModulesXMLHelper.MODULE_TYPE_EJB);
    
public java.lang.String[]getModules()

        return getModulesByType(ModulesXMLHelper.MODULE_TYPE_ALL);
    
private java.lang.String[]getModulesByType(int moduleTypes)

        try
        {
            String location = (String)this.getAttribute(kLocation);
            return ModulesXMLHelper.getModulesFromApplicationLocation(location, moduleTypes);
        }
        catch (Exception e)
        {
            sLogger.throwing(getClass().getName(), "getModulesByType", e);
            throw new J2EEApplicationException(e.getMessage());
        }
    
public java.lang.IntegergetState()
Gets the jsr77 state corresponding to this module

        try {
            ServerContext serverContext = ApplicationServer.getServerContext();
            String namePattern = (
                serverContext.getDefaultDomainName() + ":" + 
                "j2eeType=J2EEApplication," + 
		"name=" + ((String)this.getAttribute(kName)) + "," + 
		"J2EEServer=" + serverContext.getInstanceName() + "," +
		"*");
            Integer intObj = (Integer)
	    	Switch.getSwitch().getManagementObjectManager().getState(namePattern);
	    return intObj;
        } catch (Exception e) {
            sLogger.throwing(getClass().getName(), "getState", e);
            throw new J2EEApplicationException(e.getMessage());
        }
    
public com.sun.enterprise.admin.common.EntityStatusgetStatus()
Returns the Status of this Application.

throws
J2EEApplicationException if the status can't be retrieved.

        EntityStatus status = null;

        try
        {
            boolean isAppEnabled = true; //FIXME for RI only
//            boolean isAppEnabled = ((Boolean)this.getAttribute(kEnabled)).booleanValue();
            status = new EntityStatus();
            if (isAppEnabled)
            {
                status.setEnabled();
            }
            else
            {
                status.setDisabled();
            }
        }
        catch (Exception e)
        {
            sLogger.throwing(getClass().getName(), "getStatus", e);
            throw new J2EEApplicationException(e.getMessage());
        }
        return status;
    
public java.lang.String[]getWebModules()

        return getModulesByType(ModulesXMLHelper.MODULE_TYPE_WEB);
    
public static final voidmain(java.lang.String[] args)

        System.setProperty("com.sun.aas.instanceRoot", "e:\\tmp");
        ManagedJ2EEApplication appMBean = 
            new ManagedJ2EEApplication("adminapp", "admserv");
        EntityStatus status = appMBean.getStatus();
        sLogger.info("======== Status = " + status.getStatusString());
        if (status.isDisabled())
        {
            sLogger.info("======== Enabling app");
            appMBean.enable();
            status = appMBean.getStatus();
            sLogger.info("======== Status = " + status.getStatusString());
        }
        else
        {
            sLogger.info("======== Disabling app");
            appMBean.disable();
            status = appMBean.getStatus();
            sLogger.info("======== Status = " + status.getStatusString());
        }
    
private voidmulticastAdminEvent(java.lang.String entityName, java.lang.String actionCode)
Multicasts the admin event so that the application gets loaded dynamically without the need for reconfig.

        String instanceName = super.getServerInstanceName();
        InstanceEnvironment instEnv = new InstanceEnvironment(instanceName);
        try {
                instEnv.applyServerXmlChanges(false);
        } catch (Exception e) {
            sLogger.throwing(getClass().getName(), "getAttr", e);
            throw new J2EEApplicationException(e.getMessage());
        }
        AdminEvent event = new ApplicationDeployEvent(instanceName, entityName, actionCode);
        //AdminEventCache.populateConfigChange(super.getConfigContext(), event);
        RMIClient serverInstancePinger = AdminChannel.getRMIClient(instanceName);
        if (serverInstancePinger.getInstanceStatusCode() != Status.kInstanceRunningCode) {
                    return;
        }
        AdminEventResult multicastResult = AdminEventMulticaster.multicastEvent(event);
        if (!AdminEventResult.SUCCESS.equals(multicastResult.getResultCode())) {
                AdminEventCache cache = AdminEventCache.getInstance(instanceName);
                    cache.setRestartNeeded(true);
        }
    
public voidstart()
Enables the application. Difference between this method and enable is persistence of the state. Enable method persists the state and this method does not persist the state.

        try {
            String appName = (String)this.getAttribute(kName);
            multicastAdminEvent(appName, BaseDeployEvent.ENABLE);
        } catch (Exception e) {
            sLogger.throwing(getClass().getName(), "start", e);
            throw new J2EEApplicationException(e.getMessage());
        }
    
public voidstop()
Disables the application. Difference between this method and disable is persistence of the state. Disable method persists the state and this method does not persist the state.

        try {
            String appName = (String)this.getAttribute(kName);
            multicastAdminEvent(appName, BaseDeployEvent.DISABLE);
        } catch (Exception e) {
            sLogger.throwing(getClass().getName(), "stop", e);
            throw new J2EEApplicationException(e.getMessage());
        }