FileDocCategorySizeDatePackage
RuleManager.javaAPI DocGlassfish v2 API36887Fri May 04 22:35:04 BST 2007com.sun.enterprise.management.selfmanagement

RuleManager

public final class RuleManager extends Object
This is the core class, which manages the runtime of the configured management_rules.
author
Pankaj Jairath

Fields Summary
private static final Logger
_logger
Logger for self management service
private static final com.sun.enterprise.util.i18n.StringManager
localStrings
Local Strings manager for the class
private final Map
activeRules
A HashMap that contains all enabled and active rules
private final Map
inActiveRules
HashMap that contains all enabled but inactive rules
private final Map
noActionRules
HashMap that contains all the rules that have no actions. These would have their configured events logged.
private final Map
disabledRules
A HashMap that contains all the disabled rules
private final String
USER_DEFINED_TYPE
private com.sun.enterprise.config.ConfigContext
configCtx
private final String
instanceName
private MBeanServer
instanceMbs
Instance MBeanServer
private String
mailSMTPHost
SMTP host for service alert mails
private String
srvAlertRecipients
Recipients of service alert messages
private SelfManagementService
service
Self management service instance
Constructors Summary
public RuleManager(SelfManagementService service)
Creates a new instance of RuleManager

       
           
       
        this.service = service;
        instanceName = (ApplicationServer.getServerContext()).getInstanceName();
        AdminService adSrv = AdminService.getAdminService();
        instanceMbs = (adSrv.getAdminContext()).getMBeanServer();
        configCtx = (ApplicationServer.getServerContext()).getConfigContext();
    
        activeRules = Collections.synchronizedMap(new HashMap<String,Rule>());
        inActiveRules = Collections.synchronizedMap(new HashMap<String,Rule>());
        noActionRules = Collections.synchronizedMap(new HashMap<String, Rule>());
        disabledRules = Collections.synchronizedMap(new HashMap<String,Rule>());
    
Methods Summary
voidaddAction(java.lang.String ruleName, java.lang.String actionName, com.sun.enterprise.config.ConfigContext ctxToUse)
Handles addition of action

param
ruleName : Identifies the rule to which action is being added
param
actionName : Identifies the action MBean name

       Rule ruleInstance = getRuleInstance(ruleName);
       if (ruleInstance!=null) {
           synchronized(ruleInstance) {
               bindAction(ruleInstance,actionName,ctxToUse);
           }
       }
   
public voidaddDisabledRule(java.lang.String ruleName, java.lang.String ruleDescription)
Handles addition of disabled rules under management_rules as configured in domain.xml

param
ruleName Identifies the defined management rule.
param
description Associates message with the intent of the defined rule.

        Rule ruleInstance = new Rule(ruleName, ruleDescription);
        setupRuleBinding(Rule.DISABLED, ruleInstance, null, null);
    
