• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Online user Vs Offline

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have been wondering how to identify a user when he is online. What is the mechanism to use it.. I know I have to use HttpSession object for this. But i don't have the slightest idea about this..

My exact requirement is

"When a user is online, The status message in his profile will display online. The user is permissible to view other user profiles (in non-edit mode). When the user views other profiles, display must show whether other profile users are online or offline."

Thanks,
Abu.A
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only mechanism you have to know whether someone is accessing your web application is a request. If the user makes a request they are "online". HTTP is stateless, so once that request is finished you can't really tell whether the user is still online, until they make another request. So you can probably pick an arbitrary number (say 5 minutes) and record who made a request in the last fime minutes. You could use the session for this; you may want a shorter check time than a usable session timeout would allow though. You also may want to add mechanisms to get a quicker response if they navigate away or close the browser, some sort of request fired on page unload should do that.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that the answer greatly depends upon what you define as "online".
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what Paul says, is happening in Javaranch forum. Because within a shorter time a user is asked to reauthenticate...
My guess is so..

Bear Bibeault wrote:I think that the answer greatly depends upon what you define as "online".



When a user is authenticated, He is free to navigate his profile as well as other profiles. He is free to modify his profile and only allowed to view other profiles. The time between the user authentication and user logoff is what i mentioned "online". User Logoff can also be automated through session timeout.

My requirement is User page must display the message "online" or "offline". Help me out.


Abu.A
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Help me out.


Paul's post contained a possible approach; if that's not workable in your case, tell us why.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, I got the idea of Paul. But I am asking you some of the ways to implement.

If i am going to use Paul guidelines, then each and every request is going to be checked before it serves its original purpose. That's what i was thinking about. For example,

An authenticated user is displayed online because he is constantly making requests. But when suddenly he clicks a link to some other profile. This request has to bring all the details about the other person's details like his name, profession, location etc. All the details can be fetched from database. Now I must also store the info about the person is online or offline. So that i can fetch the message whether he is online or offline to the viewing user.

I am asking the way to implement these. I think i am making my point here.


Abu.A
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to store the information whether someone is online in a DB. I'd use an in-memory Map<userID, lastAccessTimestamp>. You can have a background job that removes entries from this list if the timestamp is older than your definition of "online"; you could have that running every minute or so.
You also need to update that list every time a user accesses the site, so you need to put in place proper synchronization.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks buddy, i was sprinting around answers like this. Before i am cleared up.. How can i run the every-minute-or-so job in web app ( I mean standard way of doing this). I am wondering how can i run a code that's routinely checking for a particular interval. It must sound like Servlet Listeners....
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A simple java.util.Timer will do.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i can use util.Timer. Thats fine. Where can i write my task? I guess it must be in servlet context listener.
Guide me..
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A context listener would indeed be a good place to set up both Timer and TimerTask.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all


ABU
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic