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

PwcServletStatsImpl

public class PwcServletStatsImpl extends Object implements com.sun.enterprise.web.monitor.PwcServletStats

Fields Summary
private transient MBeanServer
server
private ObjectName
servletObjName
Constructors Summary
public PwcServletStatsImpl(String domain, String vsId, String contextPath, String servletName, String appName, String serverName)
Constructor. The ObjectName of the Servlet MBean follows this pattern: :j2eeType=Servlet,name=, WebModule=,J2EEApplication=, J2EEServer= Example: com.sun.appserv:j2eeType=Servlet,name=default, WebModule=//server/,J2EEApplication=null,J2EEServer=server

param
domain Domain in which the Servlet MBean is registered
param
vsId Id of the virtual-server for which servlet monitoring is being enabled
param
contextPath Context path of the webmodule
param
servletName Name of the Servlet/JSP
param
appName Name of the J2EE App to which the web module belongs, or null if web module is standalone
param
serverName Name of the server instance

        
        // 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();

        // Construct the ObjectName of the Servlet MBean
        String objNameStr = domain
                + ":j2eeType=Servlet"
                + ",name=" + servletName
                + ",WebModule=" + createTomcatWebModuleName(vsId, contextPath)
                + ",J2EEApplication=" + appName
                + ",J2EEServer=" + serverName;
        try {
            servletObjName = new ObjectName(objNameStr);
        } catch (Throwable t) {
            MonitorUtil.log(Level.SEVERE,
                            "pwc.monitoring.objectNameCreationError",
                            new Object[] { objNameStr },
                            t);
        }
    
Methods Summary
private java.lang.StringcreateTomcatWebModuleName(java.lang.String vsId, java.lang.String contextPath)


        final String PREFIX = "//";
        String tcWebModuleName;

        if ((contextPath != null) && (!contextPath.equals(""))) {
            tcWebModuleName = PREFIX + vsId + contextPath;
        } else {
            tcWebModuleName = PREFIX + vsId + "/";
        }

        return tcWebModuleName;
    
public intgetErrorCount()
Gets the number of requests processed by the servlet being monitored that resulted in errors.

return
Error count

        return getIntValue(queryStatistic(servletObjName, "errorCount"));
    
private intgetIntValue(java.lang.Object resultObj)


        int result = 0;

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

        return result;
    
private longgetLongValue(java.lang.Object resultObj)


        long result = 0;

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

        return result;
    
public longgetMaxTimeMillis()
Gets the maximum request processing time of the servlet being monitored.

return
Maximum request processing time

        return getLongValue(queryStatistic(servletObjName, "maxTimeMillis"));
    
public longgetMinTimeMillis()
Gets the minimum request processing time of the servlet being monitored.

return
Minimum request processing time

        return getLongValue(queryStatistic(servletObjName, "minTimeMillis"));
    
public longgetProcessingTimeMillis()
Gets the total execution time of the service method of the servlet being monitored.

return
Execution time of the servlet's service method

        return getLongValue(queryStatistic(servletObjName,
                                           "processingTimeMillis"));
    
public intgetRequestCount()
Gets the number of requests processed by the servlet being monitored.

return
Number of processed requests

        return getIntValue(queryStatistic(servletObjName, "requestCount"));
    
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 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();
        }