FileDocCategorySizeDatePackage
PwcWebModuleStatsImpl.javaAPI DocGlassfish v2 API16917Fri May 04 22:34:10 BST 2007com.sun.enterprise.web.monitor.impl

PwcWebModuleStatsImpl

public class PwcWebModuleStatsImpl extends Object implements com.sun.enterprise.web.monitor.PwcWebModuleStats
Class responsible for gathering web module statistics.

Fields Summary
private static final String
WEB_MODULE_PREFIX
private static final String
LIST_SESSION_IDS
private static final String
GET_SESSION
private static final String[]
STRING_PARAM
private static final Integer
ZERO_INTEGER
private ObjectName
jspMonitorObjName
private ObjectName
sessionManagerObjName
private ObjectName
ctxObjName
private transient MBeanServer
server
Constructors Summary
public PwcWebModuleStatsImpl(String ctxObjNameStr, String ctxPath, String domain, String vsId, String appName, String serverName)
Constructor.

param
ctxObjNameStr Context object name
param
ctxPath Context path
param
domain Domain in which the Servlet MBean is registered
param
vsId The id of the virtual-server on which the web module has been deployed
param
appName Name of the J2EE application to which the web module belongs, or null if the web module is standalone
param
serverName The server instance name



                                                                                      
      
                                  
                                  
                                  
                                  
                                   

        // Get an instance of the MBeanServer
        ArrayList servers = MBeanServerFactory.findMBeanServer(null);
        if(servers != null && !servers.isEmpty()) {
            server = (MBeanServer)servers.get(0);
        } else {
            server = MBeanServerFactory.createMBeanServer();
        }

        if ("".equals(ctxPath)) {
            ctxPath = "/";
        }

        /*
         * j2eeType=WebModule
         */
        try {
            ctxObjName = new ObjectName(ctxObjNameStr);
        } catch (Throwable t) {
            MonitorUtil.log(Level.SEVERE,
                            "pwc.monitoring.objectNameCreationError",
                            new Object[] { ctxObjNameStr },
                            t);
        }

        /*
         * type=JspMonitor
         */
        String objNameStr = domain
                + ":type=JspMonitor"
                + ",WebModule=" + WEB_MODULE_PREFIX + vsId + ctxPath
                + ",J2EEApplication=" + appName
                + ",J2EEServer=" + serverName
                + ",*";
        try {
            jspMonitorObjName = new ObjectName(objNameStr);
        } catch (Throwable t) {
            MonitorUtil.log(Level.SEVERE,
                            "pwc.monitoring.objectNameCreationError",
                            new Object[] { objNameStr },
                            t);
        }

        /*
         * type=Manager
         */
        objNameStr = domain + ":type=Manager,path=" + ctxPath
                + ",host=" + vsId;
        try {
            sessionManagerObjName = new ObjectName(objNameStr);
        } catch (Throwable t) {
            MonitorUtil.log(Level.SEVERE,
                            "pwc.monitoring.objectNameCreationError",
                            new Object[] { objNameStr },
                            t);
        }

    
Methods Summary
public intgetActiveSessionsCurrent()
Gets the number of currently active sessions for the web module. .

return
Number of currently active sessions

        return getIntValue(queryStatistic(sessionManagerObjName,
                                          "activeSessions"));
    
public intgetActiveSessionsHigh()
Gets the maximum number of concurrently active sessions for the web module.

return
Maximum number of concurrently active sessions

        return getIntValue(queryStatistic(sessionManagerObjName,
                                          "maxActive"));
    
public intgetExpiredSessionsTotal()
Gets the total number of expired sessions for the web module. .

return
Total number of expired sessions

        return getIntValue(queryStatistic(sessionManagerObjName,
                                          "expiredSessions"));
    
private intgetIntValue(java.lang.Object resultObj)


        int result = 0;

        if (resultObj != null) {
            Integer countObj = (Integer)resultObj;
            result = countObj.intValue();
        }

        return result;
    
public intgetJspCount()
Gets the number of JSPs that have been loaded in the web module. Web modules may have more than one JspServlet and associated JspMonitoring MBean: There is one JspServlet declared in and inherited from default-web.xml, plus one JspServlet for each servlet mapped to a jsp-file in web.xml. Therefore, the ObjectName that is queried for JSP related statistics ("jspMonitorObjName") is constructed as a wildcard name, and the queryWildcardStatistic() method will enumerate all matching ObjectNames, retrieve their individual values for the requested monitoring attribute, and return an aggregate value. .

return
Number of JSPs that have been loaded

        return queryWildcardStatistic(jspMonitorObjName, "jspCount");
    
public intgetJspErrorCount()
Gets the number of errors that were triggered by JSP invocations. .

return
Number of errors triggered by JSP invocations

        return queryWildcardStatistic(jspMonitorObjName, "jspErrorCount");
    
public intgetJspReloadCount()
Gets the number of JSPs that have been reloaded in the web module. .

return
Number of JSPs that have been reloaded

        return queryWildcardStatistic(jspMonitorObjName, "jspReloadCount");
    
private longgetLongValue(java.lang.Object resultObj)


        long result = 0;

        if (resultObj != null) {
            Long countObj = (Long)resultObj;
            result = countObj.longValue();
        }

        return result;
    
public intgetRejectedSessionsTotal()
Gets the total number of rejected sessions for the web module.

This is the number of sessions that were not created because the maximum allowed number of sessions were active.

return
Total number of rejected sessions

        return getIntValue(queryStatistic(sessionManagerObjName,
                                          "rejectedSessions"));
    
