PwcWebModuleStatsImplpublic class PwcWebModuleStatsImpl extends Object implements com.sun.enterprise.web.monitor.PwcWebModuleStatsClass 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.
// 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 int | getActiveSessionsCurrent()Gets the number of currently active sessions for the web module.
.
return getIntValue(queryStatistic(sessionManagerObjName,
"activeSessions"));
| public int | getActiveSessionsHigh()Gets the maximum number of concurrently active sessions for the web
module.
return getIntValue(queryStatistic(sessionManagerObjName,
"maxActive"));
| public int | getExpiredSessionsTotal()Gets the total number of expired sessions for the web module.
.
return getIntValue(queryStatistic(sessionManagerObjName,
"expiredSessions"));
| private int | getIntValue(java.lang.Object resultObj)
int result = 0;
if (resultObj != null) {
Integer countObj = (Integer)resultObj;
result = countObj.intValue();
}
return result;
| public int | getJspCount()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 queryWildcardStatistic(jspMonitorObjName, "jspCount");
| public int | getJspErrorCount()Gets the number of errors that were triggered by JSP invocations.
.
return queryWildcardStatistic(jspMonitorObjName, "jspErrorCount");
| public int | getJspReloadCount()Gets the number of JSPs that have been reloaded in the web module.
.
return queryWildcardStatistic(jspMonitorObjName, "jspReloadCount");
| private long | getLongValue(java.lang.Object resultObj)
long result = 0;
if (resultObj != null) {
Long countObj = (Long)resultObj;
result = countObj.longValue();
}
return result;
| public int | getRejectedSessionsTotal()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 getIntValue(queryStatistic(sessionManagerObjName,
"rejectedSessions"));
| public long | getServletProcessingTimesMillis()Gets the cumulative processing times of all servlets in the web module
associated with this PwcWebModuleStatsImpl.
return getLongValue(queryStatistic(ctxObjName, "processingTimeMillis"));
| public java.util.HashMap | getSession(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.
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 int | getSessionAverageAliveTimeSeconds()Gets the average time (in seconds) that expired sessions had been
alive.
return getIntValue(queryStatistic(sessionManagerObjName,
"sessionAverageAliveTimeSeconds"));
| public java.lang.String | getSessionIds()Returns the 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 int | getSessionMaxAliveTimeSeconds()Gets the longest time (in seconds) that an expired session had been
alive.
return getIntValue(queryStatistic(sessionManagerObjName,
"sessionMaxAliveTimeSeconds"));
| public int | getSessionsTotal()Gets the total number of sessions that have been created for the web
module.
.
return getIntValue(queryStatistic(sessionManagerObjName,
"sessionCount"));
| public long | getStartTimeMillis()Gets the time when the web module was started.
return getLongValue(queryStatistic(ctxObjName, "startTimeMillis"));
| private java.lang.Object | queryStatistic(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 int | queryWildcardStatistic(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.
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 void | readObject(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 void | reset()Resets this PwcWebModuleStats.
// Reset JSP stats
resetWildcardStatistic(jspMonitorObjName, "jspReloadCount");
| private void | resetStatistic(javax.management.ObjectName on, java.lang.String attrName)Resets the value of the given attribute on the MBeans with
the given ObjectName.
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 void | resetWildcardStatistic(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.
Set monitorONs = server.queryNames(wildcardON, null);
Iterator<ObjectName> iter = monitorONs.iterator();
while (iter.hasNext()) {
resetStatistic(iter.next(), attrName);
}
|
|