FileDocCategorySizeDatePackage
ManagementRulesMBeanHelper.javaAPI DocGlassfish v2 API26008Fri May 04 22:33:44 BST 2007com.sun.enterprise.admin.selfmanagement.event

ManagementRulesMBeanHelper

public class ManagementRulesMBeanHelper extends Object

Fields Summary
private static Logger
_logger
private static String
instanceName
private static com.sun.enterprise.config.ConfigContext
configCtx
Constructors Summary
Methods Summary
public static java.util.ListgetAllActionMBeans(boolean enabled)
Gets the registred actions in the domain.

param
enabled if true, gets only enabled actions, otherwise all actions.
returns
registered actions
throws
ConfigException

        List<String> actionMBeanList = new ArrayList<String>();
        List<Mbean> mbeanList = ServerBeansFactory.getAllMBeanDefinitions(getConfigContext());
        for (Mbean  mbean : mbeanList) {
            if (enabled && !mbean.isEnabled())
                continue;
            String implClassName = mbean.getImplClassName();
            if (implementsInterface(implClassName, "javax.management.NotificationListener"))
                actionMBeanList.add(mbean.getName());
        }
        return actionMBeanList;
    
public static java.util.ListgetAllNotificationEmitterMbeans(boolean enabled)

        List<String> customMBeanList = new ArrayList<String>();
        List<Mbean> mbeanList = ServerBeansFactory.getAllMBeanDefinitions(getConfigContext());
        for (Mbean  mbean : mbeanList) {
            if (enabled && !mbean.isEnabled())
                continue;
            String implClassName = mbean.getImplClassName();
            if (implementsInterface(implClassName, "javax.management.NotificationEmitter"))
                customMBeanList.add(mbean.getName());
        }
        return customMBeanList;
    
public static java.util.ListgetAttributes(javax.management.ObjectName objName)
Gets the attributes for a given ObjectName.

param
objName ObjectName for which the attributes are required.
returns
list of attributes
throws
InstanceNotFoundException,IntrospectionException, ReflectionException

        if (objName == null)
            return new ArrayList<String>(0);
        MBeanInfo mbInfo =  MBeanServerFactory.getMBeanServer().getMBeanInfo(objName);
        MBeanAttributeInfo attrInfoArr[] = mbInfo.getAttributes();
        List<String> attributes = new ArrayList<String>();
        for (MBeanAttributeInfo attrInfo : attrInfoArr) {
            attributes.add(attrInfo.getName());
        }
        return attributes;
    
public static java.util.ListgetAttributes(java.lang.String dottedName)

 return null; 
public static javax.management.ObjectNamegetCascadingAwareObjectName(javax.management.ObjectName configON)

        try {
            final String serverNameKey  = "server";
            //final String serverNameVal  = System.getProperty("com.sun.aas.instanceName");
            final Hashtable properties  = configON.getKeyPropertyList();
            properties.put(serverNameKey, instanceName);
            final ObjectName ron = new ObjectName(configON.getDomain(), properties);
            return ( ron );
        } catch(final Exception e) {
            throw new RuntimeException(e);
        }
    
private static com.sun.enterprise.config.ConfigContextgetConfigContext()


        
        return AdminService.getAdminService().getAdminContext().getAdminConfigContext();
    
public static java.util.ListgetDottedNames(java.lang.String dottedName)

 return null; 
public static java.util.ListgetEventProperties(java.lang.String eventType)
Gets the properties for a given event type.

