Announcement Announcement Module
Collapse
No announcement yet.
Looking for Online Users (Friends) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Looking for Online Users (Friends)

    Hello!

    Im working on a small webapplication with Spring and Spring Security and I want to realize something, but Im not sure how to do it.

    I have a webapplication where users can register, login and logout. The users are stored in a database.
    Now I want to implement that every user can have a list of other users marked as friends.
    For Example: User A has got three friends: User B, User C, User D.
    This is not the problem, but when User A logs in, I want to show him, whose friends of him are online and who are not.

    I will store the list of User As Friend in a database. The problem is how to find out very quickly which friends are online (without slowing down the server too much)

    I was thinking about something like a flag that is set for every user in the database when he is online (1) and offline (0).
    I could query than the state of every friend from User A - online or offline.
    The disadvantage might be, that I have to do a query for every friend the user has.
    When Ive got many users, there are many queries to be done and this might slow down the server.

    So I read about sessionRegistry.getAllPrincipals() which should retrieve all active users. Well, this will give me than a BIG list and I have to search for the three friends in there.
    For every user going online and looking after his friends, I will have this BIG list again. Im not sure if this is an efficient solution.


    So I wanted to ask you what solution of these two you would prefer (or if you have another idea on how to solve this issue)


    Then, after deciding which option to use, I might have some more questions at how to realize it :-)
    Thank you for your help! (and sorry for my bad english)

  • #2
    I would probably extend the current interfaces to provide a new method that only looks up what you need i.e. SessionRegistry.lookupOnlineFriendsFor(String username). Spring Security can continue to use the original interface and you can use the method(s) you have added to achieve better performance.

    Comment


    • #3
      Need Ur help

      Hi,
      I am very new to spring i have to list all the online users of the logged in user.
      so plz give me the sample.

      Comment


      • #4
        @annielucinda
        I haven't implemented it yet, Im starting right now with it, so I can't help yet, sorry :-)

        @rwinch
        I would probably extend the current interfaces to provide a new method that only looks up what you need i.e. SessionRegistry.lookupOnlineFriendsFor(String username). Spring Security can continue to use the original interface and you can use the method(s) you have added to achieve better performance.

        hm, but if I dont use the sessionRegistry.getAllPrincipals() method, but write my own method (select onlinestatus for friends of username), why should I extend the interface then? I could also add this method in my DAO-class, which I always use for accessing the database and then just call this method in my sourcecoude, whereever I need it. what would be the advantage of extending SessionRegistry?

        one more question regarding the setting of the flags (online/offline) in the database: if a user logs out, I set the flag to 0. (logout-method is called - I for example have this method in my own RememberMe-Implementation and its always called when a users logs out, so I can add the necessary code changes there. but I also need to change the flag when a user's session times out. where can I add source code for changing the flag when a session times out?

        and where would you set the flag? would you use an extra table for it (online_status(users_id, status)) or would you extend the users-table (users_id, username, password, enabled, status)?

        thank you! :-)


        [EDIT] forget about what I wrote. If I extend the SessionRegistry Interface, I dont need to look up the database, because there already is a list of online principal (existing sessions). I guess I just need a method who looks through this big list, or how else would you implement SessionRegistry.lookupOnlineFriendsFor(String username)?

        Thinking further, I dont even need to extend SessionRegistry. I dont see any difference between
        - writing a class with lookupOnlineFriendsFor(String username) which calls SessionRegistry.getAllPrincipals() and looks through this list
        - and implementing the same method in SessionRegistry-Implementation

        This bring me to the problem or the question I had before:

        Code:
        So I read about sessionRegistry.getAllPrincipals() which should retrieve all active users. Well, this will give me than a BIG list and I have to search for the three friends in there.
        For every user going online and looking after his friends, I will have this BIG list again. Im not sure if this is an efficient solution
        So now conclusing, my question is: How shall I implement lookupOnlineFriendsFor(String username)? IN SessionRegistryImplementation or OUTSIDE, calling SessionRegistry? (see no difference)
        and: how else could it be implemented then calling getAllPrincipals() and then looking through it for specific names? Is it a good approach to do so?

        thanks in advance! :-)
        Last edited by jeeper; Apr 5th, 2011, 09:15 AM.

        Comment

        Working...
        X