}
return scores;
}
public static ApplicationSession getApplicationSession(Session session, boolean calcSize, boolean addAttributes) {
ApplicationSession sbean = null;
if (session != null && session.isValid()) {
sbean = new ApplicationSession();
sbean.setId(session.getId());
sbean.setCreationTime(new Date(session.getCreationTime()));
sbean.setLastAccessTime(new Date(session.getLastAccessedTime()));
sbean.setMaxIdleTime(session.getMaxInactiveInterval() * 1000);
sbean.setManagerType(session.getManager().getClass().getName());
sbean.setInfo(session.getInfo());
boolean sessionSerializable = true;
int attributeCount = 0;
long size = 0;
HttpSession httpSession = session.getSession();
Set processedObjects = new HashSet(1000);
try {
for (Enumeration e = httpSession.getAttributeNames(); e.hasMoreElements();) {
String name = (String) e.nextElement();
Object o = httpSession.getAttribute(name);
sessionSerializable = sessionSerializable && o instanceof Serializable;
long oSize = 0;
if (calcSize) {
try {
oSize += Instruments.sizeOf(name, processedObjects);
oSize += Instruments.sizeOf(o, processedObjects);
} catch (Throwable th) {
logger.error("Cannot estimate size of attribute \"" + name + "\"", th);
//
// make sure we always re-throw ThreadDeath
//
if (e instanceof ThreadDeath) {
throw (ThreadDeath) e;
}
}
}
if (addAttributes) {
Attribute saBean = new Attribute();
saBean.setName(name);
saBean.setType(ClassUtils.getQualifiedName(o.getClass()));
saBean.setValue(o);
saBean.setSize(oSize);
saBean.setSerializable(o instanceof Serializable);
sbean.addAttribute(saBean);
}
attributeCount++;
size += oSize;
}
String lastAccessedIP = (String) httpSession.getAttribute(ApplicationSession.LAST_ACCESSED_BY_IP);
if (lastAccessedIP != null) {
sbean.setLastAccessedIP(lastAccessedIP);
}
try {
sbean.setLastAccessedIPLocale(InetAddressLocator.getLocale(InetAddress.getByName(lastAccessedIP).getAddress()));
} catch (Throwable e) {
logger.error("Cannot determine Locale of "+lastAccessedIP);
//
// make sure we always re-throw ThreadDeath
//
if (e instanceof ThreadDeath) {
throw (ThreadDeath) e;
}
}
} catch (IllegalStateException e) {
logger.info("Session appears to be invalidated, ignore");
}
sbean.setObjectCount(attributeCount);
sbean.setSize(size);
sbean.setSerializable(sessionSerializable);
}
return sbean;
}