public voidaddRule(java.lang.String ruleName, java.lang.String description, Event ruleEvent, java.lang.String actionMBeanName, java.lang.Object handback, com.sun.enterprise.config.ConfigContext ctxToUse)

        ObjectName actionObjName = null;
        Object alertAction = null;
        Rule ruleInstance = new Rule(ruleName, description);
        //rule.setRuleEvent(ruleEvent);
        if (ctxToUse!=null) {
            configCtx = ctxToUse;
        }
        
        try {
            if (actionMBeanName != null) {
            
                Domain domain = ServerBeansFactory.getDomainBean(configCtx);
                ApplicationRef appRef = verifyActionMBean(actionMBeanName, domain,
                                                          ctxToUse);
       
       
                if (appRef != null) {
                    Applications apps = domain.getApplications();
                    Mbean definedMBean = apps.getMbeanByName(actionMBeanName);    
                
                   
                    if (appRef.isEnabled() && definedMBean.isEnabled() ) {
                        if ((definedMBean.getObjectType()).equals(USER_DEFINED_TYPE)) {
                            actionObjName = registerAction(ruleEvent,actionMBeanName,
                                                           definedMBean,false, handback);
                        } else {
                            // system defined, need to explictly load
                            actionObjName = registerAction(ruleEvent,actionMBeanName,
                                                           definedMBean,true, handback); 
                        }
                        //obtain the action instance from name
                        setupRuleBinding(Rule.ENABLED, ruleInstance, ruleEvent,
                                         (Object)actionObjName);
                        //rule.setActionMBean(actionInstance);
                        //rule.setState(Rule.ENABLED);
                        //addToActiveRuleMap(ruleName,rule);
                    } else {
                        /* action is disabled, but rule is active; Add a default mail
                         * alert
                         */
                        alertAction = registerAlertAction(ruleEvent, actionMBeanName,
                                                          ruleName, handback);
                        _logger.log(Level.WARNING,"sgmt.ruleactiondisabled",
                                    new Object[]{ruleName,actionMBeanName});
                        
                        setupRuleBinding(Rule.INACTIVE, ruleInstance, ruleEvent,
                                         alertAction);
                        //rule.setActionMbean(actionInstance);
                        //rule.setState(Rule.INACTIVE);
                        //addToInActiveRuleSet(ruleName,rule);
                    }
                 } else {
                     //log error, invalid action MBean provided for this rule
                     _logger.log(Level.SEVERE, "smgt.invalid_action", new Object[]{
                                 ruleName, actionMBeanName});
                     //config error
                 }
            } else {
                //no action rule, event would simply record itself
                setupRuleBinding(Rule.NOACTION, ruleInstance, ruleEvent, null);
            }
        } catch (ConfigException ex) {
            _logger.log(Level.INFO, "config_error", ex);
        } catch (InstanceNotFoundException ex) {
            //log it, 
            _logger.log(Level.INFO, "smgt.error_reg_action", new Object[]{
                        ruleName, actionMBeanName});
            registerAlertAction(ruleEvent, actionMBeanName, ruleName, handback);            
        } catch (MalformedObjectNameException ex) {
            _logger.log(Level.WARNING, "sgmt.error_reg_action", new Object[]{
                        ruleName, actionMBeanName});
        } catch (RuntimeOperationsException ex) {
            //log it, actionMBean is not a listener type, add to inactive rules
            _logger.log(Level.WARNING, "smgt.error_reg_action", new Object[]{
                        ruleName,actionMBeanName});
            registerAlertAction(ruleEvent, actionMBeanName, ruleName, handback);
        } catch (CustomMBeanException cmbe) {
            /**  
	     * log it, as thrown from customRegistration, add to inactive rules
	     */
	    _logger.log(Level.WARNING, "smgt.error_reg_action", new Object[] {
			ruleName, actionMBeanName});
	    registerAlertAction(ruleEvent, actionMBeanName, ruleName, handback);
        } catch (RuntimeException ex) {
            /*
             *log it, as thrown from customRegistration, add to inactive rules
             */
            _logger.log(Level.WARNING, "smgt.error_reg_action", new Object[] {
                        ruleName, actionMBeanName});
            registerAlertAction(ruleEvent, actionMBeanName, ruleName, handback);
       }
    