public longgetServletProcessingTimesMillis()
Gets the cumulative processing times of all servlets in the web module associated with this PwcWebModuleStatsImpl.

return
Cumulative processing times of all servlets in the web module associated with this PwcWebModuleStatsImpl

        return getLongValue(queryStatistic(ctxObjName, "processingTimeMillis"));
    
public java.util.HashMapgetSession(java.lang.String id)
Returns information about the session with the given id.

The session information is organized as a HashMap, mapping session attribute names to the String representation of their values.

param
id Session id
return
HashMap mapping session attribute names to the String representation of their values, or null if no session with the specified id exists, or if the session does not have any attributes


        Object resultObj = null;

        try {
            resultObj = server.invoke(sessionManagerObjName,
                                      GET_SESSION,
                                      new Object[] { id },
                                      STRING_PARAM);
        } catch (Throwable t) {
            // Ignore if session has been invalidated
            if (!(t instanceof IllegalStateException)) {
                MonitorUtil.log(Level.SEVERE,
                                "pwc.monitoring.actionInvocationError", 
                                new Object[] { GET_SESSION,
                                               sessionManagerObjName },
                                t);
            }
        }

        return (HashMap) resultObj;
    
public intgetSessionAverageAliveTimeSeconds()
Gets the average time (in seconds) that expired sessions had been alive.

return
Average time (in seconds) that expired sessions had been alive.

        return getIntValue(queryStatistic(sessionManagerObjName,
                                          "sessionAverageAliveTimeSeconds"));
    
public java.lang.StringgetSessionIds()
Returns the session ids of all currently active sessions.

return
Session ids of all currently active sessions


        Object resultObj = null;

        try {
            resultObj = server.invoke(sessionManagerObjName, 
                                      LIST_SESSION_IDS,
                                      null,
                                      null);
        } catch (Throwable t) {
            MonitorUtil.log(Level.SEVERE,
                            "pwc.monitoring.actionInvocationError", 
                            new Object[] { LIST_SESSION_IDS,
                                           sessionManagerObjName },
                            t);
        }

        return (String) resultObj;
    
public intgetSessionMaxAliveTimeSeconds()
Gets the longest time (in seconds) that an expired session had been alive.

return
Longest time (in seconds) that an expired session had been alive.

        return getIntValue(queryStatistic(sessionManagerObjName,
                                          "sessionMaxAliveTimeSeconds"));
    
public intgetSessionsTotal()
Gets the total number of sessions that have been created for the web module. .

return
Total number of sessions created

        return getIntValue(queryStatistic(sessionManagerObjName,
                                          "sessionCount"));
    
public longgetStartTimeMillis()
Gets the time when the web module was started.

return
Time (in milliseconds since January 1, 1970, 00:00:00) when the web module was started

        return getLongValue(queryStatistic(ctxObjName, "startTimeMillis"));
    
private java.lang.ObjectqueryStatistic(javax.management.ObjectName on, java.lang.String attrName)


        Object resultObj = null;
        try {
            resultObj = server.getAttribute(on, attrName);
        } catch (Throwable t) {
            MonitorUtil.log(Level.SEVERE,
                            "pwc.monitoring.queryError",
                            new Object[] { attrName, on },
                            t);
        }

        return resultObj;
    
private intqueryWildcardStatistic(javax.management.ObjectName wildcardON, java.lang.String attrName)
Queries the MBeanServer for the given monitoring attribute for all MBeans that match the given wildcard ObjectName.

param
wildcardON The wildcard ObjectName
param
attrName The name of the attribute whose value is to be returned
return
The value corresponding to the given attribute name, aggregated over all MBeans that match the given wildcard ObjectName


	int result = 0;

        Set monitorONs = server.queryNames(wildcardON, null);
        Iterator iter = monitorONs.iterator();
        while (iter.hasNext()) {

            ObjectName monitorON = (ObjectName) iter.next();
            Object obj = queryStatistic(monitorON, attrName);
            if (obj != null) {
                result += getIntValue(obj);
            }
        }

        return result;
    
private voidreadObject(java.io.ObjectInputStream ois)


        ois.defaultReadObject();

        // Get an instance of the MBeanServer
        ArrayList servers = MBeanServerFactory.findMBeanServer(null);
        if (servers != null && !servers.isEmpty()) {
            server = (MBeanServer)servers.get(0);
        } else {
            server = MBeanServerFactory.createMBeanServer();
        }
    
public voidreset()
Resets this PwcWebModuleStats.


        // Reset JSP stats
        resetWildcardStatistic(jspMonitorObjName, "jspReloadCount");
    
private voidresetStatistic(javax.management.ObjectName on, java.lang.String attrName)
Resets the value of the given attribute on the MBeans with the given ObjectName.

param
on The MBean's ObjectName
param
attrName Name of the attribute to be reset


        Attribute attr = new Attribute(attrName, ZERO_INTEGER);
        try {
            server.setAttribute(on, attr);
        } catch (Throwable t) {
            MonitorUtil.log(Level.SEVERE,
                            "pwc.monitoring.resetError",
                            new Object[] { attrName, on },
                            t);
        }
    
private voidresetWildcardStatistic(javax.management.ObjectName wildcardON, java.lang.String attrName)
Resets the value of the given attribute on all MBeans whose ObjectName matches the given wildcard ObjectName.

param
wildcardON The wildcard ObjectName
param
attrName Name of the attribute to be reset


        Set monitorONs = server.queryNames(wildcardON, null);
        Iterator<ObjectName> iter = monitorONs.iterator();
        while (iter.hasNext()) {
            resetStatistic(iter.next(), attrName);
        }