Our customer would like to know who is online and currently using the custom application we wrote for them. I discussed it with them and this does not need to be exact, more of a guestimate will work.
So my thought is a 15 minute time interval to determine user activity. Some ideas I have for doing this are as follows:
Stamp their user record with a date and time of their last activity every time they do something that hits the database, or requests a web page ... this though could be quite database intensive.
Send out a "who is online request" from our software, looking for responses, this could be done at a scheduled interval, and then stamp the user record with the current date and time for each response I received.
What are your thoughts? And how would you handle this situation?
Clarification
I would like to use the same architecture for both Windows or the Web if possible. I have a single business logic layer that multiple user interfaces interact with, could be Windows or the Web.
By Windows I would mean client-server.
Clarification
I am using an n-tier architecture so my business objects handle all the interaction with the presentation layer. That presentation layer could be feeding a client-server Windows application, Web application, Web Service and so on.
It is not a high traffic application, as it was developed for a customer of ours, maybe 100 users at most.
[DISCLAIMER 1 --- Java solution]
If each meaningful user is given a Session, then you could write your own SessionListener implementation to track each session that has been created and destroyed.
[DISCLAIMER 2 --- Code not tested or compiled]
And register this in your web.xml:
Hope this helps.
I'd just drop a log record table in the db.
UserId int FK
Action char(3) ('in' or 'out')
Time DateTime
You can drop a new record in the table when somebody logs in or out or alternatively update the last record for the user.
If you have session data just use that. Most session systems already have timestamps so they can expire sessions not used for x minutes.
I've seen strategy 1 work before. Of course the site was a small one.
The only problem with a web application solution is you often don't know when someone signs out. Obviously, if you have a login / authentication requirement, you can capture when a person signs on, and as part of your data access code, you can log when a person hits the database. But you will have to accept that there will be on reliable way of capturing when a person logs off - many will just move away from the site without taking the "log off" action.
I've just implemented a last seen system for my website. Your first option is similar, but I only update every +-5 minutes. It works for my situation, but larger scale websites might require something a little extra.