private voidbindAction(Rule ruleInstance, java.lang.String actionMBeanName, com.sun.enterprise.config.ConfigContext ctxToUse)

      String ruleName = ruleInstance.getName();
      Event ruleEvent = ruleInstance.getEvent();
      ObjectName actionObjName = null;
      Object alertAction = null;	  

      try {
          Domain domain = ServerBeansFactory.getDomainBean(ctxToUse);
          ApplicationRef appRef = verifyActionMBean(actionMBeanName, domain, ctxToUse);


          if (appRef != null) {
              Applications apps = domain.getApplications();
              Mbean definedMBean = apps.getMbeanByName(actionMBeanName);


              if (appRef.isEnabled() && definedMBean.isEnabled() ) {
                  if ((definedMBean.getObjectType()).equals(USER_DEFINED_TYPE)) {
                      actionObjName = registerAction(ruleEvent,actionMBeanName,
                                                     definedMBean,false,null);
                  } else {
                      // system defined, need to explictly load
                      actionObjName = registerAction(ruleEvent,actionMBeanName,
                                                     definedMBean,true,null);
                  }
                  //update the binding
                  ruleInstance.setAction((Object)actionObjName);
		  //Added to set up the rule binding
		  setupRuleBinding(Rule.ENABLED, ruleInstance, ruleEvent,
                                      (Object)actionObjName);
                  _logger.log(Level.INFO,"smgt.successaddaction", 
                               new Object[]{ruleName,actionMBeanName});
              } else {
                  /* action is disabled, but rule is active; Add a default mail
                   * alert
                   */
                  //alertAction = registerAlertAction(ruleEvent, actionMBeanName,
                  //                                   ruleName, null);
                  _logger.log(Level.WARNING,"sgmt.ruleactiondisabled",
                              new Object[]{ruleName,actionMBeanName});
                  //update the binding
                  ruleInstance.setState(Rule.INACTIVE);
				  //Added to set up the rule binding 
		  setupRuleBinding(Rule.INACTIVE, ruleInstance, ruleEvent,
                                         alertAction);
              }
           } else {
               //log error, invalid action MBean provided for this rule
               _logger.log(Level.SEVERE, "smgt.invalid_action", new Object[]{
                           ruleName, actionMBeanName});
               //config error
           }
        } catch (ConfigException ex) {
            _logger.log(Level.INFO, "config_error", ex);
        } catch (InstanceNotFoundException ex) {
            //log it,
            _logger.log(Level.INFO, "smgt.error_reg_action", new Object[]{
                        ruleName, actionMBeanName});
            //registerAlertAction(ruleEvent, actionMBeanName, ruleName, null);
        } catch (MalformedObjectNameException ex) {
            _logger.log(Level.WARNING, "sgmt.error_reg_action", new Object[]{
                        ruleName, actionMBeanName});
        } catch (RuntimeOperationsException ex) {
            //log it, actionMBean is not a listener type, add to inactive rules
            _logger.log(Level.WARNING, "smgt.error_reg_action", new Object[]{
                        ruleName,actionMBeanName});
            //registerAlertAction(ruleEvent, actionMBeanName, ruleName, null);
        } catch (CustomMBeanException cmbe) {
            /**  
	     * log it, as thrown from customRegistration, add to inactive rules
	     */
	    _logger.log(Level.WARNING, "smgt.error_reg_action", new Object[] {
			ruleName, actionMBeanName});
	    // registerAlertAction(ruleEvent, actionMBeanName, ruleName, handback);
        } catch (RuntimeException ex) {
            /*
             *log it, as thrown from customRegistration, add to inactive rules
             */
            _logger.log(Level.WARNING, "smgt.error_reg_action", new Object[] {
                        ruleName, actionMBeanName});
           //registerAlertAction(ruleEvent, actionMBeanName, ruleName, null);
       }
   
EventcheckEventExists(java.lang.String type, com.sun.enterprise.config.serverbeans.ElementProperty[] eventProps)
Determines if an event already exists which matches the details of the passed type and configured event properties

return
Event : The already existing event instance null : If no such event has been configured

        //placeHolder
        return null;
        
    
private voidcreateLoggingListener(Event event, java.lang.Object handback)

	NotificationListener logListener = LogMgmtEventsNotificationListener.getInstance(); 
	instanceMbs.addNotificationListener (event.getObjectName(), logListener, event.getNotificationFilter(), handback);
	return;
    