param
eventType for a given event type, gets the associated property names.
returns
list of property names associated with an event type

        if (eventType == null || "".equals(eventType))
            return new ArrayList<String>(0);
        List<String> valueList = null;
        if (eventType.equals(EVENT_LIFECYCLE)) {
            valueList = new ArrayList<String>(1);
            valueList.add(PROPERTY_LIFECYCLE_NAME);
            return valueList;
        }
        if (eventType.equals(EVENT_MONITOR)) {
            valueList = new ArrayList<String>();
            valueList.add(PROPERTY_MONITOR_OBSERVED_OBJ);
            valueList.add(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME);
            valueList.add(PROPERTY_MONITOR_OBSERVED_ATTRIBUTE);
            valueList.add(PROPERTY_MONITOR_GRANULARITY_PERIOD);
            valueList.add(PROPERTY_MONITOR_NUMBERTYPE);
            valueList.add(PROPERTY_MONITOR_DIFFERENCEMODE);
            valueList.add(PROPERTY_MONITOR_INIT_THRESHOLD);
            valueList.add(PROPERTY_MONITOR_OFFSET);
            valueList.add(PROPERTY_MONITOR_MODULUS);
            valueList.add(PROPERTY_MONITOR_LOW_THRESHOLD);
            valueList.add(PROPERTY_MONITOR_HIGH_THRESHOLD);
            valueList.add(PROPERTY_MONITOR_STRING_TO_COMPARE);
            valueList.add(PROPERTY_MONITOR_STRING_NOTIFY);
            return valueList;
        }
        if (eventType.equals(EVENT_TRACE)) {
            valueList = new ArrayList<String>(1);
            valueList.add(PROPERTY_TRACE_NAME);
            return valueList;
        }
        if (eventType.equals(EVENT_LOG)) {
            valueList = new ArrayList<String>(2);
            valueList.add(PROPERTY_LOG_LOGGERNAME);
            valueList.add(PROPERTY_LOG_LEVEL);
            return valueList;
        }
        if (eventType.equals(EVENT_TIMER)) {
            valueList = new ArrayList<String>(5);
            valueList.add(PROPERTY_TIMER_PATTERN);
            valueList.add(PROPERTY_TIMER_DATESTRING);
            valueList.add(PROPERTY_TIMER_PERIOD);
            valueList.add(PROPERTY_TIMER_NUMBER_OF_OCCURRENCES);
            valueList.add(PROPERTY_TIMER_MESSAGE);
            return valueList;
        }
        if (eventType.equals(EVENT_NOTIFICATION)) {
            valueList = new ArrayList<String>(2);
            valueList.add(PROPERTY_NOTIFICATION_SOURCEMBEAN);
            valueList.add(PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME);
            return valueList;
        }
        if (eventType.equals(EVENT_CLUSTER)) {
            valueList = new ArrayList<String>(2);
            valueList.add(PROPERTY_CLUSTER_NAME);
            valueList.add(PROPERTY_CLUSTER_SERVERNAME);
            return valueList;
        }
        return new ArrayList<String>(0);
    
