FileDocCategorySizeDatePackage
ManagementRuleReconfig.javaAPI DocGlassfish v2 API11971Fri May 04 22:35:04 BST 2007com.sun.enterprise.management.selfmanagement.reconfig

ManagementRuleReconfig

public final class ManagementRuleReconfig extends Object implements com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEventListener
This class handles dynamic reconfiguration notification related to management-rule creation, update and deletion.
author
Pankaj Jairath

Fields Summary
private static final com.sun.enterprise.management.selfmanagement.SelfManagementService
service
private static final Logger
_logger
Logger for self management service
Constructors Summary
Methods Summary
public synchronized voidhandleCreate(com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEvent event)
Create a new management-rule

    
              
        
                                              
        _logger.log(Level.FINE,"sgmt.reconfig_handlecreatereceived");
        try{             
            ConfigContext configContext = event.getConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            ConfigAdd configAdd = null;
            ConfigChange configChange = null;
            ArrayList<ConfigChange> configChangeList = event.getConfigChangeList();
            ManagementRule rule = null;
            String xpath = null;
            String pXPath = null;
            Object object;
            String ruleName = null;
            for (int i=0; i < configChangeList.size(); i++){
                configChange = configChangeList.get(i);
                if (configChange instanceof ConfigAdd) {
                    _logger.log(Level.INFO,"sgmt.reconfig_handlecreaterulereceived");
                    xpath = configChange.getXPath();
                    if (xpath != null) {
                        _logger.log(Level.INFO, "sgmt.reconfig_handlexpath",xpath);
                        rule = (ManagementRule)configContext.exactLookup(xpath);
                        if (rule.isEnabled())
                            service.addRule(rule, configContext); 
                        else
                            service.addDisabledRule(rule);
                       
                    }
                } else if(configChange instanceof ConfigSet) {
                    //handle action addition
		    pXPath = configChange.getParentXPath();
		    String name = configChange.getName();
		    if (name.equals(ManagementRule.ACTION)) {
		        _logger.log(Level.INFO,"smgt.handleactionadd",pXPath);
		        rule = (ManagementRule)configContext.exactLookup(pXPath);
		        service.handleActionAdd(rule, configContext);
                    }
		}
            }
        } catch (Exception ex) {
           throw new AdminEventListenerException(ex);
        }  
    
public synchronized voidhandleDelete(com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEvent event)
Delete an existing management-rule.

        _logger.log(Level.INFO,"sgmt.reconfig_handledeletereceived");                         
        try{
            ConfigContext oldConfigContext = event.getOldConfigContext();
			ConfigContext configContext = event.getConfigContext();
            ConfigContext adminConfigCtx =
                 AdminService.getAdminService().
                 getAdminContext().getAdminConfigContext();
            Config config = ServerBeansFactory.getConfigBean(adminConfigCtx);
            ConfigDelete configDel = null;
            ArrayList<ConfigDelete> configChangeList = event.getConfigChangeList();
            ManagementRule rule = null;
            String xpath = null;
            Object object;

            for (int i=0; i < configChangeList.size(); i++){
                configDel = configChangeList.get(i);

                xpath = configDel.getXPath();
                if (xpath != null){
                    _logger.log(Level.INFO, "sgmt.reconfig_handledelxpath",xpath);
		    object = oldConfigContext.exactLookup(xpath); 
                    if (object instanceof Action) {
                        //handle action removal - noaction
                        String realXPath = xpath.substring(0,xpath.lastIndexOf("/"));
                        rule = (ManagementRule) adminConfigCtx.exactLookup(realXPath);
                        String ruleName = rule.getName();
                        service.deleteAction(ruleName);
                    } else if (object instanceof ManagementRule) {
                        rule = (ManagementRule)object;
                        String ruleName = rule.getName();
                        service.deleteRule(ruleName);
                    } else {
                        String realXPath = xpath.substring(0,xpath.lastIndexOf("/"));
                        rule = (ManagementRule) adminConfigCtx.exactLookup(realXPath);
                        String ruleName = rule.getName();
                        service.deleteAction(ruleName);
		    }
                }
            }
        }  catch( Exception ex){
           throw new AdminEventListenerException(ex);
        }      
    
public synchronized voidhandleUpdate(com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEvent event)
Update an existing management-rule.

   
        _logger.log(Level.INFO,"sgmt.reconfig_handleupdatereceived");
        try {
            ConfigContext configContext = event.getConfigContext();
            ConfigContext adminConfigCtx =
                        AdminService.getAdminService().
                        getAdminContext().getAdminConfigContext();
            Config config = ServerBeansFactory.getConfigBean(configContext);
            ConfigUpdate configUp = null;
            ArrayList<ConfigUpdate> configChangeList = event.getConfigChangeList();
            String xPath = null;
            Object object;

            for (int i=0; i < configChangeList.size(); i++){
	        if (configChangeList.get(i) instanceof ConfigAdd ||
		    configChangeList.get(i) instanceof ConfigSet ||
		    configChangeList.get(i) instanceof ConfigDelete) {
		    ConfigChange change = configChangeList.get(i);
		    xPath =  change.getXPath();
	        } else {
                    configUp = configChangeList.get(i);
                    xPath = configUp.getXPath();
	        }
                if (xPath!=null) {
                    _logger.log(Level.INFO,"sgmt.handleupdatexpath", xPath);
                    object = configContext.exactLookup(xPath);
                    if (object instanceof ManagementRules) {
                        ManagementRules rules = (ManagementRules)object;
                        service.handleRulesUpdate(configContext,configUp);
                    } else if(object instanceof ManagementRule) {
                        ManagementRule rule = (ManagementRule)configContext.exactLookup(xPath); 
                        service.handleRuleUpdate(rule,configUp,configContext);
                    } else {
                        String pXPath = null;
                        if(object instanceof ElementProperty ||
			   xPath.lastIndexOf("element-property") >= 0  ) {
                            pXPath = xPath.substring(0,xPath.lastIndexOf("/"));
                            if(pXPath != null) {
                                pXPath = pXPath.substring(0,pXPath.lastIndexOf("/"));
                            }
                        } else {
                            pXPath = xPath.substring(0,xPath.lastIndexOf("/"));
                        }
                        if(pXPath != null) {
                            ManagementRule rule = (ManagementRule)configContext.exactLookup(pXPath); 
                            if(rule != null) {
                                String ruleName = rule.getName();

                                //Delete the rule (will delete the rule runtime)
                                service.deleteRule(ruleName);

                                //Recreate the rule
                                if (rule.isEnabled()) {
                                    service.addRule(rule, adminConfigCtx);
                                } else {
                                    service.addDisabledRule(rule);
                                }
                            }
                        }
                        break;
                    }
                 }
            }
                     
       
        } catch (Exception ex) {
           throw new AdminEventListenerException(ex);
        }