public voiddeleteAction(java.lang.String name)

        Event ruleEvent = null;
        Rule ruleInstance = null;
        try {
            ruleInstance = getRuleInstance(name);
            ruleEvent = ruleInstance.getEvent();
            NotificationFilter filter = ruleEvent.getNotificationFilter();
            ObjectName eventObjName = ruleEvent.getObjectName();
            ObjectName actionObjName = (ObjectName)ruleInstance.getAction();
            instanceMbs.removeNotificationListener(eventObjName,actionObjName,
                                                   filter, null);
            setupRuleBinding(Rule.NOACTION, ruleInstance, ruleEvent, null);
        } catch (Exception ex) {
            _logger.log(Level.WARNING, "sgmt.error_delete_action",
                new Object[]{name,ex.toString()});
        }

        //ensure gc of contained event
        ruleInstance = null;
    
public voiddeleteRule(java.lang.String name)
Handles deletion of an existing rule

param
name The Rule name which needs to be deleted

        Event ruleEvent = null;
        String description = null;
        Rule ruleInstance = null;
        
        try {
            if (activeRules.containsKey(name)) {
                //remove from the active list and its binding
                ruleInstance = activeRules.remove(name);
                ruleEvent = ruleInstance.getEvent();
                NotificationFilter filter = ruleEvent.getNotificationFilter();
                ObjectName eventObjName = ruleEvent.getObjectName();

                ObjectName actionObjName = (ObjectName)ruleInstance.getAction();
				if(actionObjName != null) {
                    instanceMbs.removeNotificationListener(eventObjName,
									actionObjName, filter, null);
				}
                ruleEvent.destroy();
            } else if (inActiveRules.containsKey(name)) {
                //remove from in active set and its binding
                ruleInstance = inActiveRules.remove(name);
                //alert action ?
                ruleEvent = ruleInstance.getEvent();
                ruleEvent.destroy();
            } else if (noActionRules.containsKey(name)) {
                //remove from no action set and its binding
                ruleInstance = noActionRules.remove(name);
                ruleEvent = ruleInstance.getEvent();
                ruleEvent.destroy();
            } else if (disabledRules.containsKey(name)) {
                //remove from disabled set
                ruleInstance = disabledRules.remove(name);
            } else {
                //log error
                _logger.log(Level.WARNING,"sgmt.delete_invalidname", name);
                return;
            }
        } catch (Exception ex) {
            _logger.log(Level.WARNING, "sgmt.error_delete_rule", 
                        new Object[]{name,ex.toString()});
            return;
        }    
       
        description = ruleInstance.getDescription();

        _logger.log(Level.INFO,"sgmt.deleted_rule",
                    new Object[] {name,description});

        //ensure gc of contained event
        ruleInstance = null;
    
private voiddisableRule(Rule ruleInstance, boolean disableService)

       /*
        * The disableService param determines whether the call is due
        * to service being disabled and thus the rule would get implicitly
        * /internally disabled or due to an explict call to disable the 
        * configured rule.
        */
       String ruleName = ruleInstance.getName();
       Event ruleEvent = ruleInstance.getEvent();
     
 
       try {
           if (ruleInstance.getState() == Rule.ENABLED) {
               //remove the event action binding
               NotificationFilter filter = ruleEvent.getNotificationFilter();
               ObjectName eventObjName = ruleEvent.getObjectName();
               ObjectName actionObjName = (ObjectName)ruleInstance.getAction();

               instanceMbs.removeNotificationListener(eventObjName,actionObjName,
                                                      filter, null);
               ruleInstance.setAction(null);
               if (!disableService) { 
                   activeRules.remove(ruleName);
               }
           } else if (ruleInstance.getState() == Rule.INACTIVE) {
               //remove event binding, default action (when supported)   
               ruleInstance.setAction(null);
               if (!disableService) { 
                   inActiveRules.remove(ruleName);
               }
           } else if (ruleInstance.getState() == Rule.NOACTION) {
               ruleInstance.setAction(null);
               if (!disableService) { 
                   noActionRules.remove(ruleName);
               }
           } 

           //notificationfiltersupport?
           ruleEvent.destroy();
           ruleInstance.setEvent(null);
           if (!disableService) {
               //call is for explict rule disable
               ruleInstance.setEnabled(false);
               ruleInstance.setState(Rule.DISABLED);
               disabledRules.put(ruleName,ruleInstance);    
               
           }
       } catch (Exception ex) {
           _logger.log(Level.WARNING,"sgmt.error_disablerule", 
                       new Object[]{ruleName,ex});
           throw ex;
       }               

   
