Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Telling who is logged onto my jsp application and occasionally logging their activities  RSS feed

 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We have an open source project to create online training simulations. (More info at opensimplatform.org)

The entire technology stack from client to back-end is: AJAX - JSP (Running on Apache-Tomcat) - POJOS - Hibernate - MYSQL.

When people log on I give them an object in their session that retains the fact that they are logged in. I have an AJAX script that sends heartbeat pulses back to let me know they are still logged on. This information gets persisted back to the database every minute.

I have some simple questions on what would be the best practices:

How can I tell if their session has just terminated from them closing the browser, as opposed to a log out event (which I can easily log) ?

How can I occasionally tell the server to log information regarding the user activities? I want to keep track of what parts of the simulations users are spending the most time in, but I figure that if I rely on user activity to trigger logging, then I'll miss logging some events if the user just goes into inactivity and their sessions eventually drop. (Is there a way to start up a thread to just do logging every 5 minutes on the web server, or is that a bad idea?)

I guess these are basic questions. If there are some simple, recommended ways to handle these issues, I'll be most appreciative to know them.

Best,
Skip
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Skip Cole wrote:How can I tell if their session has just terminated from them closing the browser
You can't. If the heartbeat stops, they've either closed the browser or navigated elsewhere. You can't tell the difference.

How can I occasionally tell the server to log information regarding the user activities?
Personally I never do stuff like this in the app. Rather I do analysis on the access logs on the server.
 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for your quick response in this.

What do you look at for in the server logs? Is there an easy way to link an exact identity (a user logged onto my application) to a session?

Your response makes me think there is no better standard way to do this than what I am doing. I'd like to set up a timer inside the web application that periodically persists user information, but I'm concerned about thread safety. I really don't know very much about the inner workings of servlet engines. I just hack around and get things to work and this sounds like a place where I could run into trouble.

Another thing I could try to do is to save things when the web application goes down - for example when Apache is stopped. But this also appears to me that it might run into trouble. (I don't know how long Apache/Tomcat will wait to shut down if my application is busy persisting data as it does.)

Best,
Skip

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each container implementation has its own manner to set up access logs. You'll need to check with the documentation of whichever container you are using.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36441
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Skip Cole wrote:How can I tell if their session has just terminated from them closing the browser, as opposed to a log out event (which I can easily log) ?

You can set up a listener to tell you when the session is invalidated. This includes from timeouts. Which you will get 30 or 60 or however many minutes after they close the browser.

Skip Cole wrote:How can I occasionally tell the server to log information regarding the user activities? I want to keep track of what parts of the simulations users are spending the most time in, but I figure that if I rely on user activity to trigger logging, then I'll miss logging some events if the user just goes into inactivity and their sessions eventually drop. (Is there a way to start up a thread to just do logging every 5 minutes on the web server, or is that a bad idea?)

You could use a timer in AJAX (setTimeout I believe the method is called) to push a status update. I don't recommend it though as it is unnecessary traffic.
 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this information.

Hopefully the heartbeat pulses sent back won't be too much traffic for the app, but they are kind of necessary.

We are trying to set up a fairly generic application, so from what I'm hearing I won't be able to do much more than I had planned. I do not want to, for example, get into doing container specific coding. That seems to me big hole into which one can pour many hours.

I want to be able to login to a control panel and see which users are online, and to also be able to log users off. This last trick seems doable, but it will require that I put some checks in log them out when the controller has invalidated something in their session. Fun :-)

I'll probably have most of this done and incorporated into our code base at http://code.google.com/p/opensimplatform/ So if someone is looking for code that does all of this after around 1 June 2009, it will be there.

Best,
Skip
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!