*/
public static Application getApplication(Context context, ResourceResolver resourceResolver, boolean calcSize) {
logger.debug("Querying webapp: " + context.getName());
Application app = new Application();
app.setName(context.getName().length() > 0 ? context.getName() : "/");
app.setDocBase(context.getDocBase());
app.setDisplayName(context.getDisplayName());
app.setAvailable(context.getAvailable());
app.setDistributable(context.getDistributable());
app.setSessionTimeout(context.getSessionTimeout());
app.setServletVersion(context.getServletContext().getMajorVersion() + "." + context.getServletContext().getMinorVersion());
if (resourceResolver != null) {
logger.debug("counting servlet attributes");
int ctxAttrCount = 0;
for (Enumeration e = context.getServletContext().getAttributeNames(); e.hasMoreElements(); e.nextElement()) {
ctxAttrCount++;
}
app.setContextAttributeCount(ctxAttrCount);
if (app.isAvailable()) {
logger.debug("collecting session information");
app.setSessionCount(context.getManager().findSessions().length);
boolean serializable = true;
int sessionAttributeCount = 0;
long size = 0;
Session[] sessions = context.getManager().findSessions();
for (int i = 0; i < sessions.length; i++) {
ApplicationSession appSession = getApplicationSession(sessions[i], calcSize, false);
if (appSession != null) {
sessionAttributeCount += appSession.getObjectCount();
serializable = serializable && appSession.isSerializable();
size += appSession.getSize();
}
}
app.setSerializable(serializable);
app.setSessionAttributeCount(sessionAttributeCount);
app.setSize(size);
}
logger.debug("aggregating servlet stats");
collectApplicationServletStats(context, app);
if (resourceResolver.supportsPrivateResources() && app.isAvailable()) {
int[] scores = getApplicationDataSourceUsageScores(context, resourceResolver);
app.setDataSourceBusyScore(scores[0]);
app.setDataSourceEstablishedScore(scores[1]);
}
}
return app;
}