FileDocCategorySizeDatePackage
StatsUtil.javaAPI DocGlassfish v2 API9555Fri May 04 22:36:08 BST 2007com.sun.enterprise.web.stats

StatsUtil

public final class StatsUtil extends Object
Utility class for retrieving and manipulating stats.

Fields Summary
private static final Logger
_logger
Constructors Summary
Methods Summary
static longgetAggregateLongStatistic(javax.management.MBeanServer server, javax.management.ObjectName on, java.lang.String attrName)
Queries the MBeans corresponding to the given (wildcard) object name for the value of the attribute with the given name, and returns the aggregated attribute values.

param
server MBean server
param
on MBean object name
param
attrName Attribute name
return
Aggregated attribute values


	long result = 0;

        Iterator iter = server.queryNames(on, null).iterator();
        while (iter.hasNext()) {
            Object obj = StatsUtil.getStatistic(server,
                                                (ObjectName) iter.next(),
                                                attrName);
            if (obj != null) {
                result += getLongValue(obj);
            }
        }

        return result;
    
static intgetAggregateStatistic(javax.management.MBeanServer server, javax.management.ObjectName on, java.lang.String attrName)
Queries the MBeans corresponding to the given (wildcard) object name for the value of the attribute with the given name, and returns the aggregated attribute values.

param
server MBean server
param
on MBean object name
param
attrName Attribute name
return
Aggregated attribute values


	int result = 0;

        Iterator iter = server.queryNames(on, null).iterator();
        while (iter.hasNext()) {
            Object obj = StatsUtil.getStatistic(server,
                                                (ObjectName) iter.next(),
                                                attrName);
            if (obj != null) {
                result += getIntValue(obj);
            }
        }

        return result;
    
static intgetAverageStatistic(javax.management.MBeanServer server, javax.management.ObjectName on, java.lang.String attrName)
Queries the MBeans corresponding to the given (wildcard) object name for the value of the attribute with the given name, and returns the average attribute value.

param
server MBean server
param
on MBean object name
param
attrName Attribute name
return
Average attribute value


        int total = 0;
        int num = 0;

        Iterator iter = server.queryNames(on, null).iterator();
        while (iter.hasNext()) {
            Object obj = StatsUtil.getStatistic(server,
                                                (ObjectName) iter.next(),
                                                attrName);
            if (obj != null) {
                total += getIntValue(obj);
                num++;
            }
        }

        return total/num;
    
static intgetConstant(javax.management.MBeanServer server, javax.management.ObjectName on, java.lang.String attrName)
Queries the first MBeans corresponding to the given (wildcard) object name for the value of the attribute with the given name, and returns it. This method assumes that the given attribute name has the same value for all MBeans corresponding to the given wildcard object name.

param
server MBean server
param
on MBean object name
param
attrName Attribute name
return
Attribute values


	int result = 0;

        Iterator iter = server.queryNames(on, null).iterator();
        if (iter.hasNext()) {
            Object obj = StatsUtil.getStatistic(server,
                                                (ObjectName) iter.next(),
                                                attrName);
            result = getIntValue(obj);
        }

        return result;
    
static intgetIntValue(java.lang.Object resultObj)


        int result = 0;

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

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


        long result = 0;

        if (resultObj instanceof Long) {
            result = ((Long)resultObj).longValue();
        } else if (resultObj instanceof Integer) {
            result = ((Integer)resultObj).intValue();
        }

        return result;
    
static longgetMaxLongStatistic(javax.management.MBeanServer server, javax.management.ObjectName on, java.lang.String attrName)
Queries the MBeans corresponding to the given (wildcard) object name for the value of the attribute with the given name, and returns the largest attribute value.

param
server MBean server
param
on MBean object name
param
attrName Attribute name
return
Largest attribute value


        long max = 0;

        Iterator iter = server.queryNames(on, null).iterator();
        while (iter.hasNext()) {
            Object obj = StatsUtil.getStatistic(server,
                                                (ObjectName) iter.next(),
                                                attrName);
            long result = getLongValue(obj);
            if (result > max) {
                max = result;
            }
        }

        return max;
    
static intgetMaxStatistic(javax.management.MBeanServer server, javax.management.ObjectName on, java.lang.String attrName)
Queries the MBeans corresponding to the given (wildcard) object name for the value of the attribute with the given name, and returns the largest attribute value.

param
server MBean server
param
on MBean object name
param
attrName Attribute name
return
Largest attribute value


	int max = 0;

        Iterator iter = server.queryNames(on, null).iterator();
        while (iter.hasNext()) {
            Object obj = StatsUtil.getStatistic(server,
                                                (ObjectName) iter.next(),
                                                attrName);
            int result = getIntValue(obj);
            if (result > max) {
                max = result;
            }
        }

        return max;
    
static java.lang.ObjectgetStatistic(javax.management.MBeanServer server, javax.management.ObjectName on, java.lang.String attrName)
Queries the MBean with the given object name for the value of the attribute with the given name.

param
server MBean server
param
on MBean object name
param
attrName Attribute name
return
Attribute value



                                           
         
                                   

        Object resultObj = null;

        try {
            resultObj = server.getAttribute(on, attrName);
        } catch (Throwable t) {
            String msg = _logger.getResourceBundle().getString(
                                            "webcontainer.mbeanQueryError");
            msg = MessageFormat.format(msg, new Object[] { attrName, on });
            _logger.log(Level.WARNING, msg, t);
        }

        return resultObj;