public static java.util.ListgetEventPropertyValues(java.lang.String eventType, java.lang.String propertyName)

        if (eventType == null || "".equals(eventType))
            return new ArrayList<String>(0);
        List<String> valueList = null;
        if (eventType.equals(EVENT_LIFECYCLE)) {
            if (PROPERTY_LIFECYCLE_NAME.equals(propertyName)) {
                valueList = new ArrayList<String>(3);
                valueList.add("ready");
                valueList.add("shutdown");
                valueList.add("termination");
                return valueList;
            }
        }
        if (eventType.equals(EVENT_MONITOR)) {
            if (PROPERTY_MONITOR_OBSERVED_OBJ.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_OBSERVED_ATTRIBUTE.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_GRANULARITY_PERIOD.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_TYPE.equals(propertyName)) {
                valueList =  new ArrayList<String>(3);
                valueList.add(PROPERTY_MONITOR_COUNTER);
                valueList.add(PROPERTY_MONITOR_GAUGE);
                valueList.add(PROPERTY_MONITOR_STRING);
                return valueList;
            }
            if (PROPERTY_MONITOR_NUMBERTYPE.equals(propertyName)) {
                valueList = new ArrayList<String>(6);
                valueList.add("long");
                valueList.add("int");
                valueList.add("short");
                valueList.add("double");
                valueList.add("float");
                valueList.add("byte");
                return valueList;
            }
            if (PROPERTY_MONITOR_DIFFERENCEMODE.equals(propertyName)) {
                valueList = new ArrayList<String>(2);
                valueList.add("true");
                valueList.add("false");
                return valueList;
            }
            if (PROPERTY_MONITOR_INIT_THRESHOLD.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_OFFSET.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_MODULUS.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_LOW_THRESHOLD.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_HIGH_THRESHOLD.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_STRING_TO_COMPARE.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
            if (PROPERTY_MONITOR_STRING_NOTIFY.equals(propertyName)) {
                valueList =  new ArrayList<String>(2);
                valueList.add(PROPERTY_MONITOR_STRING_NOTIFY_MATCH);
                valueList.add(PROPERTY_MONITOR_STRING_NOTIFY_DIFFER);
                return valueList;
            }
        }
        if (EVENT_TRACE.equals(eventType)) {
            if (PROPERTY_TRACE_NAME.equals(propertyName)) {
                valueList = new ArrayList<String>(6);
                valueList.add("web_component_method_entry");
                valueList.add("web_component_method_exit");
                valueList.add("request_start");
                valueList.add("request_end");
                valueList.add("ejb_component_method_entry");
                valueList.add("ejb_component_method_exit");
                return valueList;
            }
        }
        if (EVENT_LOG.equals(eventType)) {
            if (PROPERTY_LOG_LOGGERNAME.equals(propertyName)) {
                valueList = new ArrayList<String>();
                Enumeration<String> loggerNames = LogManager.getLogManager().getLoggerNames();
                while (loggerNames.hasMoreElements()) {
                    valueList.add(loggerNames.nextElement());
                }
                return valueList;
            }
            if (PROPERTY_LOG_LEVEL.equals(propertyName)) {
                valueList = new ArrayList<String>();
                valueList.add(Level.ALL.getName());
                valueList.add(Level.CONFIG.getName());
                valueList.add(Level.FINE.getName());
                valueList.add(Level.FINER.getName());
                valueList.add(Level.FINEST.getName());
                valueList.add(Level.INFO.getName());
                valueList.add(Level.SEVERE.getName());
                valueList.add(Level.WARNING.getName());
                return valueList;
            }
        }
        if (EVENT_TIMER.equals(eventType)) {
            if (PROPERTY_TIMER_PATTERN.equals(propertyName) ||
                    PROPERTY_TIMER_DATESTRING.equals(propertyName) ||
                    PROPERTY_TIMER_PERIOD.equals(propertyName) ||
                    PROPERTY_TIMER_NUMBER_OF_OCCURRENCES.equals(propertyName) ||
                    PROPERTY_TIMER_MESSAGE.equals(propertyName) ) {
                return new ArrayList<String>(0);
            }
        }
        if (EVENT_NOTIFICATION.equals(eventType)) {
            if (PROPERTY_NOTIFICATION_SOURCEMBEAN.equals(propertyName)) {
                return getAllNotificationEmitterMbeans(true);
                // return new ArrayList<String>(0);
            }
            if (PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME.equals(propertyName)) {
                return new ArrayList<String>(0);
            }
        }
        if (EVENT_CLUSTER.equals(eventType)) {
            if (PROPERTY_CLUSTER_NAME.equals(propertyName)) {
                valueList = new ArrayList<String>(3);
                valueList.add("start");
                valueList.add("stop");
                valueList.add("fail");
                return valueList;
            }
            if (PROPERTY_CLUSTER_SERVERNAME.equals(propertyName)) {
                valueList = new ArrayList<String>();
                Server servers[] = ServerHelper.getServersInDomain(getConfigContext());
                for (Server server : servers) {
                    valueList.add(server.getName());
                }
                return valueList;
            }
        }
        return new ArrayList<String>(0);
    
public static java.util.ListgetEventTypes(boolean isEE)
Gets the list of event types.

param
isEE if true, gets events for EE, otherwise gets events for PE.
returns
list of event types

        List<String> eventTypeList = new ArrayList<String>();
        eventTypeList.add(EVENT_LIFECYCLE);
        eventTypeList.add(EVENT_LOG);
        eventTypeList.add(EVENT_TIMER);
        eventTypeList.add(EVENT_TRACE);
        eventTypeList.add(EVENT_MONITOR);
        eventTypeList.add(EVENT_NOTIFICATION);
        if (isEE) {
            eventTypeList.add(EVENT_CLUSTER);
        }
        return eventTypeList;
    
public static java.util.ListgetMBeanAttributes(java.lang.String objectNameStr)

        ObjectName objName = new ObjectName(objectNameStr);
        return getAttributes(objName);
    
private static java.lang.ClassLoadergetMBeanClassLoader()

        try {
            return (ClassLoader) Class.forName(
            "com.sun.enterprise.admin.mbeans.custom.loading.MBeanClassLoader").
            newInstance();
        } catch (Exception ex) {
            _logger.log(Level.FINE, " An unexpcted exception occurred " , ex);
        }
       return null;
    
    
public static java.util.ListgetNotificationTypes(javax.management.ObjectName objName)

        if (objName == null)
            return new ArrayList<String>(0);
        MBeanInfo mbInfo =  MBeanServerFactory.getMBeanServer().getMBeanInfo(objName);
        MBeanNotificationInfo notifInfoArr[] = mbInfo.getNotifications();
        List<String> notifications = new ArrayList<String>();
        for (MBeanNotificationInfo notifInfo : notifInfoArr) {
            String notifTypes[] = notifInfo.getNotifTypes();
            for (String notifType : notifTypes)
                notifications.add(notifType);
        }
        return notifications;
    
public static java.util.ListgetNotificationTypes(java.lang.String objectNameStr)

        ObjectName objName = new ObjectName(objectNameStr);
        return getNotificationTypes(objName);
    
public static java.lang.StringgetObjName(java.lang.String mBeanName)

        String objName = null;
        String cascadedObjName = null;
        if (mBeanName != null) {
            try {
                Domain domain = ServerBeansFactory.getDomainBean(configCtx);
                ApplicationRef appRef = verifyMBean(mBeanName, domain);
                if (appRef != null) {
                    Applications apps = domain.getApplications();
                    Mbean definedMBean = apps.getMbeanByName(mBeanName);
                    if(definedMBean != null) {
                        objName = definedMBean.getObjectName();
                        cascadedObjName = getCascadingAwareObjectName(new ObjectName(objName)).toString();
                    }
                }
            } catch(ConfigException ex) {
                _logger.log(Level.INFO, "An unexpected exception occured.", ex);
            } catch (Exception ex) {
                _logger.log(Level.INFO, "An unexpected exception occured.", ex);
            } 
        }                                                                                                                                   
        //objName = ObjectNames.getApplicationObjectName(instanceName,mBeanName);
        /*if (!(objName.endsWith(",server=" + instanceName))) {
            objName = objName + ",server=" + instanceName;
        }*/
        return cascadedObjName;
    
public static java.util.SetgetRegisteredMBeans(java.lang.String filter)
Gets the registred MBeans registered in the server's MBean server.

param
filter ObjectName filter for quering MBean server.
returns
list of registered mbeans
throws
MalformedObjectNameException

        ObjectName userFilteredObjectName = null;
        MBeanServer mbeanServer = MBeanServerFactory.getMBeanServer();
        if (filter != null) {
            userFilteredObjectName = new ObjectName(filter);
            return mbeanServer.queryNames(userFilteredObjectName, null);
        }
        String monitoringObjectNameFilter = "com.sun.appserv:category=monitor,*";
        String jsr77ObjectNameFilter = "com.sun.appserv:category=runtime,*";
        ObjectName monitoringFilteredObjectName = null;
        ObjectName jsr77FilteredObjectName = null;
        try {
            monitoringFilteredObjectName = new ObjectName(monitoringObjectNameFilter);
            jsr77FilteredObjectName = new ObjectName(jsr77ObjectNameFilter);
        } catch (Exception ex) {
            _logger.log(Level.FINE, " An unexpcted exception occurred " , ex);
        }
        Set<ObjectName> setObjNames = mbeanServer.queryNames(monitoringFilteredObjectName, null);
        setObjNames.addAll(mbeanServer.queryNames(jsr77FilteredObjectName,null));
        return setObjNames;
    
private static booleanimplementsInterface(java.lang.String implClassName, java.lang.String interfaceName)

        Class ifList[] = null;
        Class class1 = null;
        try {
            ClassLoader mbeanClLoader = getMBeanClassLoader();
            if (mbeanClLoader != null)
                class1  = Class.forName(implClassName,false,mbeanClLoader);
            else
                class1  = Class.forName(implClassName);
            while (class1 != null) {
                ifList = class1.getInterfaces();
                if(ifList != null) {
                    for (int i=0; i<ifList.length; i++) {
                        String canonicalName = ifList[i].getCanonicalName().trim();
                        if( canonicalName.equals(interfaceName) ) {
                            return true;
                        }
                    }
                    class1 = class1.getSuperclass();
                }
            }
        } catch (Exception ex) {
            _logger.log(Level.FINE, " An unexpcted exception occurred " , ex);
        }
        return false;
    
private static com.sun.enterprise.config.serverbeans.ApplicationRefverifyMBean(java.lang.String mBeanName, com.sun.enterprise.config.serverbeans.Domain domain)

        ApplicationRef appRef = null;
        
        try {
            Server instanceBean = ServerBeansFactory.getServerBean(configCtx);
            appRef = instanceBean.getApplicationRefByRef(mBeanName);
                                                                                                                                               
            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(mBeanName);
                        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(mBeanName);
                if (definedMBean == null ) {
                    appRef = null;
                }
            }
        } catch (ConfigException ex) {
            _logger.log(Level.INFO, "smgt.config_error", ex);
        }
                                                                                                                                               
        return appRef;