If you want to program in the belief that "this will never happen to me" that is your choice. I prefer solutions that scale to situations I could not imagine in the early days. And there's nothing in the requirements articulated so far that you cannot do with a database-based solution -- you just have to be willing to pay the cost of collecting the necessary data.
Ironically, the "cost" in this case is mostly in a wee bit of extra software to write out the current state information to the database (if you know how to do this for model data, you already know what to do here as well :-). The performance differences are likely to be fairly trivial, given that databases cache actively accessed data like this table would contain in memory anyway. But a couple of key points are relevant:
* If you design your primary key to be (server+sessionid) in the first place,
you won't have to make *any* changes if you scale to a distributed environment.
* Tools *outside* your web application can observe and monitor the current
state of your webapp ... you're not stuck with just whatever you enabe inside
your app.
Craig
On 2/21/06, Mario Ivankovits <
[EMAIL PROTECTED]> wrote:
Hi!
> Instead of a database, I used an application-scoped class to track the
> data.
Instead of the application-scoped class I used the mbean stuff to gather
this information.
StandardManagerInterface standardManager =
(StandardManagerInterface)
MBeanUtils.findInstance ("Catalina:host=localhost,path=/opsjs,type=Manager",
StandardManagerInterface.class);
String sessionList = standardManager.listSessionIds();
String sessionIds[] = sessionList.split (" ");
for (int i = 0; i < sessionIds.length; i++)
{
String sessionId = sessionIds[i];
lastAccessedTime =
standardManager.getLastAccessedTime(sessionId);
userInfo = standardManager.getSessionAttribute(sessionId,
"userInfo");
}
where "userInfo" is a session attribute setup by the application using a
servlet filter.
The StandardManagerInterface is a simple local interface which contains
the methods I wished to get connected to the mbean.
public interface StandardManagerInterface
{
public String listSessionIds();
public String getLastAccessedTime(String sessionId);
public String getSessionAttribute(String sessionId, String key);
}
But ok, this heavily depends on the used container. It was just a test
to play around with the mbeans in tomcat.
Ciao,
Mario

