2 Replies Latest reply: Feb 11, 2012 1:52 PM by fvitorc RSS

Best way to detect user presence

fvitorc Newbie

Hi,

 

I am trying to find the best way to detect user presence (or queue presence).

I've been looking at the source code for sometime now, and I think that one way to know when a user has connected is to listen to the FinishStateSync command on the ServerBus. Am I correct? Is there a better way for that?

 

As for the disconnect I haven't find anything.

 

I know that I could send Connected and Disconnected messages from the client, but I would not like to rely on these methods. For example, if the browser crashes, I would never know that the user has disconnected, because he didn't even had the chance to send the Disconnected message.

 

Regards,

Vitor.

  • 1. Re: Best way to detect user presence
    fvitorc Newbie

    Actually, it's not possible to listen to incoming messages on the ServerBus. I get the following exception if I try to do so:

     

    java.lang.IllegalArgumentException: cannot modify or subscribe to reserved service: ServerBus

     

     

    So I would like to request a new feature for errai. The proposal would be to get queue connect/disconnect events.

    The end user could write something like that to get these events:

     

    @QueuePresence

    public class MyQueuePresence implements QueuePresenceListener {

     

        @Override

         public void onConnect(String sessionId) {

             // do whatever I want

        }

     

        @Override

        public void onDisconnect(String sessionId) {

            // do whatever I want

        }

     

    }

     

    Of course, the interface, annotation and methods names could be different.

    Where can I request such feature? Is it writing in this forum enough?

     

    Regards,

    Vitor.

  • 2. Re: Best way to detect user presence
    fvitorc Newbie

    After a while, I found a solution for that. For disconnects it's quite simple, but for connects you must disable the monitor tool.

     

    Anyway, the ServerMessageBusImpl (just cast to it from a MessageBus) has a addQueueClosedListener for disconnects.

     

    It also has a attachMonitor method, which provides not only connect/disconnect events, but a lot of other notifications.

    The bad part is that you won't be able to use the monitor tool, because only one monitor can be active at a time.

     

    I believe the best thing to do then, is to initially send your own connect message (do not rely on ServerBus), and use a QueueClosedListener for disconnects.

     

    Regards,

    Vitor.