2 Replies Latest reply on Aug 18, 2011 5:15 AM by Rihards Zbitkovskis

    Online users counter

    Rihards Zbitkovskis Newbie

      Hello!

       

      What would be the way to create a counter of current portal users online?

      In case of servlets/jsps I could extend HttpSessionListener that counts current active sessions but what can be done in case of portlets?

        • 1. Re: Online users counter
          Trong Tran Master

          Counting users online would not be done in portlet and I also don't think it's possible. The portlet is just for presenting in this case.

           

          The good way is to create two listeners which extends from org.exoplatform.services.listener.Listener<ConversationRegistry, ConversationState>, then register them to ConvesationRegistry service with name "exo.core.security.ConversationRegistry.register" and "exo.core.security.ConversationRegistry.unregister". These two listeners will be triggered whenever user log-in and log-out from Portal correspondingly.

           

          For example, let's say you have :

           

          public class LoginListener extends Listener<ConversationRegistry, ConversationState> {
          
            public LoginListener() throws Exception {
            }
          
            @Override
            public void onEvent(Event<ConversationRegistry, ConversationState> event) throws Exception {
              // save user logged-in somehow
            }
          

           

          and

           

          public class LogoutListener extends Listener<ConversationRegistry, ConversationState> {
          
            public LogoutListener() throws Exception {
            }
          
            @Override
            public void onEvent(Event<ConversationRegistry, ConversationState> event) throws Exception {
              // remove user logged-out
            }
          

           

          You would register them by configuration like following :

           

            <external-component-plugins>
              <target-component>org.exoplatform.services.listener.ListenerService</target-component>
              <component-plugin>
                <name>exo.core.security.ConversationRegistry.register</name>
                <set-method>addListener</set-method>
                <type>LoginListener</type>
                <description>increase number of online users</description>      
              </component-plugin>       
              <component-plugin>
                <name>exo.core.security.ConversationRegistry.unregister</name>
                <set-method>addListener</set-method>
                <type>LogoutListener</type>
                <description>decrease number of online users</description>      
              </component-plugin>       
            </external-component-plugins>