synchronized voiddisableService()
Handles disabling the service. Would internally disable all enabled rules.

      int size = activeRules.size() + inActiveRules.size() + noActionRules.size(); 
      Map<String,Rule> completeMap = (Map<String,Rule>) new HashMap(size);
      completeMap.putAll(activeRules);
      completeMap.putAll(inActiveRules);
      completeMap.putAll(noActionRules);

      Set<String> rules = completeMap.keySet();
      for (String name : rules) {
          Rule ruleInstance = completeMap.get(name);
          disableRule(ruleInstance,true);
      }
  
private javax.management.ObjectNamegetCascadedObjectName(java.lang.String actionMBeanName)

        ObjectName configObjName = new ObjectName(actionMBeanName);
        String serverNameKey  = ServerTags.SERVER;
        Hashtable properties  = configObjName.getKeyPropertyList();
        properties.put(serverNameKey, instanceName);
        ObjectName casdObjName = new ObjectName(configObjName.getDomain(),
                                                     properties);
        return (casdObjName);
    
private com.sun.enterprise.admin.server.core.CustomMBeanRegistrationgetCustomMBeanRegistration()
Retrives the custom MBean interface responsible for loading/registering the custom defined MBeans.


        //This a temp support, till appropriate provider is provided later
        final String CUSTOM_REGRISTRATION_IMPL_CLASS = 
          "com.sun.enterprise.admin.mbeans.custom.loading.CustomMBeanRegistrationImpl";
        CustomMBeanRegistration customObj = null; 

        Constructor ctor = null;
	Object[] args =  null;

        try {
            Class c = Class.forName(CUSTOM_REGRISTRATION_IMPL_CLASS);
            Class[] params = new Class[]{javax.management.MBeanServer.class};
            ctor = c.getConstructor(params);
            args = new Object[]{instanceMbs};

            customObj = (CustomMBeanRegistration) ctor.newInstance(args); 
        } catch (Exception ex) {
            _logger.log(Level.FINE,"smgt.internal_error", ex);
        }

        return customObj;
    
private RulegetRuleInstance(java.lang.String ruleName)

       Rule rule = null; 
       if (activeRules.containsKey(ruleName)) {
           rule = activeRules.get(ruleName);
       } else if (disabledRules.containsKey(ruleName)) {
           rule = disabledRules.get(ruleName);
       } else if (inActiveRules.containsKey(ruleName)) {
           rule = inActiveRules.get(ruleName);
       } else if (noActionRules.containsKey(ruleName)) {
           rule = noActionRules.get(ruleName);
       }

       return rule;
   
private java.util.MapgetRuleMap(java.lang.String ruleName)

       Map ruleMap = null;
  
       if (activeRules.containsKey(ruleName)) {
           ruleMap = activeRules;
       } else if (disabledRules.containsKey(ruleName)) {
           ruleMap = disabledRules;
       } else if (inActiveRules.containsKey(ruleName)) {
           ruleMap = inActiveRules;
       } else if (noActionRules.containsKey(ruleName)) {
           ruleMap = noActionRules;
       }

       return ruleMap;
   
private javax.management.ObjectNameregisterAction(Event ruleEvent, java.lang.String actionMBeanName, com.sun.enterprise.config.serverbeans.Mbean definedActionMBean, boolean isSystemDefined, java.lang.Object handback)
For valid and enabled rule definitions registers the action to the defined event.

