StatsUtilpublic final class StatsUtil extends Object Utility class for retrieving and manipulating stats. |
Fields Summary |
---|
private static final Logger | _logger |
Methods Summary |
---|
static long | getAggregateLongStatistic(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.
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 int | getAggregateStatistic(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.
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 int | getAverageStatistic(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.
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 int | getConstant(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.
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 int | getIntValue(java.lang.Object resultObj)
int result = 0;
if (resultObj instanceof Integer) {
Integer countObj = (Integer)resultObj;
result = countObj.intValue();
}
return result;
| static long | getLongValue(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 long | getMaxLongStatistic(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.
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 int | getMaxStatistic(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.
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.Object | getStatistic(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.
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;
|
|