param
ruleEvent
param
actionMBeanName
param
definedActionMBean
param
isSystemDefined
param
handback
return
ObjectName

       ObjectName actionObjName = null;
       ObjectName eventObjName = ruleEvent.getObjectName();
       NotificationFilter filter = ruleEvent.getNotificationFilter();

       try { 
            //check if this is a system defined rule then explictly load the MBean       
            if (isSystemDefined) {
                CustomMBeanRegistration obj = getCustomMBeanRegistration();
                actionObjName = obj.registerMBean(definedActionMBean);
                instanceMbs.addNotificationListener(eventObjName, actionObjName,
                                                    filter, null);    
            } else {
                //user defined should have been loaded by adminservice
                //if mbean has defined object name, use that to obtain
                //obj instance else use objectnames static call for apps
                String objName = definedActionMBean.getObjectName();
                if (objName == null) {
                    //should have been assigned implict obj name
                    actionObjName = ObjectNames.getApplicationObjectName(
                                                                   instanceName,
                                                                   actionMBeanName);
                } else {
                    //actionObjName = new ObjectName(objName);
                    actionObjName = getCascadedObjectName(objName);
                }

                instanceMbs.addNotificationListener(eventObjName, actionObjName,
                                                    filter, null);
                if (handback!=null) {
	            createLoggingListener (ruleEvent, handback);
                }
            }  
        } catch (CustomMBeanException ex) {
            if ( ex.getCause() instanceof InstanceAlreadyExistsException) {
                String objName = definedActionMBean.getObjectName();
                actionObjName = getCascadedObjectName(objName); 
            } else {
                throw ex;
            }
        }

      return actionObjName;
    
private java.lang.ObjectregisterAlertAction(Event ruleEvent, java.lang.String actionMBeanName, java.lang.String ruleName, java.lang.Object handback)
Registers MailAlert listener for the defined enabled rule incase the there has been error loading/registering the action when loading the system applications.

param
ruleEvent
param
actionMBeanName
param
ruleName
param
handback

        NotificationFilterSupport filter = null;
        if (srvAlertRecipients == null) {
            //disable the event in filter
            filter = new NotificationFilterSupport();
            filter.disableAllTypes();
        }
        String subject = localStrings.getString("ruleMgr.alert_action",
                                                    ruleName, actionMBeanName);
        MailAlert alertAction = new MailAlert();
        alertAction.setSubject(subject);
        alertAction.setRecipients(srvAlertRecipients);
        

        ObjectName eventObjName = ruleEvent.getObjectName();
        // instanceMbs.addNotificationListener(eventObjName, alertAction, filter, null);
	createLoggingListener (ruleEvent, handback);

        return alertAction; 
    
public voidsetMailSMTPHost(java.lang.String value)
Sets the service property which defines the mail SMTP host to be used for sending the service alert messages

param
value SMTP host

        if ( mailSMTPHost != null) {
            mailSMTPHost = value;
        } else {
            mailSMTPHost = "localhost";
        }
    
public voidsetRecipients(java.lang.String value)
Sets the service property which defines the recipients of alert messages from the service

param
value Recipients of alert messages

        srvAlertRecipients = value;
    
private voidsetupRuleBinding(int ruleState, Rule ruleInstance, Event ruleEvent, java.lang.Object action)
Setup the the bindings for the RuelManager for defined rules in domain.xml

param
ruleState
param
ruleInstance
param
ruleEvent
param
action Incase of enabled rule, this would be it's object name Incase of inactive rule, this would be mail alert obj listener.

        
        String ruleName = ruleInstance.getName();
        
	Map ruleMap = getRuleMap(ruleName);
	if (ruleMap != null) 
	    ruleMap.remove(ruleName);
        ruleInstance.setState(ruleState);
        if (ruleState != Rule.DISABLED) {
            ruleInstance.setEvent(ruleEvent);
            ruleInstance.setAction(action);
            ruleInstance.setEnabled(true);
        }
        
        switch (ruleState) {
        case Rule.ENABLED:           
            activeRules.put(ruleName, ruleInstance);
            break;
             
        case Rule.INACTIVE:
            inActiveRules.put(ruleName, ruleInstance);
            break;
        
        case Rule.NOACTION:
            noActionRules.put(ruleName, ruleInstance);
            break;
            
        case Rule.DISABLED:
            //event and action would be null by default during rule creation
            disabledRules.put(ruleName, ruleInstance);
            break;
        }
    
voidupdateRule(com.sun.enterprise.config.serverbeans.ManagementRule rule, com.sun.enterprise.config.ConfigUpdate configUp, com.sun.enterprise.config.ConfigContext ctxToUse)
Handles an update to a configured rule.

param
rule - The config bean for the rule from the old config context
param
configUp - Contains the config changes for the rule
param
ctxToUse - The updated config context

       String name = rule.getName();
       Rule ruleInstance = getRuleInstance(name);

       // null should not be the case with validator check
       if (ruleInstance!=null) {
           synchronized(ruleInstance) {
               String description = ruleInstance.getDescription();
               Set<String> attributesChg = configUp.getAttributeSet();
               for (String attribute : attributesChg) {
                   if (attribute.equals(ServerTags.ENABLED)) {
                       String oldValue = configUp.getOldValue(attribute);
                       String newValue = configUp.getNewValue(attribute);
                       _logger.log(Level.INFO,"sgmt.updateruleattribute",
                                   new Object[]{attribute,oldValue,newValue});
                       if (ruleInstance.isEnabled() && newValue.equals("false")) {
                           if (service.isServiceEnabled()) {
                               //disable the rule
                               disableRule(ruleInstance,false);
                               _logger.log(Level.INFO,"smgt.disabledrule",
                                           new Object[]{name,description});
                            } else {
                               //with validator, may not need this 
                               _logger.log(Level.WARNING,"sgmt.error_disablerule_noservice",
                                           new Object[]{name,description});
                            }
                       } else if (!ruleInstance.isEnabled() && newValue.equals("true")) {
                           //enabled the rule
                           if (service.isServiceEnabled()) {
                               service.addRule(rule,ctxToUse);
                               _logger.log(Level.INFO,"smgt.enabledrule", 
                                           new Object[]{name,description});
                           } else {
                               //with validator, may not need this 
                               _logger.log(Level.WARNING,"sgmt.error_enablerule_noservice",
                                          new Object[]{name,description});
                           }
                       } else {
                          _logger.log(Level.INFO,"smgt.cannot_changesstate",
                                      new Object[]{name,description});
                       }
                   }
               }
           }
       }
   
private com.sun.enterprise.config.serverbeans.ApplicationRefverifyActionMBean(java.lang.String actionMBeanName, com.sun.enterprise.config.serverbeans.Domain domain, com.sun.enterprise.config.ConfigContext ctxToUse)
Verify's whether the action MBean is a referenced application by the server instance and also has a valid definition at the domain level

param
actionMBeanName
param
domain
return
ApplicationRef

        ApplicationRef appRef = null;
        if (ctxToUse != null) {
           configCtx = ctxToUse;
        }
        
        try {
            Server instanceBean = ServerBeansFactory.getServerBean(configCtx);
            appRef = instanceBean.getApplicationRefByRef(actionMBeanName);
        
            if (appRef == null) {
                //check at cluster level, if this instance is part of cluster
                Clusters clusters = domain.getClusters();
                Cluster[] cluster = clusters.getCluster();
                for (Cluster val : cluster) {
                    if ((val.getServerRefByRef(instanceName)) != null) {
                        appRef = val.getApplicationRefByRef(actionMBeanName);
                        break;
                    } 
                }
            }
        
            //should have obtained the app reference, if all well
            if (appRef != null) {
                //check there exists a definition
                Applications apps = domain.getApplications();
                Mbean definedMBean = apps.getMbeanByName(actionMBeanName); 
                if (definedMBean == null ) {
                    appRef = null;
                }
            }
        } catch (ConfigException ex) {
            _logger.log(Level.INFO, "smgt.config_error", ex);
        }
        
        return appRef;